Sie sind auf Seite 1von 1

 HOME REVIEWS ELECTRONICS  ARDUINO 

Electrical engineering & Arduino resources for makers

Home » Arduino » How to » How to interface a GPS module with Arduino

How to interface a GPS module with Arduino


33 comments

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:

U-blox NEO-6M GPS Module used in this tutorial

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!

The GPS module with the antenna attached

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.

Arduino connected to GPS Module

Once everything is ready, you should have something looking like the picture below:

GPS Module connected to Arduino Uno. Note: the Uno is a beautifully made Robotdyn clone.

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.

Default baud rate specified on this particular 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:

Raw GPS Data

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.

Installing TinyGPS++ library

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!

Raw GPS data parsed by TinyGPS++

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!

Leave a comment
Your email address will not be published. Required fields are marked *

COMMENT

*NAME *EMAIL WEBSITE

POST COMMENT

33 thoughts on “How to interface a GPS module with Arduino”


33 comments

Gurjeet February 25, 2018, 4:43 am

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.

R E P LY

Tony P Post author March 1, 2018, 4:09 pm

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.

R E P LY

Pinki Kumari April 28, 2019, 6:33 pm

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 .

R E P LY

GIRISH SAI November 6, 2019, 12:33 am

same problem but led is not blinking

R E P LY

gowtham April 10, 2018, 2:24 pm

change the baud rate to 115200 in serial monitor

R E P LY

OMOSEYIN TOLU April 17, 2018, 11:39 pm

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.

R E P LY

Tony P Post author April 18, 2018, 4:39 pm

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.

R E P LY

girish November 6, 2019, 12:34 am

i also got this msg

R E P LY

Rere May 2, 2018, 3:04 am

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?

R E P LY

Tony P Post author May 3, 2018, 1:21 pm

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.

R E P LY

Deepayan June 28, 2018, 6:44 am

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.

R E P LY

Tony P Post author June 29, 2018, 11:30 am

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?

R E P LY

Aiden September 3, 2018, 10:17 pm

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?

R E P LY

Tony P Post author September 12, 2018, 11:07 am

Hi Aiden,
That means your GPS is not catching any data. Leave it outdoor for 5min; it should work!

R E P LY

Jeremy December 21, 2018, 11:08 pm

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?

Tony P Post author December 28, 2018, 7:33 pm

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.

Chamberlain Henry August 3, 2018, 6:47 am

Very helpful, easy to follow. Just a problem here receiving indoors, signal not consistent.
Many thanks.

R E P LY

Talha Ayub November 4, 2018, 8:45 pm

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

R E P LY

Tony December 9, 2018, 1:06 pm

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.

R E P LY

shivananda January 4, 2019, 1:14 am

thank you

R E P LY

shruti January 11, 2019, 2:06 am

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

R E P LY

Hind February 27, 2019, 7:09 pm

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 ?

R E P LY

Jason March 7, 2019, 1:47 pm

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.

R E P LY

Viraj April 4, 2019, 2:07 am

This same thing is not working for Arduino mega, I followed the same pin configuration.

Can anyone please post the reason

Thank you

R E P LY

L1 December 14, 2019, 1:08 am

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.

R E P LY

L1 December 14, 2019, 1:14 am

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).

R E P LY

Himaas Ali September 18, 2019, 3:12 am

I am having an issue in serial monitor, it displays no gps detected, check wiring. Please help me out

R E P LY

sravya September 19, 2019, 8:03 pm

Using NEO6m GPS interfacing with aurdino uno how to push lat and long values in message form?sort me out!!

R E P LY

Paul Vlaar September 30, 2019, 1:15 am

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.

R E P LY

M Nauman Tariq October 3, 2019, 4:31 pm

RED LED is blinking but still serial monitor is showing


No GPS detected: check wiring.

R E P LY

sravya November 18, 2019, 12:38 pm

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 ?

R E P LY

sankar November 26, 2019, 6:18 pm

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??

R E P LY

jamshaid January 27, 2020, 11:42 pm

your device is not connected to the satellite .


when it blinks then your device is connected to the satellite

R E P LY

Raspberry Pi Arduino Blog SparkFun: Commerce Blog

Raspberry Jams around the world celebrate Raspberry Preview the Debugger feature for the Arduino Pro IDE Be All That You Can XBee
Pi’s 8th birthday
An Arduino-enabled observatory dome door opener Enginursday: Fixing the ESP32 Thing Plus
A birthday gift: 2GB Raspberry Pi 4 now only $35
Arm Pelion Device Management comes to the Arduino Dumpster Dive is Today
Play Pong with ultrasonic sensors and a Raspberry Pi | IoT Cloud
The Teensy Life
HackSpace magazine
OpenAstroTracker is a tracking and GoTo mount for
Make a micro:bot with micro:bit
Create Boing!, our Python tribute to Pong DSLR astrophotography
Enginursday: Non-Addressable RGB LEDs
The History of Pong | Code the Classics Resys is an LED drawer system that makes it easy to
find your resistors How to Write A Great Arduino Library
Colour us bewildered
Take control of your dashboard — the new Arduino IoT Dumpster Dive Returns
How to play sound and make noise with your Raspberry
Cloud Dashboard with advanced features! A Fresh Delivery of Power for Valentine's Day
Pi
Duel Disk System blends physical cards with a virtual Enginursday: A New Sensory Experience with the
Build a Raspberry Pi Zero W Amazon price tracker
playfield Cthulhu Shield
Build a Raspberry Pi laser scanner
This SpaceX fan created a levitating Starship lamp
3D-printable Raspberry Pi bits and pieces you should
AAScan is an open source, Arduino-powered 3D
totally make
scanner that uses your phone

A DIY digital readout for your wood lathe

© 2020 idyl.io – All rights reserved

Powered by  – Designed with the Customizr theme

Das könnte Ihnen auch gefallen