Tutorial: Arduino and GSM Cellular – Part One
Connect your Arduino to the cellular network with the SM5100 GSM module shield. This is chapter twenty-six of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 18/03/2013
Introduction
The purpose of this tutorial is to have your Arduino to communicate over a GSM mobile telephone network using the SM5100B GSM Cellular Shield:
This is the first of several articles related to the SM5100B GSM shield. My goal is to illustrate various methods of interaction between an Arduino and the GSM cellular network using the shield, with which you can then use your existing knowledge to build upon those methods. Doing so isn’t easy – but it isn’t that difficult.
Stop! Please read first:
- It is assumed that you have a solid understanding of how to program your Arduino. If not, start from chapter zero
- Read the “boring stuff” section on my About page
- Sending SMS messages and making phone calls cost real money, so it would be very wise to use a prepaid cellular account or one that allows a fair amount of calls/SMS
- The GSM shield only works with “2G” GSM mobile networks operating on the 850, 900 and PCS1800 MHz frequencies. If in doubt, ask your carrier first
- Australians – you can use any carrier’s SIM card, except for “Three”
- Canadians – this doesn’t work with Sasktel
- North Americans – check with your cellular carrier first if you can use third-party hardware (i.e. the shield)
- I cannot offer design advice for your project nor technical support for this article.
- If you are working on a college/university project and need specific help – talk to your tutors or academic staff. They get paid to help you.
- Please don’t make an auto-dialler…
![From http://simpsons.wikia.com/wiki/User:Jihem [CC by-sa]](http://images1.wikia.nocookie.net/__cb20091128195239/simpsons/images/1/1a/AutoDialer_AT5000.jpg)
As mentioned previously, we’re using the Sparkfun GSM shield with the SM5100B module. When you order the shield, don’t forget to order the stacking header pin set as they’re not included with the shield, and you’ll need to solder them on yourself. Power -the GSM shield can often require up to 2A of current in short bursts – especially when turned on, reset, or initiating a call. However your Arduino board can only supply just under 1A. It is highly recommended that you use an external regulated 5V power supply capable of delivering 2A of current – from an AC adaptor, large battery with power regulator, etc. Otherwise there is a very strong probability of damaging your shield and Arduino.
Ignore this at your own risk
When connecting this supply DO NOT use the DC socket on the Arduino. Instead, connect the 5V (positive) from the supply to the 5V pin on the GSM shield, and the negative to the GND pin.
If you’re looking for a more permanent or easy-to-wire solution, get yourself a DFRobot power shield:
This shield sits on top of your GSM shield (which sits on top of your Arduino). Before use you need to set it up:
- The only jumpers that should be on the power shield are as shown in the image above;
- Connect a power supply of between 9 and 35V DC to the blue terminal block at the bottom-left of the shield;
- Connect a voltmeter/multimeter to the other blue terminal block at the top-left and adjust the potentiometer (blue thing between the terminal blocks) until the voltage measured is 5 volts; ignore the LEDs on the shield as they’re not that accurate;
- Run a wire from the positive power output to the 5V pin on the shield, and run another one from the negative power output to a GND pin on the shield;
- If you have the USB cable connected to your project while operating the GSM shield, remove the USB cable before turning off external power to the project.
Here’s what it looks like once assembled with the antenna:
Next – use an antenna! The wire hanging from the shield is not an antenna. YOU NEED THE ANTENNA! There are two choices. Either use the smaller one for areas where handheld mobile reception is acceptable, such as this one:
Or if you are in an area of weaker reception, use an external antenna such as that used on a motor vehicle. If you are using the larger vehicle-style aerial, you might find that the plug will not fit to the shield’s connector. For example, consider the following:
On the left is the end of the lead from the carphone aerial, the right is the lead from the GSM shield. Problem! The solution is in the centre: an FME male to SMA male adaptor. This one came from element-14, part number 1826209 (it is a Multicomp R23-014-00-002611000).
Furthermore, care needs to be taken with your GSM shield with regards to the aerial lead-module connection, it is very fragile:
And finally, download this document (.pdf). It contains all the AT and ERROR codes that will turn up when you least expect it. Please review it if you are presented with a code you are unsure about.
Wow – all those rules and warnings?
The sections above may sound a little authoritarian, however I want your project to be a success. With the previous iterations of the tutorial people just didn’t follow the instructions – so I hope you do
Are you using an Arduino Mega or Leonardo board?
Things are a little different for you. Those boards don’t support SoftwareSerial on digital pins 2 and 3 thus rendering the GSM shield a little trickier to use. Instead, bend back the D2 and D3 pins on the GSM shield as such (click image to enlarge):
Then run jumpers from D2 on the attached shield to D10 and another from D3 to D11. If you’re using the aforementioned power shield it would be on top of the GSM shield however the jumper wires would be the same. Finally in all the sketches, change the line SoftwareSerial cell(2,3); to SoftwareSerial cell(10,11); . If you have a Leonardo, get a Uno.
Initial check – does it work?
This may sound like a silly question, but considering the cost of the shield and the variables involved, it is a good idea to check if your setup is functioning correctly before moving on. From a hardware perspective for this article, you will need your Arduino board, the GSM shield with activated SIM card and an aerial, and a range of previously used components. Make sure your SIM card is set to not require a PIN when the phone is turned on. You can check and turn this requirement off with your cellphone. For our initial test, upload the following sketch:
#include <SoftwareSerial.h>
char incoming_char=0; //Will hold the incoming character from the Serial Port.
SoftwareSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
void setup()
{
//Initialize serial ports for communication.
Serial.begin(9600);
cell.begin(9600);
Serial.println("Starting SM5100B Communication...");
}
void loop()
{
//If a character comes in from the cellular module...
if(cell.available() >0)
{
incoming_char=cell.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
//If a character is coming from the terminal to the Arduino...
if(Serial.available() >0)
{
incoming_char=Serial.read(); //Get the character coming from the terminal
cell.print(incoming_char); //Send the character to the cellular module.
}
}
Then connect the GSM shield, aerial, insert the SIM card and apply power. Open the serial monitor box in the Arduino IDE and you should be presented with the following:
It will take around fifteen to thirty seconds for the text above to appear in full. What you are being presented with is a log of the GSM module’s actions. But what do they all mean?
- +SIND: 1 means the SIM card has been inserted;
- the +SIND: 10 line shows the status of the in-module phone book. Nothing to worry about there for us at the moment;
- +SIND: 11 means the module has registered with the cellular network
- +SIND: 3 means the module is partially ready to communicate
- and +SIND: 4 means the module is registered on the network, and ready to communicate
If your terminal returned a +SIND 8 instead of 4, that is OK, we’ll sort that out in a moment. From this point on, we will need to use a different terminal program, as the Arduino IDE’s serial monitor box isn’t made for full two-way communications. You will need a terminal program that can offer full two-way com port/serial communication. For those running MS Windows, an excellent option is available here. It’s free, however consider donating for the use of it. For other operating systems, people say this works well. So now let’s try it out with the terminal software. Close your Arduino IDE serial monitor box if still open, then run your terminal, set it to look at the same serial port as the Arduino IDE was. Ensure the settings are 9600, 8, N, 1. Then reset your Arduino and the following should appear:
The next step is to tell the GSM module which network frequency(ies) to use. Please download this document (.pdf), and view page 127. There is a range of frequency choices that our module can use. If you don’t know which one to use, contact the telephone company that your SIM card came from. Australia – use option 4. Choose your option, then enter
AT+SBAND=x
(where X is the value matching your required frequency) into the terminal software and click SEND. Then press reset on the Arduino and watch the terminal display. You should hopefully be presented with the same text as above, ending with +SIND: 4. If your module returns +SIND: 4, we’re ready to move forward.
Our next test is to call our shield. So, pick up a phone and call it. Your shield will return data to the terminal window, for example:
As you can see, the module returns what is happening. I let the originating phone “ring” twice, and the module received the caller ID data (sorry, blacked it out). Some telephone subscribers’ accounts don’t send caller ID data, so if you don’t see your number, no problem. “NO CARRIER” occurred when I ended the call. +SIND: 6,1 means the call ended and the SIM is ready.
Have your Arduino “call you”
The document (.pdf) we downloaded earlier contains a list of AT commands – consider this a guide to the language with which we instruct the GSM module to do things. Let’s try out some more commands before completing our initial test. The first one is:
ATDxxxxxx
which dials a telephone number xxxxxx. For example, to call (212)-8675309 use
ATD2128675309
The next one is
ATH
which “hangs up” or ends the call. So, let’s reach out and touch someone. In the terminal software, enter your ATDxxxxxxxx command, then hit send. Let your phone ring. Then enter ATH to end the call. If you are experimenting and want to hang up in a hurry, you can also hit reset on the Arduino and it will end the call as well as resetting the system. So by now you should realise the GSM module is controlled by these AT commands.
To use an AT command in a sketch, we use the function
cell.println()
for example, to dial a phone number, we would use
cell.println("ATD2128675309");
To demonstrate this in a sketch, consider:
A simple sketch to dial a telephone number, wait, then hang up. Replace xxxxxxxx with the number you wish to call.
#include <SoftwareSerial.h>
SoftwareSerial cell(2,3);
void setup()
{
cell.begin(9600);
delay(25000); // give the GSM module time to initialise, locate network etc.
// this delay time varies. Use example 26.1 sketch to measure the amount
// of time from board reset to SIND: 4, then add five seconds just in case
}
void loop()
{
cell.println("ATDxxxxxxxxx"); // dial the phone number xxxxxxxxx
// change xxxxxxx to your desired phone number (with area code)
delay(20000); // wait 20 seconds.
cell.println("ATH"); // end call
do // remove this loop at your peril
{
delay(1);
}
while (1>0);
}
The sketch in example 26.2 assumes that all is well with regards to the GSM module, that is the SIM card is ok, there is reception, etc. The delay function in void setup() is used to allow time for the module to wake up and get connected to the network. Later on we will read the messages from the GSM module to allow our sketches to deal with errors and so on. However, you can see how we can simply dial a telephone. You could now have a home alarm system that can call you upon an event happening, etc.
Send an SMS from your Arduino
Another popular function is the SMS or short message service, or text messaging. Before moving forward, download and install Meir Michanie’s SerialGSM Arduino library from here.
Sending a text message is incredibly simple – consider the following sketch:
#include <SerialGSM.h>
#include <SoftwareSerial.h>
SerialGSM cell(2,3);
void setup()
{
delay(30000); // wait for GSM module
cell.begin(9600);
}
void sendSMS()
{
cell.Verbose(true); // used for debugging
cell.Boot();
cell.FwdSMS2Serial();
cell.Rcpt("+xxxxxxxxx"); // replace xxxxxxxxx with the recipient's cellular number
cell.Message("Contents of your text message");
cell.SendSMS();
}
void loop()
{
sendSMS();
do // remove this loop at your peril
{
delay(1);
}
while (1>0);
}
It’s super-simple – just change the phone number to send the text message, and of course the message you want to send. The phone numbers must be in international format, e.g. Australia 0418 123456 is +61418123456 or USA (609) 8675309 is +16098675309.
Well that is all we have time for in this instalment. Now you can move onto GSM and Arduino – part two.
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
January 19, 2011 Posted by John Boxall | arduino, CEL-00675, CEL-09607, cellphone hacking, cellular, GSM, SMS, tronixstuff, tutorial | 1800, 850, 900, arduino, ATT, call, card, CEL-09607, cellphone, cellular, control, education, electronics, GPRS, GSM, GSM1800, GSM850, GSM900, guide, guides, hacking, lesson, lessons, message, MHz, microcontrollers, mobile, monitor, network, optus, PCS, project, projects, remote, shield, SIM, SM5100, SM5100B, SMB5100B, SMS, sparkfun, spreadtrum, telephone, telstra, text, tutorial, tutorials, VHA, vodafone | 20 Comments
YouTube
Visit tronixstuff on YouTube for our range of videosClock Projects
Zero - blinky the clock
One - DMD clock
Two - Single digit clock
Three - Pillow clock
Four - Scrolling text clockArduino Tutorials
Click for Detailed Chapter Index
Chapters 0 1 2 3 4
Chapters 5 6 6a 7 8
Chapters 9 10 11 12 13
Ch. 14 - XBee
Ch. 15 - RFID - RDM-630
Ch. 15a - RFID - ID-20
Ch. 16 - Ethernet
Ch. 17 - GPS part I
Ch. 18 - RGB matrix
Ch. 19 - GPS part II
Ch. 20 - I2C bus part I
Ch. 21 - I2C bus part II
Ch. 22 - AREF pin
Ch. 23 - Touch screen
Ch. 24 - Monochrome LCD
Ch. 25 - Analog buttons
Ch. 26 - Arduino + GSM - part I
Ch. 27 - Arduino + GSM - part II
Ch. 28 - Colour LCD
Ch. 29 - TFT LCD
Ch. 30 - Arduino + twitter
Ch. 31 - Inbuilt EEPROM
Ch. 32 - Infra-red control
Ch. 33 - Control AC via SMS
Ch. 34 - SPI bus part I
Ch. 35 - Video-out
Ch. 36 - SPI bus part II
Ch. 37 - Timing with millis()
Ch. 38 - Thermal Printer
Ch. 39 - NXP SAA1064
Ch. 40 - Push wheel switches
Ch. 40a - Wheel switches II
Ch. 41 - More digital I/O
Ch. 42 - Numeric keypads
Ch. 42a - Keypads II
Ch. 43 - Port Manipulation
Ch. 44 - ATtiny+Arduino
Ch. 45 - Ultrasonic Sensor
Ch. 46 - Analog + buttons II
Ch. 47 - Internet-controlled relays
Ch. 48 - MSGEQ7 Spectrum Analyzer
Arduino Due - first look
Ch. 49 - KTM-S1201 LCD modules
Ch. 50 - ILI9325 colour TFT LCD modules
Ch. 51 - MC14489 LED display driver IC
Search
RSS Feeds
Categories
Previous posts
Archives
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- October 2012
- September 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
Contact information
email - john at tronixstuff dot com
Google Group
Australian Electronics!
Buy and support Silicon Chip - Australia's only Electronics Magazine.Creative Commons
All the original material in this website, unless noted otherwise, is covered under a Creative Commons Attribution-Non Commercial-Share Alike v3.0 license. Please email me if you see any mis-attributions or would like to use my content in different circumstances.on twitter…
- "Arduino Workshop" will soon be available in Chinese (simplified and traditional), German and Polish... nostarch.com/arduino @arduino 7 hours ago
- @BruceHoult There's a good review of those in May Silicon Chip magazine. 1 day ago
- Australia’s Slow-Motion Car Crash theglobalmail.org/blog/australia… via @TheGlobalMail 1 day ago
- Thanks everyone - logic probe kit review won - altronics.com.au/index.asp?area… 1 day ago
- @Sqrt_2GM_over_R No, only single-ended ADC 1 day ago
Flickr Photos



More PhotosFind me on…
Interesting Sites
David L. Jones' eev blog
Freetronics Arduino Geniuses!
Silicon Chip magazine Always a great read!
Amazing Arduino Shield Directory
The Amp Hour podcast
EEWeb Elec Engineering Forum
Superhouse.tv High-tech home renovation
Mr Dick Smith OANuclear weapons = global suicide
In a war with nuclear weapons, everybody loses. Please check these out:
Count Down to Zero
The War Game
Threads










