loading

This Instructable explains how to send an SMS from an Arduino using the Internet. There are many ways to approach this and I will explain one of the different methods used to accomplish this task.

Some major points needed for my project:

  • I have a standard Ethernet shield, and ENC28J60 Ethernet module, and I needed my program to work with both and also over a wifi connection (using the ESP8266 - I just ordered some to test)
  • I would like the SMS service to be free

So aside from the hardware, I found three main ways to interface with the Arduino and send an SMS.

  1. Using Temboo to send an SMS through Twilio
  2. Using Lithouse connected to IFTTT to send an SMS
  3. Using Thingspeak ThingHTTP to send an SMS through Twilio

I tested all of these methods, and only one successfully worked on my ENC28J60 Ethernet module, the target I was going for. But more importantly the code on the Arduino side is very simple, and should work using WiFi or Ethernet without any special libraries, other than the standard Ethernet communication libraries.

So again I will only explain method number 3. If you want to use another method there are other guides on the internet, but I felt like Thingspeak ThingHTTP is slighjtly undocumented.

Step 1: Setup

The hardware is pretty simple.

  1. Arduino Uno, or equivalent
  2. A connection to the internet, using an Ethernet shield, the ENC28J60 Ethernet module, or a WiFi module/shield

The software is a little more complicated to set up.

Since the Arduino does not support HTTPS, we are going to use Thingspeak to trigger Twilio.

You will need:

  1. A Twilio account. Register at https://www.twilio.com/try-twilio. After signing up, verify your number.
  2. A Thingspeak account. Register at https://thingspeak.com/users/sign_up

If you are using the ENC28J60 or wifi module, you will need the acompaning libraries. For the ENC28J60, I reccomend Arduino UIP. Download the zip and move it to the libraries folder. https://github.com/ntruchsess/arduino_uip

Okay now that's all set up, we will start the configuration.

Step 2: Configuring Thingspeak ThingHTTP

Go to Thingspeak.com, click on apps, then ThingHTTP, and then New ThingHTTP. This will take you to the setup page. You will have to find your Twilio account SID and auth token on your Twilio dashboard page

Copy the following data into the fields. Where italics and caps you must replace with the data from Twilio.

  1. Name it Twilio Send SMS
  2. URL is https://api.twilio.com/2010-04-01/Accounts/YOUR TWILIO ACCOUNT SID/SMS/Messages
  3. HTTP Auth Username is YOUR TWILIO ACCOUNT SID
  4. HTTP Auth Password is YOUR TWILIO AUTH TOKEN
  5. Set the method to POST
  6. Content type is application/x-www-form-urlencoded
  7. Click remove headers, and leave host blank
  8. Body = From=YOUR TWILIO NUMBER&To=%%number%%&Body=%%message%%

Click Save ThingHTTP

Take note of the API key for your ThingHTTP. You will need it in the Arduino sketch

Step 3: Arduino Side

The Arduino will need a connection to the internet, again the Ethernet shield and ENC28J60 Ethernet module will both work, and Wifi will too with some small changes to the program

Here is a guide to connect the ENC28J60 to the Arduino https://www.instructables.com/id/Add-Ethernet-to-a...

This code will work both with the Arduino Ethernet Shield and the ENC28J60 Ethernet module, with a simple modification. Download the file and change the API key and phone number to your own, then upload it.

Test the program, and hopefully within a few seconds your phone will receive the SMS. The Serial monitor will also display some helpful information for debugging.

Good luck and hope this was helpful!

