Example Code for Arduino-GPS Feature (AT Commands)
Last revision 2026/01/24
This article demonstrates how to integrate GPS functionality with an Arduino board using AT commands, outlining necessary hardware and software, providing step-by-step setup instructions, and offering example code to facilitate GPS data retrieval.
Hardware Preparation
- DFR0355 SIM808 with Leonardo mainboard x1
- GSM & GPS Antennas (Included) x1
- External power supply (7-23V, DC) x1
- SIM card (GSM/GPRS) x1
- FIT0265 Micro USB Cablex1
Software Preparation
- Download and install the Arduino IDE: Click to Download Arduino IDE
- Download and install the DF Serial Debugger: Click to Download DF Serial Debugger
Preparations
- Install the SIM card in the sim slot on the back of the board
- Make sure your SIM card is available, and you can put the SIM card into the socket or get it out by sliding the metal lock.
- Install the GPS & GSM antennas on the board
- Connect with PC and power supply(there are three ways to supply the power)
- Through 7~23V power supply jack
- Through VIN pin on board
- Remove the jumper on NO BAT, and connect a 3.7V Lithium Battery to BAT jack
- After connecting the board to PC by an USB cable, the board shows up as Leonardo automatically if you have installed the Arduino by .exe file, or you will need to install the driver manually

- BOOT SIM808 by pressing the BOOT white button for 2 seconds if the NET indicator LED is OFF.
- Upload the debugging code below to Leonardo.
Sample Code
/*
* The sketch here will make Leonardo exchange
* data between the USB serial port and SIM808 module.
*/
void setup() {
Serial.begin(115200); //initialize Serial(i.e. USB port)
Serial1.begin(115200); //initialize Serial1
}
void loop() {
//If Serial1 receive data, print out to Serial
while (Serial1.available()) {
Serial.write(Serial1.read());
}
//If Serial receive data, print out to Serial1
while (Serial.available()) {
Serial1.write(Serial.read());
}
delay(1); //delay for a short time to
// avoid unstable USB communication
}
Other Preparation Work(AT command)
We recommend using this feature outside for best perfomance.
- Send AT+CGNSPWR=1, the serial monitor will confirm with OK immediately
- Send AT+CGNSTST=1, the serial monitor will confirm with OK
The module should then start displaying GPS location data.
Result
The module should then start displaying GPS location data.

To get GPS position data, the module should be placed outside. Here, we did the it inside in order to demonstrate the AT commands.
Read: The raw GPS data from the serial is in the form: DDmm.mmmmm.
e.g. If the raw information is: 5320.12345, then it is: 53 degress and 20.12345 minutes. In order to convert to decimal coordinates you need to divide the minutes by 60. i.e. 20.12345/60 = 0.33539. So the decimal result is 53.33539.
Was this article helpful?
