Interface ublox NEO-6M GPS Module with Arduino

Give your next Arduino project ability to sense locations with NEO-6M GPS Module that can track up to 22 satellites and identifies locations anywhere in the world. It may serve as a great launch pad for anyone looking to get into the world of GPS.

They are low power (suitable for battery powered devices), inexpensive, easy to interface with and are insanely popular among hobbyists.

How does GPS work?

GPS receivers actually work by figuring out how far they are from a number of satellites. They are pre-programmed to know where the GPS satellites are at any given time.

The satellites transmit information about their position and the current time in the form of radio signals towards the Earth. These signals identify the satellites and tell the receiver where they are located.

How GPS Works - Trilateration Process

The receiver then calculates how far away each satellite is by figuring out how long it took for the signals to arrive. Once it has information on how far away at least three satellites are and where they are in space, it can pinpoint your location on Earth.

This process is known as Trilateration.

Hardware Overview of NEO-6M GPS Module

NEO-6M GPS Chip

At the heart of the module is a NEO-6M GPS chip from u-blox. The chip measures less than the size of a postage stamp but packs a surprising amount of features into its little frame.

NEO-6M GPS Module Chip

It can track up to 22 satellites on 50 channels and achieves the industry’s highest level of sensitivity i.e. -161 dB tracking, while consuming only 45mA supply current.

Unlike other GPS modules, it can do up to 5 location updates a second with 2.5m Horizontal position accuracy. The u-blox 6 positioning engine also boasts a Time-To-First-Fix (TTFF) of under 1 second.

One of the best features the chip provides is Power Save Mode(PSM). It allows a reduction in system power consumption by selectively switching parts of the receiver ON and OFF. This dramatically reduces power consumption of the module to just 11mA making it suitable for power sensitive applications like GPS wristwatch.

The necessary data pins of NEO-6M GPS chip are broken out to a 0.1″ pitch headers. This includes pins required for communication with a microcontroller over UART. The module supports baud rate from 4800bps to 230400bps with default baud of 9600.

Here are complete specifications:

NEO-6M GPS Chip Specifications
Receiver Type50 channels, GPS L1(1575.42Mhz)
Horizontal Position Accuracy2.5m
Navigation Update Rate1HZ (5Hz maximum)
Capture TimeCool start: 27s
Hot start: 1s
Navigation Sensitivity-161dBm
Communication ProtocolNMEA, UBX Binary, RTCM
Serial Baud Rate4800-230400 (default 9600)
Operating Temperature-40°C ~ 85°C
Operating Voltage2.7V ~ 3.6V
Operating Current45mA
TXD/RXD Impedance510Ω

For more information about NEO-6M GSM chip, check out this datasheet.

Position Fix LED Indicator

NEO-6M GPS Module - Position Fix LED Indicator

There is an LED on the NEO-6M GPS Module which indicates the status of Position Fix. It’ll blink at various rates depending on what state it’s in:

  • No Blinking – It’s searching for satellites.
  • Blink every 1s – Position Fix is found(The module can see enough satellites).

3.3V LDO Regulator

NEO-6M GPS Module - 3.3V Voltage Regulator

The operating voltage of the NEO-6M chip is from 2.7 to 3.6V. But the good news is that, the module comes with MIC5205 ultra-low dropout 3V3 regulator from MICREL.

The logic pins are also 5-volt tolerant, so we can easily connect it to an Arduino or any 5V logic microcontroller without using any logic level converter.

Battery & EEPROM

NEO-6M GPS Module - Battery and EEPROM

The module is equipped with an HK24C32 two wire serial EEPROM. It is 4KB in size and connected to the NEO-6M chip via I2C.

The module also contains a rechargeable button battery which acts as a super-capacitor.

An EEPROM together with battery helps retain the battery backed RAM (BBR). The BBR contains clock data, latest position data(GNSS orbit data) and module configuration. But it’s not meant for permanent data storage.

As the battery retains clock and last position, time to first fix (TTFF) significantly reduces to 1s. This allows much faster position locks.

Without the battery the GPS always cold-start so the initial GPS lock takes more time.

The battery is automatically charged when power is applied and maintains data for up to two weeks without power.

Antenna

An antenna is required to use the module for any kind of communication. So, the module comes with a patch antenna having -161 dBm sensitivity.

NEO-6M Patch Antenna

You can snap-fit this antenna to small U.FL connector located on the module.

NEO-6M GPS Module - u.fl Connector

Patch antenna is great for most projects. But if you want to achieve more sensitivity or put your module inside a metal case, you can also snap on any 3V active GPS antenna via the U.FL connector.

TIP

U.FL connectors are small, delicate and are not rated for strain. To prevent damaging the U.FL connection, we recommend threading the U.FL cable through the mounting hole, then attach the U.FL connectors.

NEO-6M GPS Module Pinout

The NEO-6M GPS module has total 4 pins that interface it to the outside world. The connections are as follows:

Ublox NEO-6M GPS Module Pinout