<p>The serial port stops at &quot;sending sms&quot; not sheer what the problem is can anyone help?</p>
<p>Hi All!</p><p>You can download smarter UIPEthernet library from:</p><p><a href="https://github.com/UIPEthernet/UIPEthernet" rel="nofollow">https://github.com/UIPEthernet/UIPEthernet</a></p><p>This support more MCUs and more IDEs.</p><p>(UIPEthernet <br>library for Arduino IDE,Eclipse with arduino plugin and MBED/SMeshStudio<br> (AVR,STM32F,ESP8266,Intel ARC32, Nordic nRF51, Teensy boards,Realtek <br>Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet <br>W5100 Ethernet library API.)</p><p>You can find wiring diagrams:</p><p><a href="https://github.com/UIPEthernet/UIPEthernet/tree/master/hardware" rel="nofollow">https://github.com/UIPEthernet/UIPEthernet/tree/ma...</a></p><p>Best Regards</p>
<p>I want to thank you for this post, I've been trying to send an sms with my Arduino and searching for a successful process. I tried Cayenne , Temboo, Native all with no luck and then stumbled on your post. It was straight forward simple and worked like a champ. Exactly what I was looking for !!</p><p>I configured a motion sensor that works out at my shed where I've had some break in's. The remote motion sensor also uses a RF 433Mhz TX and sends a message to my in door unit which in turns sounds a buzzer and now sends me a Text message on my phone !!</p><p>You are the best !!...</p>
<p>Could someone please post example code for WiFi instead of Ethernet. I'm using an ESP8266.</p><p>Thank You </p>
<p>I am getting an error as To number is not valid. What is happening is that ThingSpeak is removing the '+' sign from the To number. How can I get around this problem?</p>
<p>Hi Praveen, is your problem solved? I am having the same issue as yours :(</p>
<p>are you sure thingspeak removes the plus? I get a non valid number error message as well, but with or without plus Twilio still mentions the plus in front of the number</p>
<p>I am getting the 'to' number is invalid although I have already registered and verified my mobile phone number. Anyone can help me about this? :(</p>
<p>Error:</p><p>The 'From' number +XXXXXXXX is not a valid phone number, shortcode, <br>or alphanumeric sender ID</p><p>When I test directly from Twilio, it works, so the problem must be somewhere in the Thingspeak part</p>
<p>Hi there, i have a problem with my codes. I changed your ethernet codes and added my wifi library since I am using wifi shield for this project. It only sends</p><p>Setting up WiFi...</p><p>Attempting to connect to WEP network, SSID: iotlab</p><p>Sending SMS</p><p>H</p><p>and does not send any message to my phone. I did add my phone number on twilio and did what i am instructed to in this page but I still have error. Are you able to help me?</p>
<p>Shall I use my own phone number there? I don't see other numbers, just a button to buy a number and as far as I got it from your &quot;requirements&quot;, the SMS service should be free. Am I doing something wrong?</p>
<p>The To phone number is your cell phone number - this needs to be verified on your twilio account before first use. The From phone number is your free Twilio number, find it in your account. If you can't find it try googling Twilio Trial number. Good luck!</p>
<p>Hi i can sussesfully create a twilio acount but i dont get a number instantly. I must look from everywere to get one, now i have it in the form +12345678901</p><p>i fill the thingspeak whit:</p><p>Body = From=+12345678901&amp;To=%%number%%&amp;Body=%%message%%</p><p>but how can i test it?</p><p>i get these link but i dont know how</p><p>https://api.thingspeak.com/apps/thinghttp/send_request?api_key=4DAEVG370UWL2DHT</p><p>if only copy this i get </p><p>&quot;21603A 'From' phone number is required.https://www.twilio.com/docs/errors/21603400&quot;</p>
<p>it should be:</p><p>From=+12345678901&amp;To=%%number%%&amp;Body=%%message%%</p><p>Remove the &quot;Body = &quot; from the line.</p>
<p>I am using NodeMCU to send sms, I can get connected to the internet succesfully, also geting connected to the host too. But it returns -1. I checked all twilio and thingspeak stuffs but it doesnt send me an sms. When I try it via Timboo, it is working correctly. Can you say something about this problem.</p>
<p>Hi, can I use one of these options with Arduino MKR1000? I'm trying to get it to send me a message when outside of WiFi if, say a sensor is triggered. I'm new to programming so I'm not quite sure which one to use as i don't want to have to make hundreds of new accounts! thanks</p>
It would be hard to send a message outside of wifi because the Arduino needs wifi to send the message! You might want to look into a cellular shield or other options. However this code should work with the MKR1000, just replace the client library with the native Arduino wifi library. Good luck!
<p>I understand that! What I meant was, picture this: I'm going out somewhere, for the night or day or whatever, and I want to know if anyone breaks in to my house or if i got mail. A sensor (detecting say if a door was opened) would be triggered and I would receive a text message! Thanks a lot, and sorry for the misunderstanding!</p>
<p>That makes more sense! You could definitely do that using this code. Use the default wifi example, and then add the thing speak default URL call. Or if you're looking for a simpler solution, explore using Temboo. Let me know if you run into any issues.</p>
<p>Hi, I made accounts for Thingspeak and Twilio, and went through all the steps you said, but when I try to upload I get an error message. I think I understand that it's to do with the fact that I haven't made the changes you talked about for using Wifi; I'm not completely sure what these changes should be though! Also I'm struggling to get my MKR's mac address and type it in the correct format for this code! Sorry to be a hassle :-/ </p>
<p>Thank you for your time and attention! I'll try it out and see how it goes! </p>
<p>i'm using ESP8266 module how to send message through that using twilio.<br> &quot;From phone number is required&quot;.<br><br>could u help me plz..<br></p>
The from phone number is your Twilio ten digit number that you receive when you sign up for Twilio.
<p>please how can i write my phone number correctly ? </p>
I believe Twilio wants your phone number in the standard 10 digit form, so +1, then your area code, then your phone number. Let me know if that doesn't work.
<p>I'm not getting a response from the server. I'm using an arduino uno R3 with an ENC28J60 and the UIPEthernet library (so pin 10 instead of 8 for cs). The sketch gets past printing everything to the client, but then client.connected() is never true for the next part: </p><p> while (client.connected())</p><p> {</p><p> if ( client.available() )</p><p> {</p><p> char c = client.read();</p><p> Serial.println(c);</p><p> } </p><p> }</p><p>Any advice?</p>
Have you tried to run some examples from the UIPEthernet library and do they work? If the ENC28J60 cannot connect to the internet that is your first problem. Good luck debugging!
<p>Haiiiiii</p><p>I was trying to implement this project and i have faced some errors. Please help me to resolve it........</p><p>I have given FROM number correctly in Body section.But there comes error stating that &quot;From phone number is required&quot;</p>
<p>Hi karthikeyan,<br><br>Did u succeded in sending message,if so please help me..i've to send msg plz..<br><br>thanks in advance</p>
<p>Hi Lucas,</p><p>Thanks for sharing this, it's really cool. I believe I'm real close to getting it to work. I'm using a cc3000 wifi shield. Here is what is being returned:</p><p><strong>HTTP/1.1 400 Bad Request</strong></p><p><strong>Server: nginx/1.9.3</strong></p><p><strong>Date: Sat, 23 Jan 2016 04:42:03 GMT</strong></p><p><strong>Content-Type: text/html</strong></p><p><strong>Content-Length: 172</strong></p><p>When I manually send the ThingHTTP request I get this message:</p><p>A 'From' phone number is required.https://www.twilio.com/docs/errors/21603400.</p><p>Do you have any ideas regarding this? Here's a dumb questions also, is the phone number I add to the sketch my smartphone number or a number I get from Twilio? Again, thanks for your work!</p><p>David</p>
Hi David, <br>That request could be a number of errors, but I may be able to help. You did the right thing by testing the thingspeak request before trying to run it on the cc3000.<br><br>First off, your twilio number needs to be pasted in the thingspeak request, as the &quot;from&quot; number. Your cellphone number is the &quot;to&quot; number in the arduino sketch. Make sure your cell phone number is verified with twilio if you are using a free account.<br><br>I hope that clears some things up for you, and remeber you can test the thingspeak in a browser befrom running it on the arduino.<br><br>Best of luck!
<p>I have switched over to using the ESP8266 12E (NODEMCU V1) and you mentioned that you were thinking about using the ESP8266 to communicate over WiFi. I'm using the Arduino IDE (1.6.7) with the ESP8266 Add-in libraries. Have you done that and if so is your code available. Opening up the &quot;Cloud&quot; has made the use of these SOC's much more fun. I'm now working with my Son's in Atlanta via a ThingSpeak channel that displays Temp and Humidity of their meat curing chamber. This is where I would like to send an email message when the temperature or humidity gets outside a certain range.</p><p>Thanks in advance for your consideraation.</p><p>AdaBill</p>
Hi AdaBill, Sounds like an interesting project. I have played with the ESP8266 however not with NODEMCU. My projects involve an Arduino communicating over a serial bridge with the ESP8266. Luckily, thingspeak makes this very easy. In fact I believe you can just change the line<br> <br> EthernetClient client; to your wifi class so it would look like&nbsp;WifiClient client; with the associated libraries and it should work.&nbsp;<br> <br> If that doesn't work you can use the example http request in the sendSMS function in your own program.&nbsp;<br> <br> Good luck and if you have any questions feel free to ask!<br> <br>
<p>In Body = From=<em>YOUR TWILIO NUMBER</em>&amp;To=%%number%%&amp;Body=%%message%%</p><p>do I put the + sign in front of my Twilio number?</p>
<p>Yes, I believe you need the + sign. However you could try it both ways and see what works.</p>
<p>It works with the + sign. Thanks for your instructable. I am working on another one and will give you credit for this :-)</p><p>Moltes gr&agrave;cies!</p>
Im glad it worked. Happy making!
<p>I use arduino leonardo and the arduino code is too big. I think that the main problem is library. It is too big.</p><p>What should i do to resolve the problem?</p>
The library I found is smaller than the other options. Are you using other libraries? Maybe you need an Arduino Mega for your project.
<p>This is great! Are you still monitoring this post (in case I have questions xD)?</p>
Yes I am happy to answer questions ( I wasn't getting comment notifications) and I hope your project was successful!
<p>My code is not connecting to api.thingspeak.com</p>
Lets see if we can troubleshoot it. Have you tested loading a page over the internet? Did you update the thingspeak api keys?
<p>Nicely done. Thanks for sharing this!</p>

About This Instructable

38,744views

52favorites

License:

More by lucasxavier11:Send SMS from Arduino over the Internet using ENC28J60 and Thingspeak 
Add instructable to: