Arduino NEO-6M GPS with TinyGPS++: Wiring, Code and Simulator

To build this Arduino NEO-6M GPS with TinyGPS++ project you need an Arduino Uno and an NEO-6M GPS module. TinyGPS++ reads the NEO-6M’s NMEA sentences on SoftwareSerial and prints latitude, longitude, satellites, speed and UTC time. Make the 4 connections in the wiring table, upload the Arduino C++ code, and move the GPS from the Modules tab, or set a speed and heading and watch the position change. Drop the satellites below 3 to lose the fix.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1NEO-6M GPS moduleGPS receiver: VCC (3.3–5 V), GND, TX → the board’s RX pin (SoftwareSerial at 9600). It sends real NMEA sentences ($GPRMC, $GPGGA…) once a second; read them with TinyGPS++. Move it from the Modules tab, or set a speed and heading and watch it travel.

Wiring

#FromTo
1Arduino Uno 5VNEO-6M GPS module VCC
2Arduino Uno GNDNEO-6M GPS module GND
3Arduino Uno pin 4NEO-6M GPS module TX
4Arduino Uno pin 3NEO-6M GPS module RX

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an NEO-6M GPS module from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to NEO-6M GPS module VCC.
  4. Wire 2. Connect Arduino Uno GND to NEO-6M GPS module GND.
  5. Wire 3. Connect Arduino Uno pin 4 to NEO-6M GPS module TX.
  6. Wire 4. Connect Arduino Uno pin 3 to NEO-6M GPS module RX.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Move the GPS from the Modules tab, or set a speed and heading and watch the position change. Drop the satellites below 3 to lose the fix.

Arduino C++ code

// GPS NEO-6M with TinyGPS++: position, speed, satellites and UTC time.
// GPS TX -> pin 4 (SoftwareSerial RX), GPS RX <- pin 3, VCC 5V, GND.
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(4, 3);  // RX, TX
TinyGPSPlus gps;
unsigned long lastPrint = 0;

void printTwo(int v) {
  if (v < 10) Serial.print('0');
  Serial.print(v);
}

void setup() {
  Serial.begin(115200);
  gpsSerial.begin(9600);
  Serial.println(F("Waiting for the GPS..."));
}

void loop() {
  while (gpsSerial.available()) gps.encode(gpsSerial.read());

  if (millis() - lastPrint < 1000) return;
  lastPrint = millis();

  // TinyGPS++ keeps the last position: a fix older than 2 s is a lost fix.
  if (!gps.location.isValid() || gps.location.age() > 2000) {
    Serial.print(F("No fix yet. Satellites: "));
    Serial.print(gps.satellites.value());
    Serial.print(F("  characters read: "));
    Serial.println(gps.charsProcessed());
    return;
  }
  Serial.print(F("Lat "));
  Serial.print(gps.location.lat(), 6);
  Serial.print(F("  Lng "));
  Serial.print(gps.location.lng(), 6);
  Serial.print(F("  Sats "));
  Serial.print(gps.satellites.value());
  Serial.print(F("  Speed "));
  Serial.print(gps.speed.kmph(), 1);
  Serial.print(F(" km/h  UTC "));
  printTwo(gps.time.hour());
  Serial.print(':');
  printTwo(gps.time.minute());
  Serial.print(':');
  printTwo(gps.time.second());
  Serial.println();
}

What to try

Move the GPS from the Modules tab, or set a speed and heading and watch the position change. Drop the satellites below 3 to lose the fix.

Frequently asked questions

How do I wire the NEO-6M GPS with TinyGPS++ project on an Arduino Uno?

Make 4 connections: Arduino Uno 5V to NEO-6M GPS module VCC; Arduino Uno GND to NEO-6M GPS module GND; Arduino Uno pin 4 to NEO-6M GPS module TX; Arduino Uno pin 3 to NEO-6M GPS module RX.

What parts do I need for this Arduino project?

An Arduino Uno and an NEO-6M GPS module.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

TinyGPS++ reads the NEO-6M’s NMEA sentences on SoftwareSerial and prints latitude, longitude, satellites, speed and UTC time.

Why does my NEO-6M GPS show no fix?

A GPS needs at least three, better four or more, satellites in view. Indoors it sees none: RMC says V and the position fields are empty. Take it outside and give it a minute (a cold start takes about 30 seconds). In the simulator, set the satellites above 3.

Which pins does the NEO-6M use on an Arduino Uno?

Its TX goes to a SoftwareSerial RX pin (pin 4 here), its RX to a TX pin (pin 3), VCC to 5 V and GND to GND. It talks at 9600 baud.

Why does TinyGPS++ still report a location after the fix is lost?

TinyGPS++ keeps the last valid position: isValid() stays true. Check location.age() — a fix older than a couple of seconds is a lost fix.

More Arduino Uno projects