Receive SMS Example

Receive SMS messages

This example shows you how to receive SMS messages using a GSM Shield2.


  • Arduino board
  • Arduino GSM Shield 2
  • SIM card able to receive messages


Arduino GSM Shield mounted on Arduino board 
Mount your GSM Shield 2 on an Arduino board, insert the SIM card into dedicated slot and connect it to your pc using the USB cable.


To using this sketch you must include the"GSM.h", and you must indicate the PIN number of your SIM. 
Now you can upload this example in your Arduino board and after that the loading is completed you can open your Serial Monitor and you wait the receive SMS. 
When you will receive a message, it will show on your Serial monitor.

The message received it is read through the "" function and it is removed with "sms.flush()", these functions are contained into "GSM.h" library. 
The SMS is displayed on serial monitor with the "Serial.print()" function that it is initialized in setup with "Serial.begin(9600)"command.

The complete code and its detailed description are shown down.

SMS receiver
This sketch, for the Arduino GSM shield, waits for a SMS message
and displays it through the Serial port.
* GSM shield attached to and Arduino
* SIM card that can receive SMS messages
created 25 Feb 2012
by Javier Zorzano / TD
This example is in the public domain.*/
// Include the GSM library
#include <GSM.h>
// Insert the PIN number of your SIM, if your SIM hasn't PIN, you can leave it blank:
#define PINNUMBER ""
// Initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS retrieved
char senderNumber[20];
void setup()
// Initialize serial communications and wait for port to open:
while (!Serial) {
  ; // Wait for serial port to connect. Needed for Leonardo only
Serial.println("SMS Messages Receiver");
// Create a local variable to track the connection status.
boolean notConnected = true;
// Start GSM connection
while (notConnected)
  if (gsmAccess.begin(PINNUMBER) == GSM_READY)
    notConnected = false;
    Serial.println("Not connected");
//Print some information on Serial Monitor
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
void loop()
char c;
// If there are any SMSs available()
if (sms.available())
  Serial.println("Message received from:");
  // Get remote number
  sms.remoteNumber(senderNumber, 20);
  // An example of message disposal
  // Any messages starting with # should be discarded
  if (sms.peek() == '#')
    Serial.println("Discarded SMS");
    //Delete message
  // Read message bytes and print them
  while (c =
  Serial.println("\nEND OF MESSAGE");
  // Delete message from modem memory
  Serial.println("MESSAGE DELETED");