Control an Arduino Yún from your Phone

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.

Nexmo Dashboard

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.


  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"


// 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(){
  // 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

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
  // set Temboo account credentials
  // 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
  // add an output filter to return only the choice that the user makes from the phone menu
  CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", "/digits", "CallbackData");
  // run choreo;
  // 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 new TembooAccount.h tab and then save your sketch.

#define TEMBOO_ACCOUNT "ACCOUNT_NAME"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "APP_NAME"  // your Temboo app key name
#define TEMBOO_APP_KEY  "APP_KEY"  // 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!

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.

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

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, and we'll answer you as quickly as possible.