In this tutorial we are going to interface a GPS Module with Arduino.
Any GPS module with serial communication will do, but we will be using the popular U-BLOX Neo 6M here.
Parts used in this tutorial
- An Arduino Uno
- Ublox NEO-6M GPS Module
- 4 jumper cables
You can buy the module from the usual suspects: ebay, Amazon or Aliexpress. The one used in this tutorial was sourced from Aliexpress. Here’s the transaction page with the keywords you should be looking for:
You can note straight away that the module only uses 4 pins: VCC, GND, RX, and TX: this is because these modules communicate over a simple serial RS232 connection; the exact same protocol the Arduino uses when you write “Serial.begin”.
The module is incredibly simple: it just spits non stop NMEA data strings to the TX pin. “NMEA” stands for “National Marine Electronics Association” and is a standard text protocol shared by all GPS. This tutorial will only demonstrate how to exploit the data stream, but feel free to dig deeper in the underlying features this standard has to offer!
Connecting the GPS Module to Arduino
To connect your GPS module to Arduino, use a +5V from the power side of the Arduino and any ground pin. Any two pins will work for the serial communication, but on this tutorial we will use 3 and 4:
- Connect Arduino pin 3 to the RX pin of the GPS Module.
- Connect Arduino pin 4 to the TX pin of the GPS Module.
WARNING: Most GPS module are happy to work off 5V, but the U-BLOX Neo 6M used here can only support a maximum voltage of 3.6V. If you look closely on the GPS board you will see a tiny K833 series 3.3V voltage regulator. Please make sure the module you buy benefits from the same level of security.
Once everything is ready, you should have something looking like the picture below:
Reading raw data from the GPS
Reading raw data from the GPS is a very trivial matter: simply create a new serial connection using SoftwareSerial and match the default baud rate of your GPS module. On most, it should be 9600 bauds; but don’t take my word for it and check on your module.
The code below just outputs to the SerialMonitor whatever it can read from the GPS without filtering:
#include <SoftwareSerial.h> static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 9600; // The serial connection to the GPS device SoftwareSerial ss(RXPin, TXPin); void setup() { Serial.begin(115200); ss.begin(GPSBaud); } void loop() { // Output raw GPS data to the serial monitor while (ss.available() > 0){ Serial.write(ss.read()); } }
Your Serial Monitor should look like this:
This gibberish is the “native language” of your GPS and contains all the information a GPS can provide: time, latitude, longitude, GPS satellites in view… However, there is no need to dig deeper into this, as the community has long jumped in to provide libraries that are able to decode and interpret automatically these strings of characters. In this tutorial we will focus on TinyGPS++.
Using a library: TinyGPS++
While it is entirely possible to work with GPS raw data, you might want to consider using one of the numerous libraries first. On Arduino, the reference and most advanced GPS lib is Mikal Hart’s TinyGPS++. Head over to GitHub and download the latest release first. Once complete, unzip the content into your “libraries” subfolder of your Arduino IDE installation and restart the IDE itself.
You should now have a new set of “Examples” under File/Examples/TinyGPSPlus.
“DeviceExample” has all the information you need. Don’t forget to set the correct baud rate, RX and TX pins and you are ready to go!
Troubleshooting
If you have troubles getting any data coming out of your module; let it stay plugged at 5V for about a minute. GPS modules have really slow “cold start” times. When it’s ready, some modules have a blinking LED indicating it’s sending data. Make sure to check this out before thinking your device is faulty.
For now, enjoy playing with your new toy!
38 thoughts on “How to interface a GPS module with Arduino”
Hi I tried this code for NEO-6M GPS module with arduino Uno but it was showing just ?/??//? type Symbols Could you help me regarding that.
Try the simple code of printing out raw GPS data before trying to parse it into a library. This should confirm you at least can read data correctly.
I’m using GPS NEO-6M and the led in GPS is also blinking but the location or garbage i.e nothing is displayed on serial monitor .
same problem but led is not blinking
change the baud rate to 115200 in serial monitor
This is what i get on the serial monitor. Pls what is the problem?
DeviceExample.ino
A simple demonstration of TinyGPS++ with an attached GPS module
Testing TinyGPS++ library v. 1.0.2
by Mikal Hart
No GPS detected: check wiring.
Can you get the first code to run? Just let the GPS on for a few minutes. If it’s new module it may take a while to catch signal.
i also got this msg
Hi, I tried this code for NEO-6M GPS Module with Arduino Nano, but it shows Location: INVALID Date/Time: 0/0/2000 00:00:00.00. Could you help me regarding this problem?
Try the simple code of printing out raw GPS data (the 1st code) before trying to parse it inside a GPS library. Most likely you are not getting correte NMEA strings.
Hi Tony, with the device example, when I simply change the GPS baud rate to 9600 and upload, it displays garbage as mentioned by some above: ?/??//? I tried tinkering with different baud rates for the serial monitor (and also the GPS as a last resort) but to no avail.
Even with the raw GPS data, I get garbage. The GPS module I’m using is GTPA010.
Hi Deepayan,
As long as you don’t get clean NMEA string from the raw data, you won’t be able to do anything. What kind of data are you seeing?
Hi, I am also having issues with the DeviceExample giving the following result in serial monitor:
Location: INVALID Date/Time: 0/0/2000 00:00:00.00
When I tried the print out the raw data, I get the following in the serial monitor:
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,00*79
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
Can you please advise on what this means?
Hi Aiden,
That means your GPS is not catching any data. Leave it outdoor for 5min; it should work!
Hi, I’m working from a workbench on a GPS Receiver device at my desk and i have it wired to my arduino Mega board. Using the first code, i was still unable to get anything to coming to the Serial Monitor. Is it because the GPS receiver is inside or what?
GPS signal can easily be blocked but the only way to really find out is to take your project outdoors for a few minutes and see if the module manages to catch signal properly.
Also connect the Vcc of GPS Sensor to 3.3V of Arduino UNO instead of 5V
Very helpful, easy to follow. Just a problem here receiving indoors, signal not consistent.
Many thanks.
ThankYou so much I was having the same issues ten I change the Baud to 9600 from 4800 as in the code. Now it is giving me the correct values. Thanks Again
Hi, I have been struggling on this for hours, I hope you can help.
I did try all the connections of any kind ( with resistor , with differents board, with the tx rx input on the arduino nano) nothing work.
The blue light blink ( wich mean the gps is sending data) but the code show nothing. If I try to get the ss.read I get -1 or 255 (depending of wich input tx or rx I assign to the sketch)
If it is broken how can I verify ( with a multimeter probably but where to check), im new to electronique and programming.
Thank you.
thank you
i’m using arduino uno and gpsv3 neo 6m; i have tried this code so many times but noting is happening; nothing is displyed on the serial monitor screen; tx, rx leds of arduino are also not blinking
Hello i want to ask about the GPS module When i order it from does it came with the blue board or only the little ship ? Cause in u blox site they only show the little white Ship not whole blue board ? If they only sell the litlle ZED F9P little ship can u please tell me how can i hook it up with the blue board ? Or can i hook it directly to the Arduino ?
Excuse me, I have some problem when we do the project.
I’ve already got the code. However, when I tried to apply it to another Arduino mega, it didn’t work.
I think that Arduino isn’t able to
read the GPS data. A led light kept twinkling when the gps mega has its position.
Here’s what I did:
I used two sets of RX TX. One for detecting the GPS, the other for sending the data to the ESP-12e board.
The GPS can be detected but the data couldn’t be sent onto the board.
I am wondering the problem may be caused because I used two sets of RX TX at the same time. Or maybe there’s more problem that I didn’t notice.
I would like to know how to fix this problem, thanks a lot.
This same thing is not working for Arduino mega, I followed the same pin configuration.
Can anyone please post the reason
Thank you
I had the same problem with an Arduino Mega board. I change all the ss variable by Serial1 (As the Mega board has several serial port) I had a Serial1.begin(9600); in the setup function and deleted the code related to SoftwareSerial.h. It worked for me.
For the wirering you need to connect the RX of your gps to the TX1 and the TX on the RX1 (if you want to use the serial1).
You can also check the baud rate by using your Arduino board as a Serial to USB converter with this code :
void setup(){
pinMode(0,INPUT);
pinMode(1,INPUT);
}
void loop(){
}
You need to put the RX of your GPS on the RX0 and the TX on the TX0 (As the serial0 is actually the USB).
I am having an issue in serial monitor, it displays no gps detected, check wiring. Please help me out
Using NEO6m GPS interfacing with aurdino uno how to push lat and long values in message form?sort me out!!
One thing i noticed is that the baud rate in the DeviceExample for the gps is set at 4800.
This is why the code didn’t work for me in the beginning.
Once i changed it to 9600 it worked.
RED LED is blinking but still serial monitor is showing
No GPS detected: check wiring.
Hi I used Neo-6M GPS module and node MCU to track the vehicle throw IoT pub-nub i write the program using Arduino software & get the data from GPS every 1 minute, but problem is not getting data from GPS vehicle running time i little confused about that ?
Hi i interfaced gps with node mcu to get gps values on moving vehicle but i did not get continuous values i write the code to push the data every 30 seconds but it sends the gps values only in stabled condition. i changed 3 modules but it was repeating same problem if any suggestions to over come this problem??
your device is not connected to the satellite .
when it blinks then your device is connected to the satellite
Sir,I am facing a problem with gps module when interfaced with arduino.I got NMEA codes just by uploading blank program,and decoded output shows correct location.But when i tried with tiny Gps++ library, the output of code is ********************** printed as pattern and not getting a output.I think there is some issue with the example program.Sir please help me.
In the basic example make sure you update the baud rade. By default it’s “static const uint32_t GPSBaud = 4800;” but most GPS run at 9600.
Hi
how can I modify the current code of a GPS?
my GPS is Gt06 model
really need it and will appreciate if help me
it is not working it just printing
No GPS detected: check wiring.
DeviceExample.ino
A simple demonstration of TinyGPS++ with an attached GPS module
Testing TinyGPS++ library v. 1.0.2
by Mikal Hart
No GPS detected: check wiring.
on the serial
I have tried all of the methods of yours but it is still not working and I know the module is working because when I upload an empty sketch the serial moitor gives me my location can you please help