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
- DFR0181 Arduino UNO x1
- TEL0097 SIM808 Expansion Shield x1
- External Power Supply x1
- SIM Card x1
Software Preparation
-
Download and install the Arduino IDE: Click to download Arduino IDE
-
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_GetGPSexample or copy the code to your project -
Download and set the function switch to
Arduino -
Open the serial terminal
-
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?
