Send Receive SMS & Call with SIM900 GSM Shield & Arduino

Whether you want to monitor your home from afar or activate the sprinkler system in your garden with a missed call; then the SIM900 GSM/GPRS shield can serve as a solid launching point!

The SIM900 GSM/GPRS shield is a GSM modem that can be used in a variety of IoT projects. You can use this shield to do almost anything a normal cell phone can do, such as sending SMS messages, making phone calls, connecting to the Internet via GPRS, and much more.

To top it all off, the shield supports quad-band GSM/GPRS networks, which means it will work almost anywhere in the world.

Hardware Overview

The SIM900 GSM/GPRS shield is designed to surround the SIM900 chip with everything needed to interface with Arduino, as well as a few extra goodies to take advantage of the chip’s unique features.

Let’s get acquainted with the shield’s features and abilities. Here’s a quick overview:

SIM900 GSM GPRS Shield Top Hardware Overview
SIM900 GSM GPRS Shield Bottom Hardware Overview

The SIM900 shield is packed with features. Here is a list of a few of them:

  • Supports Quad-band: GSM850, EGSM900, DCS1800 and PCS1900
  • Connect onto any global GSM network with any 2G SIM
  • Make and receive voice calls using an external earphone & electret microphone
  • Send and receive SMS messages
  • Send and receive GPRS data (TCP/IP, HTTP, etc.)
  • Scan and receive FM radio broadcasts
  • Transmit Power:
    • Class 4 (2W) for GSM850
    • Class 1 (1W) for DCS1800
  • Serial-based AT Command Set
  • U.FL and SMA connectors for cell antenna
  • Accepts Full-size SIM Card

LED Status Indicators

The SIM900 shield has three LEDs that indicate network connectivity and power status. By observing these LEDs, you can get a visual indication of the shield’s status.

LED Indicator on SIM900 GSM Shield

PWR: This LED is connected to the shield’s power supply line. If this LED is lit, the shield is receiving power.

Status: This LED indicates the SIM900’s working status. If this LED is lit, the chip is in working mode.

Netlight: This LED indicates the status of your cellular network. It will blink at different rates depending on the state it is in.

  • OFF: The module is powering on (assuming it has power).
  • 64ms on, 800ms off: The SIM900 chip is running but hasn’t made connection to the cellular network yet.
  • 64ms on, 3 seconds off: The SIM900 chip has made contact with the cellular network and can send/receive voice and SMS.
  • 64ms on, 300ms off: The GPRS data connection you requested is active.

Supplying Power

One of the most important parts of getting the SIM900 shield working is supplying it with enough power.

The SIM900, depending on its state, can be a relatively power-hungry device. The shield’s maximum current draw is around 2A (especially during a transmission burst). It won’t usually draw that much, but it may need around 216mA during phone calls or 80mA during network transmissions. This chart from the datasheet summarizes what you can expect:

ModesFrequencyCurrent Consumption
Power down60 uA
Sleep mode1 mA
Stand by18 mA
CallGSM850199 mA
EGSM900216 mA
DCS1800146 mA
PCS1900131 mA
GPRS453 mA
Transmission burst2 A

The operating voltage of the SIM900 chip ranges from 3.4V to 4.4V. The shield includes a Micrel MIC29302WU high current, high accuracy, low-dropout voltage regulator to keep the supply voltage safe at 4.1V. Furthermore, it can handle load currents of up to 3A.

DC Jack Power Selection MIC29302 on SIM900 GSM Shield

The shield has a 5.5mm DC jack to which you can connect any 5V-9V DC wall adapter. Next to the DC jack is a Slide Switch labeled EXTERN that lets you choose the power source. To use an external power source, move the slider as shown above.

Warning:

The power supply must be capable of supplying at least 2A of surge current; otherwise, the chip will repeatedly reset.

UART Communication

The SIM900 shield uses UART protocol to communicate with an Arduino. The module supports baud rate from 1200 bps to 115200 bps with Auto-Baud detection.

UART Selection Jumper on SIM900 GSM Shield

