Introduction: GSM SIM900 Arduino Daily SMS Message
Using SeeedStudio GSM SIM900 Shield with Arduino and Ting.com SMS
I wanted a way to track activity in building that has power and cell service but no WiFi service, so I turned to a SeeedStudio GSM GPRS SIM900 Arduino shield. I only wanted a single message (email or SMS) sent each morning with a simple report on the movement activity detected over the past 24 hours. The Arduino collects motion sensor data totaling hourly.
Activity seen 123 times 01/12 09:00 – 12 01/12 11:00 – 42 01/12 14:00 – 21 01/12 19:00 – 34 01/12 22:00 – 8 01/13 02:00 – 4 01/13 07:00 – 11
Example of SMS msg
I could have had DSL or Cable Internet installed, but at typically $40/month just to send a few bytes each day seemed a bit much. So, I decided to look into using cellular data. Most cell providers have yet to adopt “real” pricing for very low volume IoT (Internet of Things) type devices. They tend to think that their only customers are smart phone users with high voice/data requirements and price accordingly.
Since this project only needs about 1 kilobyte per day(!), high speed, high volume is NOT a requirement. But low monthly cost is! I found a very good provider “Ting” that has a bottom end plan for small devices starting as little as $6/month. You can get a SIM card from them for the SIM900 for about $9 one-time with no “activation” fee. If you use the link https://z2q89r47d4e.ting.com/ you (and I) can get a bill credit or discount. See below for steps.
SMS vs HTTP
This project uses SMS messaging instead of HTTP, since I wanted an alert on my phone. It is possible to convert to use HTTP, but note that older SIM900’s don’t handle HTTP POST or HTTPS very well. HTTP GET works, though.
There are a number of different versions of the GSM shields available from several vendors, but any that use the sim900 module are similar in both function and price around $60. But, you can sometimes find the older versions at much lower price. I ended up with the SeeedStudio version 1.0 from Radio Shack for about $20. The cost of the GSM module, even new, is about the same as a DSL or Cable Modem. Check eBay for cheap older versions, if you like.
NOTE: Most older SIM900 units do not come with support for HTTPS SSL.
So if you need that, be willing to try to upgrade the firmware:
This project uses SMS, so HTTPS is NOT required.
This system can be adapted to other types of sensors, such as temperature, humidity, water level, gas, etc. instead of the motion sensor I used. Just replace the PIR sensor and feel free to modify the code to add your message output.
Step 1: Requirements
You will need each of the following:
- A GSM GPRS Arduino Shield such as from SeeedStudio. I used an older version 1.0 for this project, but others should be fine. http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0
- An Arduino Uno or similar.
- A PIR Sensor, such as from SeeedStudio, Adafruit, Parallax, etc.
- A SIM card, such as from TING https://z2q89r47d4e.ting.com/
- Software from GITHUB: https://github.com/rgrokett/GSM_SIM900_Arduino
- Arduino IDE from https://www.arduino.cc/en/Main/Software
- USB cable and Arduino IDE version 1.6 or better
- Wires, LED & 220ohm resistor (optional), Case, 5v 1amp power supply
Step 2: Setup
You can assemble and run initial tests of your Arduino and GPRS SIM900 hardware without purchasing a SIM card or service. Then once ready, you can order a SIM card and activate it. Ting delivered mine in only a couple days and activation just took a few minutes. (See below)
Plug your GPRS Shield into your Arduino following the card’s directions. Note that there are several hardware settings needed for these cards. Since these vary, check the GPRS Shield’s web site for details.
Again, you do NOT need a SIM card or battery for this initial setup.
- Be sure the POWER SELECT is set to “Arduino”
- And the Communications UART is set to “Software Serial”
For more information on the SeeedStudio GPRS Shield, try:
- Attach the Antenna and verify its cable connection
NOTE: all of these hardware steps are in the SeeedStudio GPRS Wiki
pages (urls above) in more detail, so feel free to check them out!
Next, plug your USB cable into the Arduino and into your PC.
Install the Arduino IDE onto your PC (if not already installed).
Plug in your Arduino into a USB port on your PC and verify you can compile and load any Arduino Uno program. You will need to check the instructions for using the Arduino IDE for this part. But key is to select the correct board (Tools -> Board -> Arduino/Genuino Uno) and the correct serial port (Tools -> Port -> COM… )
It doesn’t matter what .ino program you try, as it won’t affect the GSM SIM900 board and will be replaced at the next step. You are just trying to verify that your development set up is good.
Step 3: Initial Testing
You can do some initial testing to be sure you can talk to the Arduino and GPRS card ok.
- Download my GPRS PIR application software from GITHUB (see Requirements) and install into a directory in your Documents folder or similar. Navigate to the sketch folder and go to the SerialRelay subfolder and double-click on the SerialRelay.ino program to start the IDE.
This program (courtesy SeeedStudio) just connects a terminal program to the SIM900 so you can issue commands to it.
- Compile and install the SerialRelay.ino program on your PC from the IDE.
- Start a serial monitor; either the one with the Arduino IDE (Tools -> Serial Monitor) or better, download and use their Sscom32E.exe program http://www.seeedstudio.com/wiki/images/b/b2/Sscom...
See SeeedStudio’s Getting Started section of their GPRS Wiki as mentioned above on how to use the sscom32e.exe program.
- Set the serial program to 19200 baud 8-N-1
Note that some SIM900's start at a different baud rate. You'll have to check its doc if you have issues.
- Turn on the GPRS SIM900 board by pressing its power button for 2 seconds.
At power up, a red and green LED will light and another green LED will start flashing.
- You should see some output print on your serial terminal screen similar to:
RDY +CFUN: 1 +CPIN: READY Call Ready
- If you see nothing but gibberish, type AT+IPR=19200 to set the baud rate of the SIM900 and disconnect/reconnect again.
- Try typing AT and return. You should get an OK back.
You can also try typing ATI to see some version info.
Many other commands are available:
- If you are seeing responses to these AT commands, then your hardware is good.
- Next is to get a SIM card and install it.
Step 4: SIM Card
As mentioned earlier, TING is a good low cost provider of the SIM card and GSM service for the SIM900 card.
- Go to Ting.com (Use the link in Parts list to get some bill credits)
- Select BYOD as you have your device!
- Enter the IMEI number as written on the top of your SIM900 chip.
This verifies that they support your device in your area. If there’s no GSM service… yikes!
- You can then order the SIM card (currently $9). They use a “universal” card, so it should work just fine for your SIM900.
NOTE that this does NOT activate your service. So you can sit on the card for up to a year or two with no monthly charges and activate later.
- Once you get the card and are ready to activate, return to the Ting.com URL and click on Activate menu option as shown in the screenshots above.
- You will step thru a series of simple screens, again entering your IMEI number. You next may need to enter your SIM card’s ICCID number (on the bar code), but it may already be filled in and selectable.
- You can select the bottom ($6/mo) service, as any usage will automatically move you up to the next appropriate level.
- Unplug your Arduino and disassemble your GPRS SIM900 from your Arduino so that you can get to the SIM slot. The slot door slides backwards a tiny bit to unlock it (look close; you will see a “lock/unlock” text on its side.) DON'T FORCE IT! Once unlocked, it should open easily.
- Swing the door open and slide the SIM card into it as shown above.
- Close the door and slide it forward a bit to lock it in.
- If you want to use the Real Time Clock (RTC), I suggest installing a CR1220 battery into it now. This will keep the clock accurate with the power off.
NOTE that your cell service provider may not support setting the time automatically, so you may need to do so manually. (Described below)
- Reinstall your SIM900 to your Arduino and plug it back into your PC. It should still have the SerialRelay program so you can just connect to it with your PC serial monitor or sscom32e.exe program again.
- Turn on the SIM900 by pressing the button for 2 seconds.
- Again, try the AT commands above.
- You can check the RTC clock by entering AT+CCLK?
- If you see something like 01/01/01, 0:0:0+0 or other incorrect time, you can set it using:
AT+CCLK="16/02/14,15:45:00+05" (GMT time + offset to local TZ)
- Try AT+CCLK? again for hopefully the correct time!
- The SeeedStudio GPRS wiki page shows how to manually send an SMS message to your mobile phone. Key to remember is to enter the FULL number, like: +19045551212 (country code, area code, local number) no dashes, spaces, etc.
- If you got to here, you are in business and ready to install your application program.
Step 5: Setting Up Your SMS & Sensor Application
Wiring the PIR Sensor
Connect the PIR Sensor to the Arduino using pins shown above.
Wiring the external LED (optional)
Connect a 220 ohm resistor to the long lead of the LED (the positive or anode lead) and to Pin 13. Connect the shorter lead (negative or cathode) to an Arduino GND pin. This is only used to show system activity. Note that there are a number of other LEDs on the Arduino and the GSM module, so you really don’t need this unless you are enclosing the entire thing (except for the PIR sensor) in a box and want an external indicator. This LED will light every time there is motion activity detected.
PIR & SMS Software
You can now replace the SerialRelay.ino program with the example PirGprsSMSAlert.ino program.
You must edit a field in this program to send to your mobile phone. This program is really just an example use case. You probably want to alter to collect different sensor data and send your own message.
// ---- USER MODIFY ---- String MYPHONENUM = "+19045551212"; // Replace with your phone# to send texts to. SMS needs country code // Which hour to send message int timeToSend = 8; // Sends SMS msg Daily at 08:00 AM Set between 1 & 23
This program detects movement and collects the sensor event counts, totaling for each hour for 24 hours and then sends an SMS message with the last few hours of data. It then resets the counts and starts again. It also sends an initial SMS message when the Arduino is reset or powered up to verify it is functioning correctly.
Compile and Upload the modified .ino script. Open the Serial Monitor. It will display startup messages and then send an initial SMS message. As you move in front of the PIR (should be good up to about 15-20 feet away), the (optional) LED will light and messages print on the serial monitor.
At the “timeToSend” time (default is 08:00 clock time), an SMS message with the date/time hour and number of movements detected for each of the past few hours will be sent.
Between sending SMS messages, the GPS SIM900 module is powered down in order to conserve power.
boolean savePower = true;// Conserve power by turning off SIM900 between transmissions
I have been using this program constantly for several weeks now and have reliably received an SMS message every morning.
PLEASE FEEL FREE TO MODIFY THE PROGRAM TO GATHER YOUR OWN SENSOR DATA AND SMS MESSAGE!
Step 6: Extra Info
NOTE that the Arduino SoftwareSerial.h file limits the SMS message to no more than 64 characters! Modify it to increase.
C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\SoftwareSerial.h
You should increase it for SMS messages longer than 64 bytes. BUT, Arduino Uno has a rather small amount of memory for such variables, so you must be sparing in increasing it!
#define _SS_MAX_RX_BUFF 128 // RX buffer size //BEFORE WAS 64
This may not apply to newer versions, so only worry about this if your longer SMS messages are truncated or never even arrive.
We have a be nice policy.
Please be positive and constructive.
thanks for sharing your project with us. Can you please provide me the following libraries (maybe you can put it on GithHub into the same folder as your main source code?)? String.h and Time.h. Many thanks in advance and BR!!
Looks like the Time Libraries have changed with newer Arduino IDE...
You need to change
line 20 #include <Time.h> to #include <TimeLib.h>
If you happen to be missing the newer Time Library, the source is available at:
(You should be able to download it as a Zip and import it into Arduino IDE Sketch->Include Libraries -> Add ZIP File.
String.h is an Arduino IDE built-in library and does not even need to be called as an #include, so you could just comment it out, if you get a compiler complaint.
I have updated the code in https://github.com/rgrokett/GSM_SIM900_Arduino