Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home IoT & Smart Home

ESP32 UART Serial: Reading GPS and GSM with Hardware Serial

ESP32 UART Serial: Reading GPS and GSM with Hardware Serial

March 11, 2026 /Posted byJayesh Jain / 0

Mastering ESP32 UART serial GPS GSM hardware serial communication is one of the most valuable skills for any IoT engineer or hobbyist in India. The ESP32 microcontroller has three hardware UART peripherals (UART0, UART1, UART2), which means you can simultaneously talk to a GPS module for location data, a GSM module for cellular communication, and still keep UART0 free for your debug console — all without any software bit-banging overhead. This tutorial walks you through the entire process from wiring to production-grade code.

Table of Contents

  1. Understanding ESP32 UART Architecture
  2. Hardware Serial vs Software Serial
  3. Wiring a GPS Module (NEO-6M / NEO-8M)
  4. Wiring a GSM Module (SIM800L / SIM900)
  5. Arduino Code for Dual UART Operation
  6. Common Issues and Fixes
  7. Frequently Asked Questions

Understanding ESP32 UART Architecture

The ESP32 is built on a dual-core Xtensa LX6 processor and includes three hardware UART controllers: UART0, UART1, and UART2. Each UART can be remapped to almost any GPIO pin using the ESP32’s GPIO matrix — this is a significant advantage over the AVR-based Arduino boards where UARTs are fixed to specific pins.

Default pin assignments for the ESP32 DEVKIT board are:

UART Default TX Default RX Primary Use
UART0 GPIO1 GPIO3 Debug/programming (USB)
UART1 GPIO10 GPIO9 Flash memory (usually reserved)
UART2 GPIO17 GPIO16 Free for user use

In practice you should remap UART1 to safer GPIO pins (e.g., GPIO25/GPIO26) since GPIO9 and GPIO10 share the flash memory bus and can cause crashes on some modules. UART2 with its default GPIO16/GPIO17 is the safest choice for your first peripheral without any remapping.

Hardware Serial vs Software Serial

Software serial (bit-banging) on the ESP8266 is notoriously unreliable above 9600 baud and causes Wi-Fi interruptions because it disables interrupts during bit periods. The ESP32 with its three hardware UARTs has no such limitation. Each hardware UART has dedicated silicon with a 128-byte RX FIFO buffer and a hardware baud rate generator, so you can receive GPS NMEA sentences at 9600 baud and GSM AT commands at 115200 baud simultaneously without missing a single character.

The Arduino ESP32 core represents these as HardwareSerial objects: Serial (UART0), Serial1 (UART1), Serial2 (UART2). You initialise them using the begin(baudRate, config, rxPin, txPin) overload.

Ai Thinker NodeMCU-32S ESP32 Development Board

Ai Thinker NodeMCU-32S ESP32 Development Board – IPEX Version

A full-featured ESP32 development board with an IPEX antenna connector for enhanced range — ideal for GPS tracker and GSM projects.

View on Zbotic

Wiring a GPS Module (NEO-6M / NEO-8M)

The NEO-6M and NEO-8M GPS modules from u-blox are the most popular choices in India for hobbyist and professional projects. Both communicate over UART at 9600 baud by default and output standard NMEA 0183 sentences like $GPGGA, $GPRMC, and $GPGSA.

Wiring for ESP32 UART2 (no remapping needed):

  • GPS VCC → ESP32 3.3 V (important: the module runs on 3.3 V, not 5 V)
  • GPS GND → ESP32 GND
  • GPS TX → ESP32 GPIO16 (UART2 RX)
  • GPS RX → ESP32 GPIO17 (UART2 TX)

Note that you connect GPS TX to ESP32 RX and GPS RX to ESP32 TX — always cross the TX/RX lines. Many beginners trip up here. The GPS module’s TX line transmits data; your microcontroller’s RX line receives it.

In your Arduino sketch, initialise like this:

#include <TinyGPS++.h>

HardwareSerial GPSSerial(2);  // UART2
TinyGPSPlus gps;

void setup() {
  Serial.begin(115200);
  GPSSerial.begin(9600, SERIAL_8N1, 16, 17);  // RX=16, TX=17
}

void loop() {
  while (GPSSerial.available() > 0) {
    gps.encode(GPSSerial.read());
  }
  if (gps.location.isUpdated()) {
    Serial.printf("Lat: %.6f, Lon: %.6fn",
      gps.location.lat(), gps.location.lng());
  }
}

The TinyGPS++ library handles all the NMEA sentence parsing. It is available through the Arduino Library Manager and works perfectly with ESP32.

