# Sending an SMS with Temboo

## Overview

Danger: 

This guide&nbsp;will show you the basic framework for programming your Arduino to interact with APIs using&nbsp;the Temboo platform. We'll focus on sending an SMS with Twilio&nbsp;here, but the same basic steps will work for any of the different processes in the Temboo library.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/686/medium800/microcontrollers_Cover_Image.jpg?1414515075)

# Sending an SMS with Temboo

## Get Set Up

To build this example project, you'll be using an internet-connected Arduino board that will&nbsp;send a text message. We've chosen to use:

![](https://cdn-learn.adafruit.com/assets/assets/000/020/279/medium800/microcontrollers_Arduino_Uno_R3.jpg?1413230058)

An Arduino Uno R3

![](https://cdn-learn.adafruit.com/assets/assets/000/020/280/medium800/microcontrollers_Adafruit_CC3000_WiFi_Shield.jpg?1413230060)

An Adafruit CC3000 WiFi Shield

![](https://cdn-learn.adafruit.com/assets/assets/000/020/281/medium800/microcontrollers_USB_A-B_Cable.jpg?1413230062)

A USB A - B cable

![](https://cdn-learn.adafruit.com/assets/assets/000/020/667/medium800/microcontrollers_Push_Button.jpg?1414446737)

A push button

![](https://cdn-learn.adafruit.com/assets/assets/000/020/668/medium800/microcontrollers_10k_Ohm_Resistor.jpg?1414446761)

A 10k Ω resistor

![](https://cdn-learn.adafruit.com/assets/assets/000/020/669/medium800/microcontrollers_Half_Breadboard.jpg?1414446777)

A half-size breadboard

![](https://cdn-learn.adafruit.com/assets/assets/000/020/670/medium800/microcontrollers_Wires.jpg?1414446790)

Some wires

You'll also need a Temboo account and a Twilio account. To set up your Temboo account (if you don't already have one) you can create one&nbsp;for free [here](https://temboo.com/signup). &nbsp;You can create a free Twilio account [here](https://www.twilio.com/).

Finally, make sure that you have the latest version of Temboo's Arduino library installed; if you don't, you can download it [here](https://temboo.com/arduino/others/library-installation).

# Sending an SMS with Temboo

## Generate Your Sketch

Danger: 

Now that you're all set up, log in to Temboo and go to the [Twilio \> SMSMessages \> SendSMS](https://temboo.com/library/Library/Twilio/SMSMessages/SendSMS/) Choreo in the Temboo Library. Turn on IoT Mode and make sure that you've added details about the shield that your Arduino board is using to connect to the internet. You can do this by setting IoT Mode to **ON** in the upper right-hand corner of the window and then selecting **Arduino** and **Adafruit CC3000 WiFi** from the dropdown menus that appear, as shown below:

![](https://cdn-learn.adafruit.com/assets/assets/000/020/178/medium800/microcontrollers_IoT_Mode.png?1413229376)

Next, fill out the **Input** fields using the information from your Twilio account, the text of the SMS that you want to send, and the phone number to which you would like to send it. You'll find your Twilio Account SID and Auth Token by going to [Twilio](https://www.twilio.com/)&nbsp;and checking your Dashboard, as shown below; note that you need to use the credentials found on the Dashboard, not the test credentials from the Twilio Dev Tools panel:

![](https://cdn-learn.adafruit.com/assets/assets/000/020/179/medium800/microcontrollers_Twilio_dashboard.png?1413229383)

When using a free Twilio account, you'll need to verify the phone numbers to which messages are being sent by going to Twilio&nbsp;and following the instructions under the&nbsp; **Numbers \> Verified Caller IDs** &nbsp;tab, as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/617/medium800/microcontrollers_Twilio_Verify_Number.png?1414178360)

Once you've&nbsp;filled out&nbsp;all of the&nbsp;input fields on the Temboo SendSMS Choreo page, test the Choreo from your browser by clicking&nbsp; **Run** at the bottom of the window.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/622/medium800/microcontrollers_Choreo_Inputs.png?1414183965)

If you elected&nbsp;to send the SMS to your own phone number, you should receive it (and if you didn't, whomever you chose will instead). You'll also see a JSON&nbsp;that is returned by Twilio appear under **Output** , indicating that, among other things, your test executed successfully.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/623/medium800/microcontrollers_JSON_Response.png?1414187993)

# Sending an SMS with Temboo

## Upload and Run

Danger: 

Now that you've tested the Choreo successfully, you can scroll down to find the **Code** section of the page.&nbsp;When you're in IoT Mode and you run a Choreo, Temboo automatically generates code that can be used to make the same API call from an Arduino sketch.&nbsp;Copy the code, and paste it into a new sketch in the Arduino IDE.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/633/medium800/microcontrollers_Generated_Code.png?1414188615)

In order to run this sketch on your Arduino, it needs to be configured with an appropriate TembooAccount.h header file that contains your Temboo account information and internet shield setup information.&nbsp;To create the header file, make a new tab in the Arduino IDE, and name it TembooAccount.h.

On the Twilio SendSMS Choreo page beneath the sketch code that you previously copied and pasted into the Arduino IDE, you’ll find another block of generated code&nbsp;containing #define&nbsp;statements and details about your internet shield. This is your header file. Copy the contents of the header into the&nbsp;TembooAccount.h&nbsp;tab in your Arduino IDE.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/635/medium800/microcontrollers_Header_ArduinoIDE.png?1414189332)

With both files in place, you are ready to start sending SMS from your Arduino. Save and upload the sketch, open the serial monitor, and watch the texts roll in!

# Sending an SMS with Temboo

## Push to Send

Of course, a device that just sends off messages with no prompting may not be of much use, so let's add a button to the Uno that will trigger an SMS when pushed.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/685/medium800/microcontrollers_Wired_Button.jpg?1414512943)

# Sending an SMS with Temboo

## Wiring Your Circuit

The circuit for the push button is fairly straightforward—connect one of the button's legs&nbsp;to the 5 volt power supply, and the other to one of the digital pins on your WiFi shield. In our diagram, we've chosen pin 8. Then, connect that same leg that is wired to pin 8 to ground through a pull down resistor.

![](https://cdn-learn.adafruit.com/assets/assets/000/020/665/medium800/microcontrollers_Push_Button.jpg?1414445965)

When the button in this circuit is pressed, pin 8 will be connected to power, and will read HIGH. When the button is left open, pin 8 is connected to ground, and will read LOW.

# Sending an SMS with Temboo

## Adding Code

Danger: 

You've already generated all of the code you need to send an SMS through Twilio using your Arduino, so you only need to add a couple of extra lines to your sketch to trigger those messages with your push button. First, initialize the pin that you will be reading (recall that we chose to use pin 8) by adding the following lines of code to what you already have in&nbsp;void setup():

```auto
// Initialize pin
pinMode(8, INPUT);
```

Your setup should now look something like this:

```auto
void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until the serial console is connected.
  delay(4000);
  while(!Serial);

  status_t wifiStatus = STATUS_DISCONNECTED;
  while (wifiStatus != STATUS_CONNECTED) {
    Serial.print("WiFi:");
    if (cc3k.begin()) {
      if (cc3k.connectToAP(WIFI_SSID, WPA_PASSWORD, WLAN_SEC_WPA2)) {
        wifiStatus = cc3k.getStatus();
      }
    }
    if (wifiStatus == STATUS_CONNECTED) {
      Serial.println("OK");
    } else {
      Serial.println("FAIL");
    }
    delay(5000);
  }
  
  // Initialize pin
  pinMode(8, INPUT);
  Serial.println("Setup complete.\n");
}
```

Then, add the following&nbsp;two lines of code to void loop() to set the SendSMS Choreo to run only when the button is pressed:

```auto
int sensorValue = digitalRead(8);
if (sensorValue == HIGH) {
```

You should nest the code that you already have in void loop()&nbsp;within this new conditional, so that it should now look&nbsp;something like this:

```auto
void loop() {
  int sensorValue = digitalRead(8);
  if (sensorValue == HIGH) {
    if (numRuns <= maxRuns) {
      Serial.println("Running SendSMS - Run #" + String(numRuns++));

      TembooChoreo SendSMSChoreo(client);

      // Invoke the Temboo client
      SendSMSChoreo.begin();

      // Set Temboo account credentials
      SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
      SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
      SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);

      // Set Choreo inputs
      String AuthTokenValue = "PLACEHOLDER";
      SendSMSChoreo.addInput("AuthToken", AuthTokenValue);
      String BodyValue = "PLACEHOLDER";
      SendSMSChoreo.addInput("Body", BodyValue);
      String ToValue = "PLACEHOLDER";
      SendSMSChoreo.addInput("To", ToValue);
      String AccountSIDValue = "PLACEHOLDER";
      SendSMSChoreo.addInput("AccountSID", AccountSIDValue);
      String FromValue = "PLACEHOLDER";
      SendSMSChoreo.addInput("From", FromValue);

      // Identify the Choreo to run
      SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");

      // Run the Choreo; when results are available, print them to serial
      SendSMSChoreo.run();

      while(SendSMSChoreo.available()) {
        char c = SendSMSChoreo.read();
        Serial.print(c);
      }
      SendSMSChoreo.close();
    }
  
    Serial.println("\nWaiting...\n");
    delay(30000); // wait 30 seconds between SendSMS calls
  }
}
```

Don't forget to add a curly bracket&nbsp;at the end of void loop() to close out the additional&nbsp;conditional! Note that in the code example above, the Choreo inputs have been replaced with placeholders. The code that you generate on the Temboo website will automatically&nbsp;have these input values filled in, so there's no need to worry about replacing them manually.

With that, your sketch is once again ready to go—you're free to tinker with it as you wish (for example, you might choose to comment&nbsp;out the 30 second delay at the end if you want to send messages more rapidly), but no further alterations are required. Save it, upload it to your&nbsp;Arduino, open the serial monitor, and push the button to dispatch your&nbsp;SMS!


## Related Guides

- [How to Build a Testing Jig](https://learn.adafruit.com/how-to-build-a-testing-fixture.md)
- [IR Sensor](https://learn.adafruit.com/ir-sensor.md)
- [MIDI for Makers](https://learn.adafruit.com/midi-for-makers.md)
- [Adafruit MOSFET Driver](https://learn.adafruit.com/adafruit-mosfet-driver.md)
- [Adafruit 3.5" 480x320 TFT FeatherWing](https://learn.adafruit.com/adafruit-3-5-tft-featherwing.md)
- [NeoPixel Aquarium with Submersible Lights](https://learn.adafruit.com/neopixel-aquarium-with-submersible-lights.md)
- [Adafruit GP8403 I2C DAC with 12V Booster](https://learn.adafruit.com/adafruit-gp8403-i2c-dac-with-12v-booster.md)
- [Mindfulness Clock OF DOOM](https://learn.adafruit.com/mindfulness-clock-of-doom.md)
- [One Key: Single Button Bluetooth Keyboard](https://learn.adafruit.com/onekey.md)
- [ESPectre Human Detector for Feather](https://learn.adafruit.com/espectre-human-detector-for-feather.md)
- [Adafruit LTR-329 and LTR-303 Light Sensors](https://learn.adafruit.com/adafruit-ltr-329-ltr-303.md)
- [Adafruit TSMP96000 IR Receiver Breakout](https://learn.adafruit.com/adafruit-tsmp96000-ir-receiver-breakout.md)
- [Adafruit 2.8" TFT Touch Shield v2 - Capacitive or Resistive](https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2.md)
- [Playing Gamebuino META Games on Arcada](https://learn.adafruit.com/playing-gamebuino-meta-games-on-arcada.md)
- [Adafruit AS5600 Magnetic Angle Sensor](https://learn.adafruit.com/adafruit-as5600-magnetic-angle-sensor.md)
