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
- DFR0181 Arduino UNO x1
- TEL0097 SIM808 Expansion Shield x1
- External Power Supply x1
- SIM Card x1
Software Preparation
-
Download and install the driver: Click to download driver
-
Download DFRobot_SIM808 library Click to Download DFRobot_SIM808 library
Steps
-
Insert a SIM card in to the SIM slot on the SIM808 expansion shield
-
Stack the expansion shield on to an Arduino UNO
-
Connect an external power source to the Arduino
-
Set the function switch to
None -
Upload the sample code
-
Set the function switch to
Arduinoand make sure SIM808 could communicate with Arduino board -
Press the Boot power button
-
Wait for the SIM card to register the network, the Net indicator LED will slowly flash every 3 seconds
-
Open the
SIM808_SMSreadexample or copy the code to your project -
Download and set the function switch to
Arduino -
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?
