Usage Example for Arduino-Get GPS Data

Last revision 2026/01/15

This article explains the process of using an Arduino UNO paired with a SIM808 expansion shield to obtain GPS data. It covers essential hardware and software preparations, detailed steps for setup, and provides sample code for retrieving and managing GPS data efficiently.

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

  10. Download and set the function switch to Arduino

  11. Open the serial terminal

  12. Place the shield outside, wait for a few minutes and it will send GPS data to serial terminal

Sample Code


  #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();
    }

  }

Was this article helpful?

TOP