The UART selection jumpers allow you to switch the shield’s RX and TX between either pins D8 and D7, or D1 and D0. That means selecting between a software UART(D8, D7) or hardware UART(D1, D0).

UART Selection Jumper Settings on SIM900 GSM Shield

Speaker and Microphone

The shield includes two standard 3.5mm jacks, one for stereo earphones and the other for a microphone. You can use it to make and receive phone calls, as well as listen to FM radio.

Speaker Microphone on SIM900 GSM Shield

Mic: You can use this jack to connect an external electret microphone. No extra circuitry is required for the mic, just wire it up directly!

Earphone: You can use this jack to connect earphones. Any iPhone or Android-compatible earphones should work.

Antenna

The SIM900 requires an external antenna connected to the shield for any type of voice or data communication, as well as to execute some AT commands.

Antenna U

The shield has two antenna connectors: a U.FL connector and a SMA connector. They are linked together by a patch cord.

The shield usually comes with a 3dBi GSM antenna, allowing the shield to be enclosed in a metal case (as long the antenna is outside).

SIM Socket

There’s a SIM socket on the back! Any 2G full-size SIM card will work perfectly.

SIM Holder on SIM900 GSM Shield

Using the SIM card socket may seem confusing at first. To unlock the latch, push the top part of the assembly towards the “OPEN” position and then lift it up. Insert the SIM card into the moving part of the socket. Fold the arm back into the socket’s body and gently push it forward toward the “LOCK” position.

RTC(Real Time Clock)

The SIM900 shield has the ability to keep time, eliminating the need for a separate RTC.

CR1220 RTC Battery Holder on SIM900 GSM Shield

To use the RTC, you must install a CR1220 battery on the shield’s back side. It helps maintain time when the power is out.

If your network provider does not support setting the time automatically, you can do so manually with the AT+CCLK AT command.

Connecting the SIM900 GSM/GPRS Shield to Arduino

Now that you are familiar with the SIM900 Shield, it is time to connect it to Arduino!

Begin by mounting the SIM900 shield on top of an Arduino. As we will be communicating with the shield via software UART, place the jumper cap on the software serial port select.

wiring sim900 gsm gprs shield with arduino uno

It should be noted that the SIM900 Shield will not work if your Arduino is only powered off USB. Use an external 5V 2A power supply to power the shield. Also, make sure the external power source is selected using the slide switch next to the DC jack.

Finally, connect the antenna and insert a fully activated SIM card into the socket.

Turning On and Off the SIM900 Chip

Even if the shield is receiving power, it cannot function unless the SIM900 chip is turned on. This can be done in two ways.

With Hardware – POWER Button

SIM900 GPRS GSM Shield Development Board Quad Band Module For Compatible 1

The shield includes a right angle tactile switch that connects to the SIM900’s PWRKEY input, which turns the chip on or off.

This button works exactly like the power button on a cell phone. If the chip is off, hold the button down for 1-2 seconds then release to turn it on. If the chip is on and you hold the button down and release, it’ll turn off.

With Software

Instead of pressing the POWER button every time, you can programmatically turn the SIM900 on and off.

Control of the POWER button is shared between the physical button itself and Arduino pin D9. So pulling pin D9 LOW has the same effect as pushing the button down.

To make this work, you must solder the SMD jumper labeled R13 on the shield, as shown in the image. This jumper allows you to connect Arduino pin D9 to the SIM900’s POWER button.

Solder R13 Jumper on SIM900 GSM Shield For Software Control

You can now insert the following code snippet into the setup() function. This is equivalent to pressing the POWER button.

digitalWrite(9,LOW);
delay(2000);
digitalWrite(9,HIGH);
delay(2000);

Arduino Code – Testing AT Commands

To send AT commands and communicate with the SIM900 shield, we will be using the Serial Monitor. The sketch below will enable the Arduino to communicate with the SIM900 shield over the serial monitor. Before we proceed with the detailed analysis of the code, connect your Arduino to PC, compile the below code and upload it to Arduino.

