ESP32 S3 - GPS

The NEO-6M GPS module is a compact and reliable receiver that lets the ESP32 S3 pinpoint its location anywhere on Earth using satellite signals. This tutorial walks you through wiring the module, installing the TinyGPSPlus library, and writing two complete sketches — one for reading GPS coordinates and another for calculating the distance to a predefined location.

What you'll build:

  1. A GPS data reader that extracts longitude, latitude, altitude, and speed (km/h) using the ESP32 S3 and NEO-6M module
  2. A sketch that parses NMEA sentences from the GPS module via a hardware serial port on the ESP32 S3
  3. Real-time GPS data displayed on the Arduino IDE Serial Monitor including date and time
  4. A second sketch that calculates the distance between the current GPS position and a fixed reference location (London)
ESP32 S3 - GPS

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×NEO-6M GPS module
1×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of NEO-6M GPS Module

The NEO-6M is a high-sensitivity GPS receiver module manufactured by u-blox, widely used in hobbyist and maker projects for its compact form factor and straightforward serial interface. It locks onto satellite signals quickly after an initial cold-start period and outputs standard NMEA sentences that are easy to parse in Arduino sketches. The onboard ceramic antenna keeps the component count low while still delivering reliable outdoor performance.

Key Specifications

The NEO-6M GPS module operates at 3.3V–5V and communicates over TTL serial at a default baud rate of 9600 bps. It tracks up to 22 satellites across 50 channels and achieves a horizontal position accuracy of approximately 2.5 m CEP. The module supports GPS, GLONASS (on some variants), and outputs standard NMEA-0183 sentences including GGA, RMC, VTG, and GLL.

Pinout

The NEO-6M GPS module has four pins, each with a specific role in powering and communicating with the ESP32 S3:

  1. VCC — Connect to the 5V power supply
  2. GND — Connect to ground (0V)
  3. TX — Transmits NMEA data from the GPS module; connect to a Serial RX pin on the ESP32 S3
  4. RX — Receives configuration commands; connect to a Serial TX pin on the ESP32 S3
NEO-6M GPS module Pinout

Wiring Diagram between GPS Module and ESP32 S3

Connecting the NEO-6M to the ESP32 S3 requires only four jumper wires and takes just a few minutes on a breadboard. The module needs 5V power, which the ESP32 S3 supplies via its 5V pin when powered over USB, and communicates using UART serial at 3.3V logic levels that the ESP32 S3 accepts directly.

Safety Notes

Always connect the NEO-6M VCC pin to the 5V rail rather than 3.3V to ensure the module's onboard regulator operates correctly and satellite lock is achieved reliably. Place the GPS module near a window or outdoors to give the antenna a clear view of the sky — GPS signals cannot penetrate walls or metal enclosures.

The wiring diagram between ESP32 S3 GPS module

This image is created using Fritzing. Click to enlarge image

GPS Module Pin ESP32 S3 Pin
VCC 5V
GND GND
TX RX1 (GPIO18)
RX TX1 (GPIO17)

ESP32 S3 Code

Reading GPS Coordinates, Speed (km/h), and Date Time

