Community project

ESP32 GPS Tracker

Photo of ESP32 GPS Tracker

Ruben Sebastian Graneros Rojas

Published November 29, 2026

This project turns an ESP32 microcontroller into a GPS tracker that logs location data to the cloud. The NEO-6M GPS module provides real-time latitude and longitude coordinates, while the ESP32 handles WiFi connectivity and secure communication with a Firebase backend.

The guide includes a complete wiring diagram, parts list, and step-by-step assembly instructions. You'll learn how to connect the GPS module directly to the ESP32, configure the antenna, and upload firmware that reads GPS coordinates and syncs them to your database. The tracker updates location data every 10 seconds when connected to WiFi.

Wiring diagram

Wiring diagram for ESP32 GPS Tracker
Loading diagram…

Gather all the parts

QtyComponent
1

NEO-6M GPS Module

u-blox NEO-6M based GPS receiver module. Outputs NMEA sentences (GGA, RMC, etc.) over UART at 9600 baud by default. Provides latitude, longitude, altitude, speed, and time. The NEO-6M module itself is a 3.3V-class device; many GY-NEO6MV2 breakout boards accept 5V on their VCC header through an onboard regulator, but UART I/O remains 3.3V-domain and must not be driven above 3.6V. Features an on-board patch antenna footprint and an SMA/IPEX connector for external active antenna (preferred for faster lock acquisition). Supply current ~45 mA in acquisition, ~11 mA in tracking.

Assemble it in 3 steps

1. Connect directly without a breadboard

With USB unplugged, use three female-to-female jumper leads between fitted headers. GPS VCC to ESP32 3V3 supplies power; GND to GND is the common ground; GPS TX to GPIO16 carries position data. Leave RX and PPS disconnected. Insulate exposed joints and secure the boards so they cannot touch.

  • Do not put 5 V on an ESP32 signal pin. Verify the GPS breakout supply specification before changing its supply.

2. Fit the GPS antenna

Fit the NEO-6M module's matching ceramic patch antenna and coax lead to its antenna socket, not an ESP32 pin. For the common GY-NEO6MV2 this is the supplied IPEX antenna cable. Align it carefully and press straight down; never force an incompatible connector. Point the ceramic face toward open sky outdoors.

  • Buy a matching replacement antenna for your GPS breakout if yours is missing. The Samsung phone antenna does not receive GPS for the ESP32.

3. Supply power and keep the hotspot nearby

Power the ESP32 using USB. Keep the Samsung phone nearby with its mobile data and 2.4 GHz Wi-Fi hotspot enabled. Keep the GPS antenna away from the ESP32 antenna and metal obstructions.

Review all connections

1. Connections between "gps" and "ESP32"

FunctiongpsESP32
powerVCC3V3
groundGNDGND
uartTXGPIO 16

Deploy the firmware

#include <Arduino.h>
#include <TinyGPS++.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <time.h>
#include "config.h"

TinyGPSPlus gps;
String token, uid;
uint32_t loginAt = 0, cloudAt = 0;
bool configured() { return WIFI_SSID[0] && DATABASE_URL[0] && FIREBASE_API_KEY[0] && DEVICE_EMAIL[0] && DEVICE_PASSWORD[0] && strlen(TLS_ROOTS) > 100; }

int request(const String &url, const String &body, bool put, String &reply) {
  WiFiClientSecure client;
  client.setCACert(TLS_ROOTS);
  HTTPClient http;
  http.setConnectTimeout(5000); http.setTimeout(5000);
  if (!http.begin(client, url)) return -1;
  http.addHeader("Content-Type", "application/json");
  int code = put ? http.PUT(body) : http.POST(body);
  if (code == 200) reply = http.getString();
  http.end(); return code;
}

void cloudTick() {
  if (!configured() || WiFi.status() != WL_CONNECTED || time(nullptr) < 1700000000) return;
  if (millis() - cloudAt < 10000) return;
  cloudAt = millis();
  if (token.isEmpty() || millis() - loginAt > 3000000UL) {
    JsonDocument auth; auth["email"] = DEVICE_EMAIL; auth["password"] = DEVICE_PASSWORD; auth["returnSecureToken"] = true;
    String body, reply; serializeJson(auth, body);
    int code = request(String("https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=") + FIREBASE_API_KEY, body, false, reply);
    JsonDocument result;
    if (code != 200 || deserializeJson(result, reply)) { Serial.printf("Firebase sign-in failed (%d). Check configuration.\n", code); return; }
    token = result["idToken"].as<String>(); uid = result["localId"].as<String>(); loginAt = millis();
  }
  if (!gps.location.isValid() || gps.location.age() > 5000) return;
  JsonDocument point;
  point["lat"] = gps.location.lat(); point["lng"] = gps.location.lng();
  if (gps.speed.isValid()) point["speedKmh"] = gps.speed.kmph();
  point["updatedAt"][".sv"] = "timestamp";
  String body, reply; serializeJson(point, body);
  int code = request(String(DATABASE_URL) + "/trackers/" + uid + "/latest.json?auth=" + token, body, true, reply);
  Serial.printf("Firebase position upload: %d\n", code);
  if (code == 401) token = "";
}



HardwareSerial gpsPort(2);
uint32_t lastReport = 0;
uint32_t previousChars = 0;

void setup() {
  Serial.begin(115200);
  if (configured()) {
    WiFi.mode(WIFI_STA); WiFi.setAutoReconnect(true); WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    configTime(0, 0, "pool.ntp.org", "time.google.com");
  } else Serial.println("Cloud disabled: fill include/config.h including HTTPS root certificates.");
  // Receive only: the GPS RX pin is deliberately left disconnected.
  gpsPort.begin(9600, SERIAL_8N1, 16, -1);
  Serial.println("GPS tracker ready. Take the antenna outdoors, facing the sky.");
}

void loop() {
  while (gpsPort.available()) gps.encode(gpsPort.read());
  cloudTick();
  if (millis() - lastReport < 2000) return;
  lastReport = millis();
  uint32_t chars = gps.charsProcessed();
  if (chars == previousChars) {
    Serial.println("No GPS data: check power, GND, and GPS TX -> GPIO16 (9600 baud).");
  } else if (!gps.location.isValid() || gps.location.age() > 5000) {
    Serial.print("Waiting for a fresh satellite fix. Satellites: ");
    if (gps.satellites.isValid()) Serial.println(gps.satellites.value());
    else Serial.println("unknown");
  } else {
    double lat = gps.location.lat();
    double lon = gps.location.lng();
    Serial.printf("Latitude: %.6f  Longitude: %.6f\n", lat, lon);
    if (gps.speed.isValid() && gps.speed.age() < 5000)
      Serial.printf("Speed: %.1f km/h\n", gps.speed.kmph());
    if (gps.altitude.isValid() && gps.altitude.age() < 5000)
      Serial.printf("Altitude: %.1f m\n", gps.altitude.meters());
    Serial.printf("Map: https://maps.google.com/?q=%.6f,%.6f\n", lat, lon);
  }
  previousChars = chars;
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik