Usage Example for Arduino-Read SMS Messages

Last revision 2026/01/15

This article explains how to use the DFRobot_SIM808 GPS/GPRS/GSM Shield with Arduino to read SMS messages, providing a practical guide to setup and implementation.

Hardware Preparation

Software Preparation

Steps

  1. Insert a SIM card in to the SIM slot on the SIM808 expansion shield

  2. Stack the expansion shield on to an Arduino UNO

  3. Connect an external power source to the Arduino

  4. Set the function switch to None

  5. Upload the sample code

  6. Set the function switch to Arduino and make sure SIM808 could communicate with Arduino board

  7. Press the Boot power button

  8. Wait for the SIM card to register the network, the Net indicator LED will slowly flash every 3 seconds

  9. Open the SIM808_SMSread example or copy the code to your project

  10. Download and set the function switch to Arduino

  11. The shield will receive SMS Messages and send them to the serial terminal

Sample Code


#include <DFRobot_sim808.h>

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;

char phone[16];
char datetime[24];

DFRobot_SIM808 sim808(&Serial);

void setup() {
  //mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init()) {
      Serial.print("Sim808 init error\r\n");
      delay(1000);
  }
  delay(3000);
  Serial.println("Init Success, please send SMS message to me!");
}

void loop() {
  //*********** Detecting unread SMS ************************
   messageIndex = sim808.isSMSunread();
    Serial.print("messageIndex: ");
    Serial.println(messageIndex);

   //*********** At least, there is one UNREAD SMS ***********
   if (messageIndex > 0) {
      sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);

      //***********In order not to full SIM Memory, is better to delete it**********
      sim808.deleteSMS(messageIndex);
      Serial.print("From number: ");
      Serial.println(phone);
      Serial.print("Datetime: ");
      Serial.println(datetime);
      Serial.print("Recieved Message: ");
      Serial.println(message);
   }
}

Was this article helpful?

TOP