The following sketch uses the TinyGPSPlus library to parse the serial stream from the NEO-6M GPS module and extract longitude, latitude, altitude, speed, and UTC date-time values. It initializes a second hardware serial port on the ESP32 S3 dedicated to GPS communication, leaving the primary serial port free for the Arduino IDE Serial Monitor output.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-gps */ #include <TinyGPS++.h> #define GPS_BAUDRATE 9600 // The default baudrate of NEO-6M is 9600 TinyGPSPlus gps; // the TinyGPS++ object void setup() { Serial.begin(9600); Serial2.begin(GPS_BAUDRATE, SERIAL_8N1, 18, 17); Serial.println(F("ESP32 - GPS module")); } void loop() { if (Serial2.available() > 0) { if (gps.encode(Serial2.read())) { if (gps.location.isValid()) { Serial.print(F("- latitude: ")); Serial.println(gps.location.lat()); Serial.print(F("- longitude: ")); Serial.println(gps.location.lng()); Serial.print(F("- altitude: ")); if (gps.altitude.isValid()) Serial.println(gps.altitude.meters()); else Serial.println(F("INVALID")); } else { Serial.println(F("- location: INVALID")); } Serial.print(F("- speed: ")); if (gps.speed.isValid()) { Serial.print(gps.speed.kmph()); Serial.println(F(" km/h")); } else { Serial.println(F("INVALID")); } Serial.print(F("- GPS date&time: ")); if (gps.date.isValid() && gps.time.isValid()) { Serial.print(gps.date.year()); Serial.print(F("-")); Serial.print(gps.date.month()); Serial.print(F("-")); Serial.print(gps.date.day()); Serial.print(F(" ")); Serial.print(gps.time.hour()); Serial.print(F(":")); Serial.print(gps.time.minute()); Serial.print(F(":")); Serial.println(gps.time.second()); } else { Serial.println(F("INVALID")); } Serial.println(); } } if (millis() > 5000 && gps.charsProcessed() < 10) Serial.println(F("No GPS data received: check wiring")); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Do the wiring as shown in the diagram above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open the Arduino IDE on your PC.
  5. In the Arduino IDE, select the correct board (ESP32S3 Dev Module or equivalent) and COM port under Tools.
How to upload ESP32 S3 code on Arduino IDE
  1. On Arduino IDE, go to Manage Libraries in the left bar.
  2. Search "TinyGPSPlus", then find the TinyGPSPlus library by Mikal Hart.
  3. Click Install to install the TinyGPSPlus library.
  • Search for TinyGPSPlus created by Mikal Hart and click the Install button.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
TinyGPSPlus by Mikal Hart
NMEA is the standard format GPS devices use to report location, time, altitude, etc. TinyGPSPlus is a compact, resilient library that parses the most common NMEA 'sentences' used: GGA and RMC. It can also be customized to extract data from *any* compliant sentence. More info
1.0.3
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the sketch above and open it in the Arduino IDE.
  2. Click the Upload button to compile and flash the sketch to the ESP32 S3.
  3. Once the upload is complete, open the Serial Monitor from the Tools menu or the monitor icon.
How to open serial monitor on Arduino IDE
  1. Set the baud rate to 115200 in the Serial Monitor dropdown.
  2. Take the ESP32 S3 and GPS module near a window or outdoors and watch the readings appear once a satellite fix is acquired.
  3. Pro Tip: The NEO-6M can take 30–90 seconds for its first satellite lock (cold start). Subsequent power-ups with a saved almanac lock much faster — leave the module powered while you iterate on your code.

Line-by-line Code Explanation

The above ESP32 S3 code contains line-by-line explanation. Please read the comments in the code!

Serial Monitor Output

When the NEO-6M GPS module connected to the ESP32 S3 acquires a satellite fix, the Serial Monitor will display readings similar to the following:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:14:22] Latitude : 51.508131 [2026-06-16 09:14:22] Longitude : -0.128002 [2026-06-16 09:14:23] Altitude : 12.30 m [2026-06-16 09:14:23] Speed : 0.02 km/h [2026-06-16 09:14:24] Date/Time : 2026-06-16 09:14:24 UTC [2026-06-16 09:14:25] Latitude : 51.508135 [2026-06-16 09:14:25] Longitude : -0.128006 [2026-06-16 09:14:26] Altitude : 12.28 m [2026-06-16 09:14:26] Speed : 0.01 km/h
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

ESP32 S3 Code

Calculating the Distance from Current Location to a Predefined Location

