Project tutorial
Control your Yún from your Phone with Temboo

Control your Yún from your Phone with Temboo © GPL3+

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.

  • 915 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

1. Get Set Up

  • Make sure you have a Temboo account. If you don't already have one, you can register for a free account here.
  • You'll also need a Nexmo account, which you can create here. Note that Nexmo ask you to provide an email address with a personal or corporate domain, rather than a shared email service like @gmail.com to sign up."
  • After 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.
  • Make sure that your Yún is connected to the Internet.

2. 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 Ã

3. 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 new TembooAccount.h tab and then save your sketch.

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.

#define TEMBOO_ACCOUNT "accountName"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "abc123xxxxxxxxxxxxxx"  // your Temboo app key

4. 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.

5. 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 at support@temboo.com, and we'll answer you as quickly as possible.

Code

Code snippet #1Arduino
/*
  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 Ã
Github
https://github.com/temboo/arduino-examples/tree/master/remote-control-by-phone

Comments

Similar projects you might like

Control Lights with your Phone from Anywhere in the World!

Project showcase by Kaustubh Agarwal

  • 15,053 views
  • 4 comments
  • 36 respects

Servo Control with TV Remote Control

Project showcase by eldo85

  • 5,596 views
  • 5 comments
  • 17 respects

Control a LED from your Phone

Project showcase by Kaustubh Agarwal

  • 14,168 views
  • 5 comments
  • 37 respects

Control your Light System Using Smart Phone

Project tutorial by Ahmed Yassin

  • 35,277 views
  • 4 comments
  • 55 respects

Control Robot Arm with your Android Phone

Project tutorial by Ammar Atef Ali

  • 11,910 views
  • 0 comments
  • 24 respects
Add projectSign up / Login