Sitemap / Advertise

Information



Tags



Share

How to use DFRobot SIM808 GPS/GPRS/GSM Shield with Arduino

Advertisement:


read_later

Read Later

Keywords



Keywords



read_later

Read Later

Information

Tags

Share





Advertisement

Advertisement




Definition

In this tutorial, I will show you how to use the SIM808 GPS/GPRS/GSM Shield with its official library for Arduino.

Introduction(1)

The SIM808 GPS/GPRS/GSM Arduino Shield includes an integrated quad-band GSM, GPRS, and GPS navigation technology. A credit card size only, according to the standard Arduino pin packaging, compatible with Arduino UNO, Arduino Leonardo, Arduino Mega, and other boards alike. As compared to the previous generation SIM908, SIM808 has improvements in performance and stability. In addition to the regular SMS and phone functions, the shield also supports MMS, DTMF, FTP, and other features. You can achieve data acquisition, wireless data transfer, IoT applications, and GPS orientating. The shield also has an integrated onboard microphone and headphone jack connected to the GSM and GPS antenna by an external antenna connector.

SIM808 GPS/GPRS/GSM Arduino Shield V1.0 uses the latest version of Simcom SIM808 module, compared with the previous SIM808 module available in the market, the new module is with better stability.

Connections and Adjustment(1)

Note: D0, D1, D12 pins are occupied by the SIM808 GPS/GPRS/GSM Shield.

Connect an external battery (7-23V) for the SIM808 module to work properly.

Attach the GPS antenna and the GSM antenna to the SIM808 shield.

Insert a SIM card into the SIM slot on the SIM808 shield.

Before uploading the code, set the function switch on the shield to None (1).

Upload the code.

Then, set the function switch to Arduino (3).

Press the Boot button on the shield until seeing the Net indicator LED flashing every 1 second and wait for the SIM card to register the network - the Net indicator LED will slowly flash every 3 seconds.

article-image
Figure - 134.1

For more information, click here.

Code

Download the required library for the SIM808 GPS/GPRS/GSM Shield from here.

These examples shown below are from the library for the SIM808 GPS/GPRS/GSM Shield. You can find more examples in the library.


-------------- Arduino --------------

------ MAKE PHONE CALLS ------

  #include <DFRobot_sim808.h>

  //Mobile phone number, need to change
  #define PHONE_NUMBER  "187******39"

  DFRobot_SIM808 sim808(&Serial);

  void setup() {
    //mySerial.begin(9600);
    Serial.begin(9600);
    //********Initialize sim808 module*************
    while(!sim808.init()) {
        delay(1000);
        Serial.print("Sim808 init error\r\n");
    }
    Serial.println("Sim808 init success");
    Serial.println("Start to call ...");

    //*********Call specified number***************
    sim808.callUp(PHONE_NUMBER);
  }
  void loop() {
    //nothing to do
  }
  
------ SEND SMS MESSAGES ------

#include <DFRobot_sim808.h>

  //Mobile phone number, need to change
  #define PHONE_NUMBER "187*******39"

  //The content of messages sent
  #define MESSAGE  "hello,world"

  DFRobot_SIM808 sim808(&Serial);

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

   //******** Initialize sim808 module *************
    while(!sim808.init()) {
        delay(1000);
        Serial.print("Sim808 init error\r\n");
    }
    Serial.println("Sim808 init success");
    Serial.println("Start to send message ...");

    //******** define phone number and text **********
    sim808.sendSMS(PHONE_NUMBER,MESSAGE);
  }

  void loop() {
    //nothing to do
  }
  
------ CONNECT TCP AND SEND GET REQUESTS ------

 #include <DFRobot_sim808.h>

  //make sure that the baud rate of SIM900 is 9600!
  //you can use the AT Command(AT+IPR=9600) to set it through SerialDebug

  DFRobot_SIM808 sim808(&Serial);

  char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
  char buffer[512];

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

    //******** Initialize sim808 module *************
    while(!sim808.init()) {
        delay(1000);
        Serial.print("Sim808 init error\r\n");
    }
    delay(3000);

    //*********** Attempt DHCP *******************
    while(!sim808.join(F("cmnet"))) {
        Serial.println("Sim808 join network error");
        delay(2000);
    }

    //************ Successful DHCP ****************
    Serial.print("IP Address is ");
    Serial.println(sim808.getIPAddress());

    //*********** Establish a TCP connection ************
    if(!sim808.connect(TCP,"mbed.org", 80)) {
        Serial.println("Connect error");
    }else{
        Serial.println("Connect mbed.org success");
    }

    //*********** Send a GET request *****************
    Serial.println("waiting to fetch...");
    sim808.send(http_cmd, sizeof(http_cmd)-1);
    while (true) {
        int ret = sim808.recv(buffer, sizeof(buffer)-1);
        if (ret <= 0){
            Serial.println("fetch over...");
            break;
        }
        buffer[ret] = '\0';
        Serial.print("Recv: ");
        Serial.print(ret);
        Serial.print(" bytes: ");
        Serial.println(buffer);
        break;
    }

    //************* Close TCP or UDP connections **********
    sim808.close();

    //*** Disconnect wireless connection, Close Moving Scene *******
    sim808.disconnect();
  }

  void loop(){

  }
  
------ GET GPS DATA ------  
  
 #include <DFRobot_sim808.h>

  DFRobot_SIM808 sim808(&Serial);

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

    //******** Initialize sim808 module *************
    while(!sim808.init()) {
        delay(1000);
        Serial.print("Sim808 init error\r\n");
    }

    //************* Turn on the GPS power************
    if( sim808.attachGPS())
        Serial.println("Open the GPS power success");
    else
        Serial.println("Open the GPS power failure");

  }

  void loop() {
     //************** Get GPS data *******************
     if (sim808.getGPS()) {
      Serial.print(sim808.GPSdata.year);
      Serial.print("/");
      Serial.print(sim808.GPSdata.month);
      Serial.print("/");
      Serial.print(sim808.GPSdata.day);
      Serial.print(" ");
      Serial.print(sim808.GPSdata.hour);
      Serial.print(":");
      Serial.print(sim808.GPSdata.minute);
      Serial.print(":");
      Serial.print(sim808.GPSdata.second);
      Serial.print(":");
      Serial.println(sim808.GPSdata.centisecond);
      Serial.print("latitude :");
      Serial.println(sim808.GPSdata.lat);
      Serial.print("longitude :");
      Serial.println(sim808.GPSdata.lon);
      Serial.print("speed_kph :");
      Serial.println(sim808.GPSdata.speed_kph);
      Serial.print("heading :");
      Serial.println(sim808.GPSdata.heading);
      Serial.println();

      //************* Turn off the GPS power ************
      sim808.detachGPS();
    }

  }  

Result:

You can inspect my electronics project in which I used DFRobot SIM808 GPS/GPRS/GSM Shield from here.

References

(1) https://wiki.dfrobot.com/SIM808_GPS_GPRS_GSM_Shield_SKU__TEL0097