IoT



[scribd id=247887501 key=key-XTZOV3A7tPQ5SwRKuEyk mode=slideshow]

Arduino Smart Home Automation

Arduino Smart Home Automation



WiFi-equipped Arduino Yun now available for $69 (video)

Arduino Yun at Maker Faire
If you were wondering what happened to the Arduino Yun after it missed its original June release target, you can relax: it’s now on sale worldwide. As promised, the $69 (€52) design combines a garden variety Leonardo board with a WiFi system-on-chip running Limino, giving owners a customizable wireless access point with Ethernet, USB and a microSD slot. Tinkerers can also program the Arduino component over the air using a newly updated developer environment. Those already sold on the concept can buy an Arduino Yun at the source link, while newcomers can check out an introductory video after the break.

How to Temboo with your Yún


Temboo makes it easy for the Arduino Yún to connect to over 100 web-based resources and services (e.g. Facebook, Dropbox, US Census data) by standardizing how you interact with their Application Programming Interfaces (APIs). Don’t worry if you’re not familiar with APIs—with Temboo you don’t have to worry about the details.

Here we’ll show you how to use Temboo by creating a simple Arduino Yún sketch that retrieves weather information for a specific address from the Yahoo Weather API. What makes Temboo uniquely powerful and useful is that, once you know how to use one API, you know how to work with any API in our Library.

Before you start, you’ll need to download and install the Arduino IDE. Make sure you’ve downloaded the version compatible with the Yún.

You’ll also need to connect your Yún to the internet. If you need help with that, take a look at Arduino’s documentation.

FIND WHAT YOU NEED

1 Log in to Temboo.

2 Go to our Library and find the Yahoo > Weather > GetWeatherByAddress Choreo.

The Yahoo GetWeatherByAddress Choreo in our Library

3Enter any complete address in the Address input field.

4Now click Run. After a moment you’ll see the data that Yahoo Weather sends back shown in the Output section of the page (which is right below the Input section).

The output from the Yahoo Weather API (which is in XML format)

MAKE YOUR ARDUINO SKETCH

When you run a Choreo from the website, Temboo automatically generates code that can be used to make the same API call from an Arduino Yún sketch.

5Turn on IoT Mode, select Arduino Yún, and scroll down to the code section of the Library page.

The IoT Mode switch can be found on each Choreo page in the Temboo Library

6Scroll down to the CODE section of the Library page. Then Copy the code, and paste it into a new sketch in the Arduino editor.

REMEMBER TO CREATE YOUR HEADER FILE

In order to run this sketch on your Yún, it needs to be configured with an appropriate TembooAccount.h header file that contains your Temboo account information.

To create the header file:

7Make a new tab in the Arduino editor, and name it TembooAccount.h

8Beneath the sketch code you previously copied from the Library, you’ll find a header file containing three #definestatements. Copy the contents of the header into your TembooAccount.h file.

The TembooAccount.h header file

RUN THE SKETCH AND REJOICE

Save and upload your sketch to the Arduino Yún, and open the serial monitor. After running the sketch, you’ll see the response from the Yahoo Weather service printed to the monitor.

Congratulations! This same approach will work with your Yún for all of our 2000+ Choreos. Because these ready-to-run tasks take care of so many steps, we named them after choreographies. Now that you know how to make your Yún run any Choreo, you’re just a few steps away from making something extraordinary. With Temboo handling all the small stuff, you’re free to think big.

You can find lots of examples of how to use Temboo with your Yún here.

Finally, if you’d like to run this, or any other Temboo sketch, via wi-fi or ethernet (as opposed to the USB cable), then you should read this tutorial.

NEED HELP?

We’re always happy to help. Just email us at support@temboo.com, and we’ll answer your questions.

Control your Yún from your Phone


NEW Program hardware without writing code – check out the Device Coder.

Here we’ll show you how to use your phone as a remote control for your Arduino Yún. Specifically, the example sketch calls a phone number and asks whether it should blink the LED attached to pin 13. We used this sketch as a basis for the project you can see in the video below.

Your Yún can use text-to-voice to construct phone menus that can be used by you or anyone else to control your Yún from afar. With this power, your Yún can work as a remote monitor and call you when it wants your input, opening up a wide range of possibilities for applications that react based on remote user input.

This sketch uses a choreo from our Nexmo bundle.

GET SET UP

1Make sure you have a Temboo account. If you don’t already have one, you can register for a free account here.

2You’ll also need a Nexmo account, which you can create here.

3After you’ve created your Nexmo account, retrieve your Nexmo API Key and API Secret – you’ll need them to run the sketch. You can find your Nexmo API Key and Secret in the API Settings menu on the top right of the Nexmo dashboard, as shown in the screenshot below.

The API Settings menu on the Nexmo dashboard

4Make sure that your Yún is connected to the Internet.

WRITE THE SKETCH

Copy the code below into a new sketch in your Arduino IDE. Replace the placeholder values in the code with your own Nexmo API details and your own phone number. Make sure to include your international access code and don’t use any punctuation. For example, a US phone number would look like this: 12062919145.

/*
  RemoteControl

  Demonstrates remotely controlling an Arduino Yun by phone with Nexmo 
  and the Temboo Arduino Yun SDK.
  
  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h"

/*** SUBSTITUTE YOUR VALUES BELOW: ***/

// your Nexmo API key
const String NEXMO_API_KEY = "xxxxxxxxx";

// your Nexmo API secret
const String NEXMO_API_SECRET = "xxxxxxxxx";

// the phone number you want your Yun to call
const String PHONE_NUMBER = "xxxxxxxxxxx";

/***************************************/

int led = 13; // the LED on pin 13
int numRuns = 0; // the number of times the sketch has been run
int maxRuns = 1; // the number of times the sketch should run

void setup(){
  Serial.begin(9600);
  
  delay(4000);
  while(!Serial);
  Bridge.begin();
  
  // initialize the digital pin as an output
  pinMode(led, OUTPUT);  
}

void loop(){
  if (numRuns < maxRuns) {
    Serial.println("Making a phone call to " + PHONE_NUMBER + "...\n");
    if (makeNexmoCall() == 1) {
      Serial.println("Blinking the LED on 13!\n");
      // blink the LED on pin 13 ten times
      for (int i =0; i < 10; i++) {
        digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(250);               // wait for a 1/4 second
        digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
        delay(250);               // wait for a 1/4 second
      } 
    } 
    // if the users choses not to blink the light, do nothing
    else {
      Serial.println("The user chose not to blink the light :-(\n");
    }
    // increment the number of times the sketch has run
    numRuns++;
    Serial.println("Done.");
  }
  delay(60000);
}

/*
Trigger a voice call via a Temboo Nexmo Choreo. Call the user, give them a menu of options
and return the selection they make on their phone keypad as an integer. 
*/
int makeNexmoCall() {
  int choice = 0;
  
  TembooChoreo CaptureTextToSpeechPromptChoreo;

  // invoke the Temboo client
  CaptureTextToSpeechPromptChoreo.begin();
    
  // set Temboo account credentials
  CaptureTextToSpeechPromptChoreo.setAccountName(TEMBOO_ACCOUNT);
  CaptureTextToSpeechPromptChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  CaptureTextToSpeechPromptChoreo.setAppKey(TEMBOO_APP_KEY);
    
  // set choreo inputs
  CaptureTextToSpeechPromptChoreo.addInput("Text", "Hello there. Would you like to blink a light on your Arduino Yun? Press one to blink, or press zero to ignore.");
  CaptureTextToSpeechPromptChoreo.addInput("APIKey", NEXMO_API_KEY);
  CaptureTextToSpeechPromptChoreo.addInput("APISecret", NEXMO_API_SECRET);
  CaptureTextToSpeechPromptChoreo.addInput("To", PHONE_NUMBER);
  CaptureTextToSpeechPromptChoreo.addInput("MaxDigits", "1");
  CaptureTextToSpeechPromptChoreo.addInput("ByeText", "Ok, your wish is my command. Goodbye!");
    
  // identify choreo to run
  CaptureTextToSpeechPromptChoreo.setChoreo("/Library/Nexmo/Voice/CaptureTextToSpeechPrompt");
  
  // add an output filter to return only the choice that the user makes from the phone menu
  CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", "/digits", "CallbackData");
    
  // run choreo
  CaptureTextToSpeechPromptChoreo.run();
  
  // parse the results 
  while(CaptureTextToSpeechPromptChoreo.available()) {
    // read the name of the next output item
    String name = CaptureTextToSpeechPromptChoreo.readStringUntil('\x1F');
    name.trim(); // use “trim” to get rid of newlines

    // read the value of the next output item
    String data = CaptureTextToSpeechPromptChoreo.readStringUntil('\x1E');
    data.trim(); // use “trim” to get rid of newlines
    
    // return the value of the choice that the user made from the phone menu
    if (name == "choice") {
      choice = data.toInt();
    } 
  }
  return choice;
}

CREATE YOUR HEADER FILE

The sketch above references the TembooAccount.h header file, which contains your Temboo account information.

If you are currently logged in, you’ll see your account details in the code snippet below (otherwise you’ll see placeholder values). Create a new tab in the Arduino IDE and call it TembooAccount.h. Copy the code below into your newTembooAccount.h tab and then save your sketch.

#define TEMBOO_ACCOUNT "kindservice"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "be11ba8507d44330856881972205967d"  // your Temboo app key

With both files in place you’re ready to upload the sketch and have your Yún call to ask if it should blink the LED attached to pin 13 or not. Make sure to open the Serial Monitor to see the output on your screen.

WHAT NEXT?

When you’ve got this sketch working, you’re in a position to build any number of applications that involve sensing information on the Yún and delegating control to a human when it’s time to make a choice about what to do next. Your own personal army of robot servants is one step closer to reality!

If you want to recreate the app that we show in the video above, then check out our Device Coder. It generates all the code you need to link Choreos and physical sensors together.

We’ve also made the sketch that we used in our video available on GitHub. There you’ll find details on the equipment we used and detailed getting started instructions.

We’d love to hear where you take this idea next so please don’t hesitate to get in touch if you have something to share.

NEED HELP?

If you’ve got questions about Nexmo, it’s best to start by learning more about the Choreo that we use in this example. You might also find what you need by searching Nexmo’s support forums.

For anything to do with Temboo and how it works with your Arduino Yún, we’re always happy to help. Just email us atsupport@temboo.com, and we’ll answer you as quickly as possible.


Tweet-a-watt – How to make a twittering power meter… by adafruit
Picture of Tweet-a-watt - How to make a twittering power meter...

Control your FAN remotely

SuperHouseTV #12: Building an Arduino home automation controller

Yun based Electricity Monitor with Cloud Support / Temboo and Google Drive

Linkio: the $100 Smart Home Devices Solution
by Linkio

Leave a Reply

Your email address will not be published. Required fields are marked *