Introduction: Send SMS From Arduino Over the Internet Using ENC28J60 and Thingspeak
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.
- Using Temboo to send an SMS through Twilio
- Using Lithouse connected to IFTTT to send an SMS
- 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.
- Arduino Uno, or equivalent
- 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:
- A Twilio account. Register at https://www.twilio.com/try-twilio. After signing up, verify your number.
- 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.
- Name it Twilio Send SMS
- URL is https://api.twilio.com/2010-04-01/Accounts/YOUR TWILIO ACCOUNT SID/SMS/Messages
- HTTP Auth Username is YOUR TWILIO ACCOUNT SID
- HTTP Auth Password is YOUR TWILIO AUTH TOKEN
- Set the method to POST
- Content type is application/x-www-form-urlencoded
- Click remove headers, and leave host blank
- 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!
Attachments
1 Person Made This Project!
- blackabbys made it!
51 Comments
1 year ago
I was able to get an SMS send to work by following the instructions here:
https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-esp8266-cpp
I did not need a ThingSpeak account.
2 years ago
I can get connected to the internet succesfully, also geting connected to the host too. But it returns -1. I m using arduino due with ethernet shield in india.
3 years ago
I didnt know to set url. can anyone help me?!!
Reply 3 years ago
of course
1.
Reply 3 years ago
replace YOUR TWILIO ACCOUNT SID with the account sid of your twilio account, you only have to follow the instruccions
3 years ago
hello how I should replace To=%%number%% I from peru. I receive this error, obviusly I change XX from my number
<TwilioResponse><RestException><Code>21211</Code><Message>The 'To' number 519537920XX is not a valid phone number.</Message><MoreInfo>https://www.twilio.com/docs/errors/21211</MoreInfo><Status>400</Status></RestException></TwilioResponse>CLOSED
3 years ago
I didnt know how to frame url can anyone help me?!!
3 years ago
I am not receving message it is not showing any error
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 2
Connection: close
Status: 200 OK
X-Frame-Options: ALLOWALL
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
ETag: "6bb61e3b7bce0931da574d19d1d82c88"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 809e1633-e88b-423d-bba8-a40aa279c0f8
X-Runtime: 0.030564
X-Powered-By: Phusion Passenger 4.0.57
Date: Thu, 24 Aug 2017 09:37:52 GMT
Server: nginx/1.9.3 + Phusion Passenger 4.0.57
3 years ago
The serial port stops at "sending sms" not sheer what the problem is can anyone help?
3 years ago
Hi All!
You can download smarter UIPEthernet library from:
https://github.com/UIPEthernet/UIPEthernet
This support more MCUs and more IDEs.
(UIPEthernet
library for Arduino IDE,Eclipse with arduino plugin and MBED/SMeshStudio
(AVR,STM32F,ESP8266,Intel ARC32, Nordic nRF51, Teensy boards,Realtek
Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet
W5100 Ethernet library API.)
You can find wiring diagrams:
https://github.com/UIPEthernet/UIPEthernet/tree/ma...
Best Regards
4 years ago
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 !!
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 !!
You are the best !!...
4 years ago
Could someone please post example code for WiFi instead of Ethernet. I'm using an ESP8266.
Thank You
4 years ago
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?
Reply 4 years ago
Hi Praveen, is your problem solved? I am having the same issue as yours :(
Reply 4 years ago
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
4 years ago
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? :(
4 years ago
Error:
The 'From' number +XXXXXXXX is not a valid phone number, shortcode,
or alphanumeric sender ID
When I test directly from Twilio, it works, so the problem must be somewhere in the Thingspeak part
4 years ago
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
Setting up WiFi...
Attempting to connect to WEP network, SSID: iotlab
Sending SMS
H
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?
4 years ago
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 "requirements", the SMS service should be free. Am I doing something wrong?
Reply 4 years ago
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!