GND is the Ground Pin and needs to be connected to GND pin on the Arduino.

TxD (Transmitter) pin is used for serial communication.

RxD (Receiver) pin is used for serial communication.

VCC supplies power for the module. You can directly connect it to the 5V pin on the Arduino.

Wiring NEO-6M GPS module with Arduino UNO

Now that we know everything about the module, we can begin hooking it up to our Arduino!

Start by connecting the patch antenna to the U.FL connector. Remember to thread the U.FL cable through one of the mounting holes for robust connection.

The module usually comes with header pins unsoldered. So, you’ll need to solder them.

Now, connect Tx and Rx pin on module to digital pin#2 and #3 respectively on Arduino; as we’ll be using software serial to talk to the module.

Next, connect VCC pin to the 5V pin on the arduino and GND to ground.

Wiring Connections NEO-6M GPS Module to Arduino UNO
Wiring NEO-6M GPS Module to Arduino UNO

Once you have everything hooked up you are ready to go!

Arduino Code – Reading GPS Data

The best thing about any GPS receiver is that they start spitting out data as soon as you turn them ON.

The best way to test this data is to use Arduino as USB to TTL Converter. Following program does just that.

#include <SoftwareSerial.h>

// Choose two Arduino pins to use for software serial
int RXPin = 2;
int TXPin = 3;

//Default baud of NEO-6M is 9600
int GPSBaud = 9600;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

void setup()
{
  // Start the Arduino hardware serial port at 9600 baud
  Serial.begin(9600);

  // Start the software serial port at the GPS's default baud
  gpsSerial.begin(GPSBaud);
}

void loop()
{
  // Displays information when new sentence is available.
  while (gpsSerial.available() > 0)
    Serial.write(gpsSerial.read());
}

Upload the program and open up the serial monitor from the Arduino IDE. Remember to select 9600 baud. You should see text like the following:

NEO-6M GPS NMEA Sentences Output On Arduino

The data you are getting over a serial interface are actually NMEA sentences.

NMEA is an acronym for the National Marine Electronics Association. This is a standard message format for Nearly all GPS receivers.

The NMEA standard is formatted in lines of data called sentences. Each sentence is comma separated to make it easier to parse by computers and microcontrollers.

These NMEA sentences are sent out at an interval called the update rate.

NEO-6M GPS module updates this information once per second(1Hz frequency) by default. But you can configure it for up to 5 updates per second(5Hz frequency).

Parsing NMEA Sentences

There are many sentences in the NMEA standard, the most common ones are:

  • $GPRMC (Global Positioning Recommended Minimum Coordinates) provides the time, date, latitude, longitude, altitude and estimated velocity.
  • $GPGGA sentence provides essential fix data which provide 3D location and accuracy data.

Let’s take an example of $GPRMC NMEA sentence from a GPS receiver.

$GPRMC, 123519, A, 4807.038, N, 01131.000, E,022.4, 084.4, 230394, 003.1, W*6A

Parsing $GPRMC NMEA sentence
$Every NMEA sentence starts with $ character.
GPRMCGlobal Positioning Recommended Minimum Coordinates
123519Current time in UTC – 12:35:19
AStatus A=active or V=Void.
4807.038,NLatitude 48 deg 07.038′ N
01131.000,ELongitude 11 deg 31.000′ E
022.4Speed over the ground in knots
084.4Track angle in degrees True
220318Current Date – 22rd of March 2018
003.1,WMagnetic Variation
*6AThe checksum data, always begins with *

Let’s take an example of $GPGGA NMEA sentence.

$GPGGA, 123519, 4807.038, N, 01131.000, E, 1, 08, 0.9, 545.4, M, 46.9, M, , *47

Parsing $GPGGA NMEA sentence
$Starting of NMEA sentence.
GPGGAGlobal Positioning System Fix Data
123519Current time in UTC – 12:35:19
4807.038,NLatitude 48 deg 07.038′ N
01131.000,ELongitude 11 deg 31.000′ E
1GPS fix
08Number of satellites being tracked
0.9Horizontal dilution of position
545.4,MAltitude in Meters (above mean sea level)
46.9,MHeight of geoid (mean sea level)
(empty field)Time in seconds since last DGPS update
(empty field)DGPS station ID number
*47The checksum data, always begins with *

For more information about NMEA sentences and what data they contain, check out gpsinformation.org

Arduino Code – TinyGPS Library

Often for our projects, we need to parse NMEA sentences into useful information. To simplify our work, we have a library called TinyGPS++ library.

This library does a lot of heavy lifting required for receiving data from GPS modules, such as reading and extracting useful data in the background. So, we don’t need to worry about icky parsing work.

Thanks to Mikal Hart for his great contribution. His website Arduiniana.org has a full overview of all of the capabilities of the TinyGPS++ library.

Download the library first, by visiting the GitHub repo or, just click this button to download the zip:

To install it, open the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library, and then select the TinyGPSPlus ZIP file that you just downloaded.  If you need more details on installing a library, visit this Installing an Arduino Library tutorial.

