Use Twilio's Programmable SMS as an interface to your Arduino. The body of the text message hits the sample Node.JS code which sends a Programmable Wireless Command to an Ardunio device asking for its current battery level and then returns the results to the original sender.
The Command resource enables you to exchange simple machine-to-machine messages with SMS-capable Devices. For example, you could use a Command to tell an idle device to enable its data capabilities and establish an IP session. In this sample, we'll send a message to an Android device asking it to return its battery level.
Commands can be sent and received using the SMS text mode or binary (PDU) mode. Text mode Commands have a maximum length of 100 single-byte characters. Binary mode Commands have a maximum length of 140 bytes. To process a Command when it reaches your Arduino, you will interface with the modem directly. From the perspective of the Arduino, a Command is delivered as a regular SMS message.
- Programmable Wireless SIM Card
- Programmable Phone Number
- Arduino board with GPS and cellular module
- Arduino IDE
- Server running Node.js v6.11+
- Clone or download this repository
- Open
config.js
with your favorite text editor - Update all values with the
{{ YOUR_X_HERE }}
convention - See table below
- Upload code to server
Key | Description |
---|---|
accountSid | Consider this your account username. It’s used to authenticate - get it here. |
authToken | Consider this your account password. It’s used to authenticate - get it here. |
phoneNumber | Used for bidirectional communication with the Arduino device - get one here. |
simUniqueName | This is the unique name of your SIM resource - get it here. |
- Navigate to the Programmable Wireless SIMs
- Select your newly created SIM
- Enter the Callback URL that points to the code you uploaded to your server.
- Ngrok Example: https://NGROK-GENERATED-NAME.ngrok.io/api/v1/callback
- Heroku Example: https://YOUR-APP-NAME-HERE.com/api/v1/callback
- Click Save
- Open Arduino IDE
- Go to File > Open in the Menu
- Navigate to your local copy of the arduino folder from this repository
- Select
wireless-sms-template.ino
- Select your Arduino board under Tools in the Menu
- Select the correct Port under Tools in the Menu
- Press the Right Arrow Button in Arduino IDE to upload the code
- Select Serial Monitor under Tools in the Menu
- Send a SMS with the text:
battery level
- Wait for response
That’s it! Happy Hacking!