Usage Example for Arduino-Auto Answering Phone Calls and Reading SMS Messages

Last revision 2026/01/15

Explore the functionality of Arduino with DFRobot_SIM808 Shield, focusing on auto answering phone calls and reading SMS messages, enhancing communication capabilities for electronics projects.

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_LoopHandle example or copy the code to your project

  10. Download and set the function switch to Arduino

  11. The shield will auto-answer phone calls or send SMS Messages to the serial terminal

Sample Code


#include <DFRobot_sim808.h>

#define MESSAGE_LENGTH 20
char gprsBuffer[64];
char *s = NULL;

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 call or send SMS message to me!");
}

void loop() {
   //******** Wait serial data *************
   if(sim808.readable()){
      sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
      //Serial.print(gprsBuffer);

   //************** Detect the current state of the telephone or SMS ************************
      if(NULL != strstr(gprsBuffer,"RING")) {
          sim808.answer();
      }else if(NULL != (s = strstr(gprsBuffer,"+CMTI: \"SM\""))) { //SMS: $$+CMTI: "SM",24$$
          char message[MESSAGE_LENGTH];
          int messageIndex = atoi(s+12);
          sim808.readSMS(messageIndex, message,MESSAGE_LENGTH);
          Serial.print("Recv Message: ");
          Serial.println(message);
     }
     sim808_clean_buffer(gprsBuffer,32);
   }
}

Was this article helpful?

TOP