Once you have the library installed, you can copy below sketch into the Arduino IDE.

The following test sketch will print the location information(Latitude, Longitude & Altitude) and UTC(Date & Time) on the serial monitor. Try the sketch out; and then we will explain it in some detail.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

// Choose two Arduino pins to use for software serial
int RXPin = 2;
int TXPin = 3;

int GPSBaud = 9600;

// Create a TinyGPS++ object
TinyGPSPlus gps;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

void setup()
{
  // Start the Arduino hardware serial port at 9600 baud
  Serial.begin(9600);

  // Start the software serial port at the GPS's default baud
  gpsSerial.begin(GPSBaud);
}

void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read()))
      displayInfo();

  // If 5000 milliseconds pass and there are no characters coming in
  // over the software serial port, show a "No GPS detected" error
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println("No GPS detected");
    while(true);
  }
}

void displayInfo()
{
  if (gps.location.isValid())
  {
    Serial.print("Latitude: ");
    Serial.println(gps.location.lat(), 6);
    Serial.print("Longitude: ");
    Serial.println(gps.location.lng(), 6);
    Serial.print("Altitude: ");
    Serial.println(gps.altitude.meters());
  }
  else
  {
    Serial.println("Location: Not Available");
  }
  
  Serial.print("Date: ");
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print("/");
    Serial.print(gps.date.day());
    Serial.print("/");
    Serial.println(gps.date.year());
  }
  else
  {
    Serial.println("Not Available");
  }

  Serial.print("Time: ");
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(":");
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(":");
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(".");
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.println(gps.time.centisecond());
  }
  else
  {
    Serial.println("Not Available");
  }

  Serial.println();
  Serial.println();
  delay(1000);
}

The sketch starts by including TinyGPS++ library and software serial library. Then, we define arduino pins to which NEO-6M GPS module is connected and variable that stores default GPS baud rate.

Creating TinyGPSPlus object will help access special functions related to the library. Next, we create a software serial port called gpsSerial through which we can talk to the module.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

int RXPin = 2;
int TXPin = 3;
int GPSBaud = 9600;

TinyGPSPlus gps;
SoftwareSerial gpsSerial(RXPin, TXPin);

In the setup function, we need to initiate the serial communication with the PC as well as the GPS module.

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

In loop function, we call displayInfo() custom function which prints location information(Latitude, Longitude & Altitude) and UTC(Date & Time) on the serial monitor, every time a new NMEA sentence is correctly encoded.

If 5000 milliseconds pass and there are no characters coming in over the software serial port, we show No GPS detected error.

void loop()
{
  while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected"));
    while(true);
  }
}

This is how the output looks like on the serial monitor.

NEO-6M GPS TinyGPS++ Arduino Library Output

Other Useful Functions In TinyGPS++ Library

There are a few useful functions you can use with TinyGPS++ object. Few of them are listed below:

  • gps.speed.value() function returns current ground speed in 100ths of a knot.
  • gps.course.value() function returns current ground course in 100ths of a degree.
  • gps.satellites.value() function returns the number of visible, participating satellites.
  • gps.hdop.value() function returns horizontal diminution of precision.
  • If you want to know how old an object’s data is, call its age() method, which returns the number of milliseconds since its last update. If this returns a value greater than 1500 or so, it may be a sign of a problem like a lost fix.
  • If you want to extract data from any other NMEA sentence. You can use library’s custom extraction functionality by telling TinyGPS++ the sentence name and the field number you are interested in, like this:TinyGPSCustom magneticVariation(gps, "GPRMC", 10)And you can query it just like the others:magneticVariation.value()

U-center software

U-center from u-blox is a powerful tool for evaluation, performance analysis and configuration of u-blox GPS receivers including NEO-6M. It’s a free tool but can only be used on Windows platform.

It can display realtime structured and graphical data visualization from any GPS receiver such as

  • Satellite summary view
  • Navigation summary view
  • Compass, speedometer, clock, altimeter
  • Chart view of any two parameters of choice
  • Data recording and playback functionality

The software can be downloaded from U-blox website.

Connecting NEO-6M to U-center

In order to use U-center software, you need to connect your NEO-6M to PC using any USB to TTL converter.

Below image shows NEO-6M connected to PC through PL2303 USB to TTL converter.

Direct Computer Wiring - NEO-6M GPS Module with PL2303 USB to TTL Converter

Using U-center

After a successful installation, u-center can be started from the Start Menu (All Programs -> u-blox-> u-center -> u-center) and will start up as shown below.

U-center Software On Start

Locate the communication toolbar and click on the arrow beside the icon. This will show a list with all available COM ports. Select the corresponding COM port where the receiver is connected.

u-center COM Port Selection

The text console button will show you the raw NMEA sentences. This is handy for quickly inspecting the visible ASCII coming from the module over USB.

u-center Text Console

u-center can display positions on pre-calibrated or Google online (dynamic) maps

U-center Map View

For more information about U-center software, please refer this user guide.