Wiring a GSM Module (SIM800L / SIM900)

The SIM800L is the most affordable GSM/GPRS module available in India, often found for under ₹400. It communicates via UART AT commands at 9600–115200 baud. The critical challenge with the SIM800L is power: it requires up to 2 A peak current during GSM registration and transmission bursts, which the ESP32’s 3.3 V pin cannot supply.

Power supply rules for SIM800L:

  • Supply voltage: 3.4 V to 4.4 V (optimal: 4.0 V)
  • Peak current: up to 2 A during transmission burst
  • Use a dedicated LiPo battery or a high-current LDO regulator (not the ESP32’s onboard regulator)
  • Add a 1000 µF capacitor across the SIM800L VCC and GND pins to buffer current spikes

Wiring for ESP32 UART1 remapped to safe pins:

  • SIM800L VCC → 4.0 V dedicated supply (LiPo or buck converter output)
  • SIM800L GND → common GND (shared with ESP32)
  • SIM800L TX → ESP32 GPIO26 (UART1 RX, remapped)
  • SIM800L RX → voltage divider → ESP32 GPIO25 (UART1 TX, remapped)
Voltage Level Warning: The ESP32 operates on 3.3 V logic. The SIM800L operates on 3.3 V logic too, but some clones operate at 5 V. Always check your specific module’s datasheet. If the SIM800L TX output is 5 V, use a resistor voltage divider (10 kΩ + 20 kΩ) on the line going into the ESP32 RX pin.

To initialise UART1 on custom pins:

HardwareSerial GSMSerial(1);  // UART1

void setup() {
  GSMSerial.begin(9600, SERIAL_8N1, 26, 25);  // RX=26, TX=25
  delay(3000);  // wait for SIM800L to register
  GSMSerial.println("AT");      // test communication
  delay(500);
  GSMSerial.println("AT+CMGF=1");  // SMS text mode
}

Arduino Code for Dual UART Operation

Running GPS and GSM simultaneously on two separate UART ports is straightforward because each HardwareSerial object manages its own buffer independently. Here is a complete dual-UART sketch that logs GPS position to a server via GSM:

#include <TinyGPS++.h>

HardwareSerial GPSSerial(2);   // UART2: GPS
HardwareSerial GSMSerial(1);   // UART1: SIM800L
TinyGPSPlus gps;

unsigned long lastSend = 0;
const unsigned long SEND_INTERVAL = 60000;  // 1 minute

void setup() {
  Serial.begin(115200);
  GPSSerial.begin(9600, SERIAL_8N1, 16, 17);
  GSMSerial.begin(9600, SERIAL_8N1, 26, 25);
  delay(3000);
  initGSM();
}

void initGSM() {
  GSMSerial.println("AT+CREG?");  // check registration
  delay(1000);
  GSMSerial.println("AT+CGATT=1");  // attach GPRS
  delay(2000);
  GSMSerial.println("AT+SAPBR=3,1,"Contype","GPRS"");
  delay(500);
  GSMSerial.println("AT+SAPBR=3,1,"APN","airtelgprs.com"");
  delay(500);
  GSMSerial.println("AT+SAPBR=1,1");
  delay(3000);
}

void sendGPSData(float lat, float lon) {
  GSMSerial.println("AT+HTTPINIT");
  delay(500);
  String url = "AT+HTTPPARA="URL","http://yourserver.in/track?lat="
               + String(lat, 6) + "&lon=" + String(lon, 6) + """;
  GSMSerial.println(url);
  delay(500);
  GSMSerial.println("AT+HTTPACTION=0");
  delay(5000);
  GSMSerial.println("AT+HTTPTERM");
}

void loop() {
  while (GPSSerial.available()) {
    gps.encode(GPSSerial.read());
  }
  if (gps.location.isValid() &&
      millis() - lastSend > SEND_INTERVAL) {
    sendGPSData(gps.location.lat(), gps.location.lng());
    lastSend = millis();
  }
}

Change the APN string to match your carrier: airtelgprs.com for Airtel, internet for Jio, www for BSNL, portalnmms for Vi (Vodafone Idea).

2x18650 Lithium Battery Shield for ESP32

2 x 18650 Lithium Battery Shield for Arduino, ESP32, ESP8266

Provides the high-current 5 V supply needed to reliably power ESP32 and the SIM800L module in GPS tracker builds.

View on Zbotic

Common Issues and Fixes

GPS has no fix indoors

GPS signals are extremely weak and cannot penetrate concrete buildings. For testing, hold the module near an open window or use a simulated NMEA signal over USB. The NEO-6M has a ceramic patch antenna — it must have a clear view of the sky to lock onto 4+ satellites. In India, GNSS also supports NavIC (IRNSS) satellites which improve fix times in the subcontinent. The NEO-M8N supports NavIC while the older NEO-6M does not.

SIM800L not responding to AT commands

The three most common causes: (1) insufficient power supply — the LED on the module should pulse every 3 seconds during normal network search; (2) baud rate mismatch — try autobaud by sending AT at multiple baud rates; (3) the module is in sleep mode — send a HIGH pulse on the DTR pin or cycle power.

Garbage characters in Serial Monitor

This almost always means a baud rate mismatch between what you set in begin() and what is set in the Serial Monitor dropdown. Both must match exactly. Also ensure the Serial Monitor line ending is set to “Both NL & CR” when sending AT commands to the GSM module.

30Pin ESP32 Expansion Board

30Pin ESP32 Expansion Board with Type-C and Micro USB Dual Interface

Breaks out all ESP32 pins cleanly onto screw terminals, making multi-UART wiring for GPS and GSM projects much more manageable.

View on Zbotic

Frequently Asked Questions

How many UART devices can the ESP32 handle simultaneously?

Three — one per hardware UART (UART0, UART1, UART2). UART0 is typically used by the USB serial programmer for debug output, leaving UART1 and UART2 for peripherals. If you need more than two external serial devices, you can use I2C-to-UART bridge chips like the SC16IS750 to expand to additional virtual COM ports over I2C.

Does the ESP32 support RS-232 or RS-485?

The ESP32 UART logic is 3.3 V TTL. For RS-232 (used in industrial meters and PLCs), you need a MAX232 or MAX3232 level converter chip. For RS-485 (half-duplex differential signalling used in Modbus), use a MAX485 or SP3485 transceiver. The ESP32 ESP-IDF framework has native RS-485 support with automatic driver enable/direction control.

Can I use UART for flashing OTA updates while GPS is running?

OTA over Wi-Fi or BLE does not use UART, so GPS and GSM operations are unaffected. If you are using the UART0 for serial flashing, the serial programmer conflicts with any sketch that also uses UART0 for its own serial communication — use UART2 or UART1 for peripherals so UART0 remains clean for programming.

What baud rate should I use for GPS modules?

Standard GPS modules default to 9600 baud. u-blox modules support up to 460800 baud after configuration via u-center software. Higher baud rates allow faster NMEA sentence delivery but consume more UART RX buffer — 9600 baud at 1 Hz update rate is sufficient for most vehicle tracking applications.

Build Your GPS GSM Tracker with ESP32

Zbotic has all the ESP32 boards, sensors, and accessories you need for serial communication projects. Fast shipping across India.

Shop ESP32 & IoT Components

Tags: ESP32 UART, GPS Module, GSM Module, Hardware Serial, serial communication
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
ESP-IDF vs Arduino IDE: Which ...
blog esp idf vs arduino ide which esp32 platform to choose 595500
blog xiao esp32 c3 smallest esp32 board for wearable projects 595507
XIAO ESP32-C3: Smallest ESP32 ...

Related posts

Svg%3E
Read more

IoT Home Insurance Sensor Kit: Leak, Smoke, and Motion

April 1, 2026 0
Table of Contents IoT and Home Insurance Water Leak Detection Smoke and Fire Detection Motion and Intrusion Sensing Building the... Continue reading
Svg%3E
Read more

IoT Pet Tracker: GPS Collar with Geofencing Alerts

April 1, 2026 0
Table of Contents Introduction and Overview Hardware Components Required GPS Module Integration with ESP32 Cloud Platform Setup Real-Time Tracking Dashboard... Continue reading
Svg%3E
Read more

IoT Aquaponics Controller: Fish and Plant Automation

April 1, 2026 0
Table of Contents The Water Monitoring Challenge in India Sensor Technologies for Water Building the Sensor Node Data Transmission and... Continue reading
Svg%3E
Read more

IoT Composting Monitor: Temperature and Moisture Tracking

April 1, 2026 0
Table of Contents Why Temperature Monitoring Matters Sensor Selection Guide Hardware Assembly and Wiring Firmware Development Cloud Data Logging Alert... Continue reading
Svg%3E
Read more

IoT Beehive Monitor: Weight, Temperature, and Humidity

April 1, 2026 0
Table of Contents Why Monitor Beehives Weight Measurement System Temperature and Humidity Sensing Building the Monitor Data Analysis for Bee... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now