Once you open the Serial Monitor, make sure the ‘Both NL and CR’ option is selected!

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();
  mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
  updateSerial();
  mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
  updateSerial();
  mySerial.println("AT+CREG?"); //Check whether it has registered in the network
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

Once you have uploaded the sketch, open the serial monitor at baud rate 9600. You should see the output below on the serial monitor.

SIM900 GSM Shield Basic AT Commands on Arduino

Code Explanation:

The sketch begins by including the SoftwareSerial.h library and initializing the SoftwareSerial object with the Arduino pins to which the Tx and Rx of the SIM900 shield are connected.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

In the setup function, we initiate a serial communication link between the Arduino, the Arduino IDE and the SIM900 shield at a baud rate of 9600.

//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);

//Begin serial communication with Arduino and SIM900
mySerial.begin(9600);

Now that we have established a basic connection, we will try to communicate with the SIM900 shield by sending AT commands.

AT – This is the most basic AT command. It also initializes the Auto-bauder. If all is well, it sends the OK message, telling you that it is understanding you correctly. You can then send some commands to query the chip and get information about it.

AT+CSQ – It checks ‘Signal Strength’. The first number in the output response is the signal strength in dB. It should be more than around 5. Higher is better. Note that this signal strength depends on your antenna and location!

AT+CCID – It checks whether the SIM card is valid or not and sends the SIM card number.

AT+CREG? It checks whether you are registered to the network or not. The second number in the output response should be 1 or 5. 1 indicates that you are registered to a home network and 5 indicates a roaming network. Any number other than these two indicates that you are not registered to any network.

mySerial.println("AT"); //Handshaking with SIM900
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();

In the loop, we call a custom function called updateSerial() which continuously waits for any input from the serial monitor and sends it to the SIM900 shield via the D8 pin (the shield’s RX). It also continuously reads the D7 pin (the shield’s TX) to see if there is a response from the shield.

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

Try Sending Different AT Commands

You can now send commands like the ones below through the Serial Monitor to get more information about your network connection and battery status:

ATI – Returns the module name and revision.

AT+COPS? – Checks which network you are connected to.

AT+COPS=? – Returns the list of operators present in the network.

AT+CBC – Returns Li-Po battery status. The second number is the battery level (in our case it is 93%) and the third number is the actual voltage in mV (in our case 3.877 V)

SIM900 GSM Shield Network Connection AT Commands on Arduino

Arduino Code – Sending an SMS

Let’s move on to the interesting stuff. Let’s program our Arduino to send an SMS.

Before trying out the sketch, you’ll need to enter the phone number to which you want to send an SMS. Look for the highlighted string ZZxxxxxxxxxx and replace ZZ with the county code and xxxxxxxxxx with the 10 digit phone number.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();

  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
 mySerial.println("AT+CMGS=\"+ZZxxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
  updateSerial();
  mySerial.print("Last Minute Engineers | lastminuteengineers.com"); //text content
  updateSerial();
  mySerial.write(26);
}

