Back to Tutorial

ESP32 with NEO-8M GPS Module


📡 What is the NEO-8M GPS Module?

The NEO-8M is a high-precision GNSS GPS receiver by u-blox, capable of receiving data from:

  • GPS (USA)
  • GLONASS (Russia)
  • Galileo (EU)
  • BeiDou (China)

It outputs serial (UART) data in NMEA sentences, giving real-time:

  • Latitude
  • Longitude
  • Altitude
  • Speed
  • Time & Date
  • Number of satellites
  • Fix quality

🧰 Components Required:

  • ESP32 (DevKit v1)
  • NEO-8M GPS Module (with or without ceramic antenna)
  • Jumper wires
  • Optional: OLED display or SD card module

⚙️ NEO-8M GPS Module Pinout:

GPS PinFunctionConnect to ESP32
VCC3.3V / 5V3.3V or 5V (check module specs)
GNDGroundGND
TXTransmit (output)GPIO16 (RX)
RXReceive (input)GPIO17 (TX)

📌 Use SoftwareSerial if you want to keep default Serial for debugging.


🛠️ Wiring Diagram:

GPS Module ESP32 ---------- ----- VCC ----------> 3.3V GND ----------> GND TX ----------> GPIO16 (RX2) RX ----------> GPIO17 (TX2)


💻 ESP32 Code (Using TinyGPSPlus Library)

1. ✅ Install Libraries:

Go to Arduino IDE:

  • Library Manager → Install TinyGPSPlus by Mikal Hart

🧠 How It Works:

  • The NEO-8M listens to satellite signals.
  • It calculates the location and time using trilateration.
  • Sends data to ESP32 as NMEA sentences like $GPRMC$GPGGA, etc.
  • TinyGPSPlus parses this and gives readable info.

🛰️ Real-world Applications:

  • Live Location Tracker
  • GPS Logger to SD Card
  • IoT Asset Tracking
  • Vehicle Tracking System
  • Geofencing
  • Outdoor Robotics / Drones

⚠️ Important Notes:

  • Cold start may take 15–60 seconds to get a GPS fix.
  • Use ceramic patch antenna or GPS module with active antenna for better signal.
  • Needs clear sky view for fast location lock.
  • Avoid indoor testing—it may not get GPS fix.
HOW TO OPERATE

#include <TinyGPSPlus.h>

// Define the RX and TX pins for Serial 2
#define RXD2 16
#define TXD2 17

#define GPS_BAUD 9600
TinyGPSPlus gps;
// Create an instance of the HardwareSerial class for Serial 2
HardwareSerial ss(2);


void setup()
{
  Serial.begin(115200);
  //ss.begin(GPS_BAUD);
  ss.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);

  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPSPlus with an attached GPS module"));
  Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

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

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

void displayInfo()
{
  Serial.print(F("Location: "));
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

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

  Serial.println();
}
ESP32 with NEO-8M GPS Module

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial