Interfacing uBlox NEO6M GPS Module with Arduino

Back to Blog
NEO6M-GPS-Tutorial-FactoryForward

Interfacing uBlox NEO6M GPS Module with Arduino

GPS was widely used in Marine navigations mostly in olden days. After that, governments decided to provide access to all users in the world to use GPS navigation. Nowadays it is used widely by all people on their Mobile phones, Car Navigation Systems, Drones, Asset Tracking systems in logistics, Anti-Theft for motorcycles, etc. Almost all of us might have used Google Maps in anyway. So we are aware about what a GPS does. So let’s go deeper into it on how do we use this GPS Module with Arduino to get location, time date, etc.

A GPS module receives signals from the GPS Satellites. There are minimum 3 satellites to get an accurate 3D Fix location; otherwise it can detect location using one satellite only (but not accurate).The number of satellite signals it gets the accuracy of the location increases.

The uBlox NEO6M GPS Module has a big 25mmx25mm antenna along with a battery and EEPROM to lock the satellites faster. The module has a GPS Antenna connected via an uFl connector. It doesn’t have any power indicator LED, but it has an onboard LED that indicates the satellite is fixed. Whenever the LED blinks the satellite is fixed and sending the data via the Serial Communication pins. It continuously sends the data via the serial pins. All we have to do is to get the data and parse it to get our required information using the Microcontroller/Microprocessor. The default baud rate for NEO6M GPS Module is 9600bps.

GPS-Module-details

In this tutorial, we will see how to use this GPS Module with Arduino.

Components required:

Circuit Diagram:

GY-NEO6MV2_bb

We will be using Software Serial Library for this as we are going to print the data from GPS to Serial Monitor. If you use the same communication port both the data will clash together and we get invalid data. Arduino MEGA has 4 Dedicated COM Ports, but in UNO we need to use the Software Library only.

Arduino PinsNEO6M GPS Pins
GNDGND
Pin 9 (RX)TX
Pin 8 (TX)RX
VCC (+5V)VCC (3.6 to 5V)

 

Note: As per the uBlox NEO6M datasheet the voltage level for GPS Module is 3.6V. But we didn’t face any heating issue with 5V. You can try with 3.3V initially (for TX/RX also) and can shift to 5V if needed. But still it is recommended to use a Level Shifter for long time purpose.

Code to get RAW GPS Data:

/*
 *Author: Sharath
 *Website: http://www.factoryforward.com
 */
 
#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 8); // (RX,TX of Arduino)

void setup()
{
  Serial.begin(9600);// Serial Monitor Baud Rate
  mySerial.begin(9600); //GPS Port Baud
}

void loop()
{
  while (mySerial.available() > 0){
    byte rawData = mySerial.read();//Storing bytes in rawData Variable
    Serial.write(rawData); //Printing rawData on Serial Monitor
 }
}

 

In the above code, we declared pin 9 as RX and Pin 8 as TX for SoftwareSerial. We named it as mySerial for simple use.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 8); // (RX,TX of Arduino)

In the setup loop, we set the baud rate for GPS as 9600 (default NEO6M Baud rate).

mySerial.begin(9600);

Inside the main loop, when the data is available we store the data in rawData variable from the GPS Module and then print it on the serial monitor.

while (mySerial.available() > 0)
  {
    byte rawData = mySerial.read();//Storing bytes in rawData Variable
    Serial.write(rawData); //Printing rawData on Serial Monitor
  }

Now upload the full code and open serial monitor, Make sure the baud rate is set as 9600 and the GPS LED is blinking. If everything is perfect you can see the data like this below.

 

“$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n”

“$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n”

“$GPRMC,045200.000,A,3014.3820,N,09748.9514,W,36.88,65.02,030913,,,A*77\r\n”

“$GPGGA,045201.000,3014.3864,N,09748.9411,W,1,10,1.2,200.8,M,-22.5,M,,0000*6C\r\n”

“$GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D\r\n”

“$GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F\r\n”;

 

It might look confusing because these are huge bytes of data coming in GPS Language. These are called NMEA Sentences. NMEA Stands for National Marine Electronics Association. There are some online parsers available to decode the information. But we need to parse it in our Arduino Board. For that, there is a library available called TinyGPS++ to parse the GPS Data. We will see how to use it easily.

Parsing data using TinyGPS++ Library:

  • Download the TinyGPS++ Library.
  • In Arduino IDE, go to Sketch > Include Library > Add .ZIP Library > Select the downloaded .zip library.
  • Close and Re-Open your IDE. Copy paste the following code.

Coding to parse Latitude and Longitude data using TinyGPS++ Library:

/*
 * Author: Sharath
 * Website: www.factoryforward.com
 */
 
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 9, TXPin = 8; //Arduino SoftSerial
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps; //TinyGPS Object

// The serial connection to the GPS device
SoftwareSerial mySerial(RXPin, TXPin);

void setup()
{
  Serial.begin(9600);
 mySerial.begin(GPSBaud);
}

void loop()
   {
    while (mySerial.available() > 0)
     {
      gps.encode(mySerial.read());
      if (gps.location.isUpdated())
       {
        Serial.print("Latitude= "); 
        Serial.print(gps.location.lat(), 6); //Getting Latitude
        Serial.print(" Longitude= "); 
        Serial.println(gps.location.lng(), 6); //Getting Longitude

        // Number of satellites in use
        Serial.print("Number os satellites in use = "); 
        Serial.println(gps.satellites.value()); 
       }
      }
    }

Upload the code and you can see the latitude and longitude values get displayed every second, once the data is parsed.

Share this post

Comment (1)

  • Teja

    Iam doing a project using neo 6m GPS ,900 a GSM,16*2lcd,an emergency switch. The theme of the project is that on pressing the switch the location must be sent to the predefined mobile number in the code and the same to be displayed on the lcd. Please help me with the code.

    October 11, 2019 at 6:00 PM

Leave a Reply

Back to Blog