void loop()
{
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

The screenshot below shows the SMS sent from the SIM900 shield.

SIM900 GSM Shield AT Commands for Sending SMS on Arduino
Sending SMS through SIM900 GSM Shield

Code Explanation:

The sketch is almost the same as the first sketch except for the code snippet below. Once the connection is established, we send the following AT commands:

AT+CMGF=1 – Selects the SMS message format as text. The default format is Protocol Data Unit (PDU).

AT+CMGS=+ZZxxxxxxxxxx – Sends SMS to the specified phone number. After this AT command any text message followed by ‘Ctrl+z’ character is treated as SMS. ‘Ctrl+z’ is actually a 26th non-printing character that is described as ‘substitute’ in the ASCII table. Therefore, we need to send 26 (0x1A) at the end of the command.

mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+ZZxxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print("Last Minute Engineers | lastminuteengineers.com"); //text content
updateSerial();
mySerial.write(26);

The loop is kept empty because we want to send SMS only once. If you want to send SMS one more time, just press the RESET key on your Arduino.

Arduino Code – Reading an SMS

Now let’s program our Arduino to read incoming messages. This sketch can be very useful when you need to perform an action like turn ON/OFF lights, enable the fan, or enable the sprinkler system when you receive a specific SMS.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

Once you send SMS to the SIM900 shield, you will see the following output on the serial monitor.

Reading SMS through SIM900 GSM Shield
SIM900 GSM Shield AT Commands for Reading SMS on Arduino

As you can see the output response starts with +CMT: All the fields in the response are comma separated where the first field is the phone number and the second field is the name of the person sending the SMS. The third field is a timestamp while the fourth field is the actual message.

Code Explanation:

The sketch is almost the same as the first sketch except for the code snippet below. Once the connection is established, we send the following AT commands:

AT+CMGF=1 – Selects the SMS message format as text. The default format is Protocol Data Unit (PDU)

AT+CNMI=1,2,0,0,0 – Specifies how incoming SMS messages should be handled. This way you can tell the SIM900 to either forward incoming SMS messages directly to the PC, or save them to the message storage and then inform the PC about their locations in the message storage.

mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
updateSerial();

Note that this time we have not kept the loop empty as we are polling incoming SMS messages.

Expanding Arduino SoftwareSerial Buffer Size

If your message is sufficiently lengthy as the one above, you’ll probably receive it with some missing characters. This is not because of a faulty code, but because the ‘Software Serial Receive Buffer’ is filling up completely, discarding the remaining characters.

The simplest solution is to increase the size of the SoftwareSerial buffer to 256 bytes from the default size of 64 bytes.

On a Windows PC, go to C:\Program Files (x86) > Arduino > hardware > Arduino > avr > libraries > SoftwareSerial (> src for newer version of Arduino IDE). Open SoftwareSerial.h and change this line:

// RX buffer size
#define _SS_MAX_RX_BUFF 64

to

// RX buffer size
#define _SS_MAX_RX_BUFF 256

Save the file and try the sketch again.

Expanding Arduino SoftwareSerial Buffer Size

Arduino Code – Making a Call

Now let’s program our Arduino to make a call. This sketch can be very useful when you want your Arduino to make a SOS/distress call in case of an emergency like the temperature is exceeded or someone breaks into your house.

Before trying out the sketch, you’ll need to enter the phone number you want to call. Look for the highlighted string ZZxxxxxxxxxx and replace ZZ with the county code and xxxxxxxxxx with the 10 digit phone number.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();
  
 mySerial.println("ATD+ +ZZxxxxxxxxxx;"); //  change ZZ with country code and xxxxxxxxxxx with phone number to dial
  updateSerial();
  delay(20000); // wait for 20 seconds...
  mySerial.println("ATH"); //hang up
  updateSerial();
}

void loop()
{
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

The following screenshot shows a call made from the SIM900 shield.

SIM900 GSM Shield AT Commands for Making Call on Arduino
Receiving Call through SIM900 GSM Shield

Code Explanation:

The following AT commands are used to make a call:

ATD+ +ZZxxxxxxxxxx; – Dials a specified number. Don’t forget the semicolon ; at the end of the command.

ATH – Hangs up the call

mySerial.println("ATD+ +ZZxxxxxxxxxx;"); //  change ZZ with country code and xxxxxxxxxxx with phone number to dial
updateSerial();
delay(20000); // wait for 20 seconds...
mySerial.println("ATH"); //hang up
updateSerial();

Arduino Code – Receiving a Call

No special code is required to receive calls; You just have to keep listening to the SIM900 shield. You may find this sketch very useful when you need to perform an action when a call is received from a specific phone number.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

The following output on the serial monitor shows the calls received by the SIM900 shield.

Calling through SIM900 GSM Shield
SIM900 GSM Shield AT Commands for Receiving Call on Arduino

As you can see incoming calls are usually represented by ‘RING’ on the serial monitor, followed by the phone number and caller ID. The following AT commands can be used to accept or hang up the call:

ATA – Accepts an incoming call.

ATH – Hangs up the call. On hanging up the incoming call, we get NO CARRIER on the serial monitor indicating that the call could not be connected.