Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Monitoring GPS Data with the NEO 6M and Arduino

I recently wrote a tutorial titled, Configuring Visual Studio Code for Arduino Development, because I’ve been exploring the Internet of Things (IoT). Up until recently I’ve only had hands on experience with Raspberry Pi, but I’ve been expanding my knowledge with Arduino.

I have an Arduino Uno and a GPS module, so I thought it’d be a good idea to demonstrate how to use the two together.

In this tutorial we’re going to see how to monitor a NEO 6M GPS module connected to an Arduino using a few lines of very simple code.

The Requirements

Because there will be an emphasis on using hardware in this tutorial, I’m going to specify our hardware requirements. I’m personally using the following:

Yes, you could probably get away with using other hardware, however I’m only listing what I’ve tested. The links I’ve provided are affiliate links, so I will get a referral credit if you click on them. Essentially, you need an Arduino, a GPS unit, and an external antenna so that way you won’t need to sit around for days waiting for a GPS fix.

You’ll need to connect your GPS unit to the Arduino with the following pin configuration:

  • GPS RX to Arduino D4
  • GPS TX to Arduino D3
  • GPS PWR to Arduino 3.3V
  • GPS GND to Arduino GND

If your GPS doesn’t have pins, make sure you solder some on and use the appropriate jumper wires. My GPS already had the pins and I had simple male to female jumper wires laying around.

There is a software requirement that must be met as well. You need the Arduino Desktop IDE with the TinyGPS++ library installed. We’ll be using TinyGPS++ to parse the data coming from our serial connection.

Developing a GPS Application with Arduino

The code involved in this project is actually quite simple. The idea is that we’re simply going to be reading the raw GPS data from the pin connection. This data is NMEA formatted which we’ll parse with the TinyGPS++ module. Then we’ll just print the parsed data to the console.

Create a new Arduino project and include the following code:

#include "SoftwareSerial.h"
#include "TinyGPS++.h"

TinyGPSPlus gps;

SoftwareSerial ss(3, 4);

void setup() {
    Serial.begin(9600);
    ss.begin(9600);
}

void loop() {
    while(ss.available() > 0) {
        // Parsing logic here...
    }
}

The above code will map the pins that we connected, open the serial connection using a baud rate of 9600, and then do some future logic when serial data is available. If we wanted to we could use ss.read() to get the raw GPS data from the serial connection.

Now we can upgrade our loop to do some parsing:

void loop() {
    while(ss.available() > 0) {
        if(gps.encode(ss.read())) {
            if(gps.location.isUpdated()) {
                Serial.println(String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6));
            }
            delay(1000);
        }
    }
}

The above code will read the raw GPS data and parse it. Every time the GPS data is updated we get the latitude and longitude information to print out. We need to cast this data as a string and we need to specify the decimal precision of six decimal places.

The TinyGPS++ library makes our lives very easy.

Conclusion

You just saw how to use a NEO 6M GPS module with an Arduino using very little code. Something that held me up when testing this example was in the details of the antenna. If you don’t use an antenna or don’t use the correct antenna, it could take days for your GPS to get a fix and start producing data. Invest in the antenna so you only have to wait a few minutes.

A video version of this tutorial can be seen below.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.

Search

Follow Us

The Polyglot Developer

Subscribe

Subscribe to the newsletter for monthly tips and tricks on subjects such as mobile, web, and game development.

The Polyglot Developer

Support This Site