Random Nerd Tutorials
Shares

Guide to SIM900 GSM GPRS Shield with Arduino

Shares

This post is a complete guide to the SIM900 GSM GPRS Shield with the Arduino. Learn how to send and receive SMS, make and receive phone calls with Arduino.

In this guide we’ll cover:

  • Introducing the SIM900 GSM GPRS Shield
  • SIM900 GSM GPRS Shield Hardware
  • SIM900 AT Commands
  • Testing the shield
  • Sending and receiving SMS – example
  • Making and answering phone calls – example

Introducing the SIM900 GSM GPRS Shield

The SIM900 GSM GPRS Shield is shown in figure below.

GSM stands for Global System for Mobile Communications and is the global standard for mobile communications.

GPRS stands for General Packet Radio Service. GPRS is a mobile service on the 2G and 3G cellular communication.

Applications:

The GSM GPRS shield is particularly useful as it allows to:

  • Connect to the Internet over GPRS network
  • Send and receive SMS
  • Place and receive phones calls

Its capabilities make it perfect for projects with Arduino like:

  • Remote control of electronic appliances – sending an SMS to turn something on;
  • Receive notifications – send SMS to your cell phone if movement is detected in your house;
  • Receive sensor data – send periodic SMS to your cell phone with daily weather data.

Features

Here’s some of the most important features of the shield:

  • Compatible with Arduino and clones
  • Based on SIM900 module from SIMCOM
  • Allows you to send SMS, MMS, GPRS and Audio via UART using AT commands.
  • It has 12 GPIOs, 2 PWMs and buit-in ADC of the SIM900 module
  • Quad Band: 850; 900; 1800 and 1900 MHZ, so it should work in all countries with GSM (2G) networks
  • Control via AT commands
  • Supports RTC (real time clock) – it has a holder for a 3V CR1220 battery at the back

  • Has microphone and headphone jacks for phone calls

Where to buy?

You can check the SIM900 GSM GPRS shield on Maker Advisor and find the best price.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Preliminary steps

Before getting started with your SIM900 GSM GPRS module, you need to consider some aspects about the SIM card and the shield power supply.

GSM coverage

Ensure you have coverage on a GSM 850 MHz, GSM 900 MHz, DCS 1800 MHz or PCS 1900 MHz network. By GSM we mean 2G.

Prepaid SIM Card

We recommend that you use a prepaid plan or a plan with unlimited SMS for testing purposes. Otherwise, if something goes wrong, you may need to pay a huge bill for hundreds of SMS text messages sent by mistake. In this tutorial we’re using a prepaid plan with unlimited SMS.

The shield uses the original SIM card size, not micro or nano. If you have micro or nano you may consider getting a SIM card size adapter.

Turn off the PIN lock

To use the SIM card with the shield, you need to turn off the pin lock. The easiest way to do this, is to insert the SIM card in your smartphone and turn off the pin lock in the phone security settings.

In my case, I needed to go through: SettingsAdvanced SettingsSecuritySIM lock and turn off the lock sim card with pin.

Getting the right power supply

The shield has a DC socket for power as shown in figure below.

Next to the power jack there is a toggle switch to select the power source. Next to the toggle switch on the board, there is an arrow indicating the toggle position to use an external power supply – move the toggle switch to use the external power supply as shown above.

To power up the shield, it is advisable to use a 5V power supply that can provide 2A as the one shown below. It can also be powered with 9V 1A, or 12V 1A.

You can find the right power adapter for this shield here. Make sure you select the model with 5V and 2A.

SIM900 GSM GPRS Shield Hardware

The figure below shows the back of the shield. It has a holder for the SIM card and for a 3V CR1220 battery for the RTC (real time clock).

The figure below shows the shield most important components on the board that you need to pay attention to.

Getting started

1) Insert the SIM card into the SIM card holder – make sure you’ve read the preliminary steps in the previous section.2) Make sure the antenna is well connected.

3) On the serial port select, make sure the jumper cap is connected as shown in figure below to use software serial.

4) Power the shield using an external 5V power supply. Make sure you select the external power source with the toggle switch next to the DC jack.

5) To power up/down the shield press the power key for about 2 seconds.

6) Then, the Status LED will light up and the NetLight LED will blink every 800 ms until it finds the network. When it finds the network, the NetLight LED will start blinking every three seconds.

Note: you can automatically turn on the shield via software. See how to do that in the Automatically turn on the shield section, after the code examples.

7) You can test if the shield is working properly by sending AT commands from the Arduino IDE using an FTDI programmer – as we’ll shown later in this guide.