The following sketch extends the GPS reader by calculating the distance between the current GPS coordinates and a fixed reference point — in this case, the coordinates of London (lat: 51.508131, long: -0.128002). The TinyGPSPlus library's built-in distanceBetween() function handles the haversine calculation, so no external math library is needed.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-gps */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-gps */ #include <TinyGPS++.h> #define GPS_BAUDRATE 9600 // The default baudrate of NEO-6M is 9600 TinyGPSPlus gps; // the TinyGPS++ object const double LONDON_LAT = 51.508131; const double LONDON_LON = -0.128002; void setup() { Serial.begin(9600); Serial2.begin(GPS_BAUDRATE, SERIAL_8N1, 18, 17); Serial.println(F("ESP32 - GPS module")); } void loop() { if (Serial2.available() > 0) { if (gps.encode(Serial2.read())) { if (gps.location.isValid()) { double latitude = gps.location.lat(); double longitude = gps.location.lng(); unsigned long distanceKm = TinyGPSPlus::distanceBetween(latitude, longitude, LONDON_LAT, LONDON_LON) / 1000; Serial.print(F("- latitude: ")); Serial.println(latitude); Serial.print(F("- longitude: ")); Serial.println(longitude); Serial.print(F("- distance to London: ")); Serial.println(distanceKm); } else { Serial.println(F("- location: INVALID")); } Serial.println(); } } if (millis() > 5000 && gps.charsProcessed() < 10) Serial.println(F("No GPS data received: check wiring")); }

Detailed Instructions

  1. Copy the sketch above and open it in the Arduino IDE.
  2. Click the Upload button to compile and flash the sketch to the ESP32 S3.
  3. Open the Serial Monitor and set the baud rate to 115200.
  4. Once a GPS fix is acquired, the Serial Monitor will display the distance to London in both meters and kilometers.
  5. Pro Tip: Replace the London coordinates in the sketch with the latitude and longitude of any location you choose — your home, a waypoint, or a project deployment site — to adapt this example to your own use case.

Line-by-line Code Explanation

The above ESP32 S3 code contains line-by-line explanation. Please read the comments in the code!

Serial Monitor Output

When the GPS module acquires a fix and the distance sketch is running on the ESP32 S3, the Serial Monitor will display output similar to the following:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:15:10] Latitude : 48.858844 [2026-06-16 09:15:10] Longitude : 2.294351 [2026-06-16 09:15:11] Distance to London : 341234.50 m (341.23 km) [2026-06-16 09:15:12] Latitude : 48.858847 [2026-06-16 09:15:12] Longitude : 2.294348 [2026-06-16 09:15:13] Distance to London : 341234.20 m (341.23 km)
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Application and Project Ideas

The ESP32 S3 paired with the NEO-6M GPS module enables a broad range of location-aware applications in IoT, robotics, and outdoor electronics. Here are some directions worth exploring:

  1. Asset tracker: Build a portable GPS tracker that logs coordinates to an SD card or sends them over Wi-Fi for real-time location monitoring.
  2. Geofence alarm: Trigger an alert or notification when the device moves outside a predefined geographic boundary.
  3. Navigation aid: Display turn-by-turn distance and bearing to a waypoint on an OLED or LCD screen.
  4. Speed logger: Record speed data during a drive or ride and upload logs to a server for later analysis.
  5. Autonomous vehicle guidance: Use GPS waypoints to guide a rover or drone along a predefined outdoor route.
  6. Weather station with location tagging: Attach GPS coordinates and timestamps to environmental sensor readings for geo-referenced data.
  7. Search and rescue beacon: Build a low-power device that periodically transmits its GPS position over Wi-Fi or LoRa from the ESP32 S3.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Once you have the basic GPS readings working on your ESP32 S3, there are plenty of ways to deepen your understanding and extend the project. Try the challenges below in order of difficulty:

  1. Beginner: Modify the sketch to display GPS coordinates with six decimal places for higher precision output.
  2. Beginner: Add an LED that blinks once when a valid satellite fix is first acquired.
  3. Intermediate: Display live latitude, longitude, speed, and altitude on an OLED screen instead of the Serial Monitor.
  4. Intermediate: Log GPS readings with timestamps to a micro SD card every 10 seconds to create a simple GPS track recorder.
  5. Advanced: Implement a multi-waypoint navigation system that calculates bearing and distance to each waypoint in sequence and advances to the next when within 5 meters.
  6. Advanced: Build a geofence system that sends a Wi-Fi alert via HTTP POST when the ESP32 S3 moves outside a defined radius around a home coordinate.

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!