SIM900 AT commands

  • set the SIM900 to text mode: AT+CMGF=1\r
  • send SMS to a number: AT+CMGS=PHONE_NUMBER (in international format)
  • read the first SMS from the inbox: AT+CMGR=1\r
  • read the second SMS from the inbox: AT+CMGR=2\r
  • read all SMS from the inbox: AT+CMGR=ALL\r
  • call to a number: ATDP+ PHONE_NUMBER (in international format)
  • hang up a call: ATH
  • receive an incoming call: ATA

For more information, you can check the SIM900 AT commands manual here.

Testing the Shield with FTDI programmer

To test if everything is working properly, you can test the shield by sending AT commands from the Arduino IDE serial monitor. For that, you need an FTDI programmer as the one shown in figure below. You can get an FTDI programmer like this here.

1) Connect the FTDI programmer to the GSM shield as shown in figure below.

2) Open the Arduino IDE and select the right COM port.

3) Open the Serial monitor 

4) Select 19200 baud rate – the shield default setting is 19200 – and Carriage return. Write AT at the box highlighted in red and then press enter. See figure below. 

5) The shield will respond with OK, if everything is working properly.

Connecting the Shield to Arduino

Connect the shield to the Arduino as shown in the schematics below.

Sending an SMS

To send an SMS, upload the code below to your Arduino board.

In this code,  you start by  including the SoftwareSerial.h library and create a software serial port on pins 7 and 8. (Pin 7 is being set as RX and 8 as TX)

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

The sendSMS() function created is what actually sends the SMS. This function uses the AT commands: AT+CMGF=1\r and AT + CMGS.

You need to change the recipient’s mobile number at: (replace the X‘s with the recipient’s phone number)

SIM900.println("AT + CMGS = \"++++++++++++++"");

The recipient’s mobile number should be in international format.

Then, at the following line you can edit the text you want to send.

// REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
SIM900.println("Message example from Arduino Uno.")

Reading received SMS

To read incoming SMS, upload the code below to your Arduino. After uploading, wait 20 seconds for the shield to establish communication. Then, test the script by sending an SMS to the shield SIM card number. The SMS is shown on the Arduino serial monitor – baud rate: 19200.

In this code, you set the module to send the SMS data to the serial output:

SIM900.print("AT+CNMI=2,2,0,0,0\r");

You store the incoming characters from the SMS message on the incoming_char variable. You read the chars using the SIM900.read() function.

Making a phone call

To make a phone call, upload the following code to your Arduino.

Don’t forget to edit the code with the phone number you want to call.

To make the call, you use the callSomeone() function that uses the ATD command.

SIM900.println("ATD + +XXXXXXXXX;");

You need to replace the X‘s (highlighted in red) with the phone number you want to call.

Don’t forget to connect a microphone and earphones to make the call.

In this code example, the call is hang up after 30 seconds, using the ATH command:

SIM900.println("ATH"); 

Hanging up after 30 seconds is not very useful, but it works well for an example. The idea is that you use the ATH command when an event is triggered. For example, connect a push button to the Arduino, that when pressed sends the ATH command to hang up the phone.

Answering incoming phone calls

The following code answers incoming calls.

When someone calls the SIM900 number, it sends a message saying “RING”. To know if someone is calling you, you can wait for incoming characters from the SIM900 and then, compare if it was a RING message.  That’s what is done in this code. When it receives a RING message, you send the ATA command to answer the phone.

Automatically turn on the shield

Instead of manually pressing the “power” key to turn on the shield, you can automatically turn on the shield via software.

1) First, you need to solder R13 connections on the shield as shown in the figure below – highlighted in red.

2) Connect D9 on the shield to the D9 Arduino pin as shown in the schematic below.

3) Add the following code snippet in the setup() function. This is the equivalent of pressing the shield “power” button.

digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);

Troubleshooting

Shield doesn’t respond with OK

Check your TX and RX connections to the Arduino. Try repeating the process by changing the TX with the RX pins.

Also check if you have selected the software serial by placing the jumper cap on the appropriate place on the serial selector.

Cannot see messages in the serial monitor

To see the messages in the serial monitor, the shield and the Arduino’s serial port baud rate should be the same. The SIM900 GSM GPRS shield default baud rate is 19200. So, select the Arduino’s baud rate to 19200.

However, if you need to change the shield baud rate, you can send the following AT command to change it to 19200 or other appropriate baud rate.

AT+IPR=19200

Wrapping up

This tutorial shows you how to send and receive SMS and making and receiving phone calls with the Arduino. You can apply the concepts learned in this tutorial to build your own projects to communicate over a cell network. For ideas on GSM projects check the shield’s Applications suggestions at the beginning of the post.

If you like Arduino projects, make sure you check our latest Arduino course that features a more advanced GSM project: Arduino Step-by-step Projects – Build 25 Projects

We hope you’ve found this guide useful.

Thanks for reading.

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off