views
Many beginners run into problems while setting up UART communication on ESP32. Wrong pin mapping, mismatched baud rate, and confusing SDK calls can waste hours. If you want to save time, the best way is to learn ESP32 UART programming with ESP-IDF examples. In this guide, we will explain UART basics, wiring, and working code so you can send and receive serial data without issues.
What is UART in ESP32?
UART (Universal Asynchronous Receiver and Transmitter) is one of the simplest communication protocols. ESP32 has three hardware UARTs:
-
UART0 – used for flashing firmware and debugging by default.
-
UART1 – available for user applications.
-
UART2 – available for user applications.
Each UART supports baud rates up to 5 Mbps.
ESP32 UART Pin Mapping
Default pin mapping is:
-
UART0 → TX0 (GPIO1), RX0 (GPIO3)
-
UART1 → TX1 (GPIO10), RX1 (GPIO9)
-
UART2 → TX2 (GPIO17), RX2 (GPIO16)
But ESP32 lets you remap UART pins to almost any GPIO using uart_set_pin()
.
ESP32 UART Programming with ESP-IDF
To work with UART in ESP-IDF, you need to:
-
Configure UART parameters.
-
Assign TX and RX pins.
-
Install a driver.
-
Write and read data.
Example 1: Sending Data with UART
This example shows how to send text over UART1.
This program sends a message every second over GPIO17 (TX) and GPIO16 (RX).
Example 2: Receiving Data with UART
Now let’s read data sent to ESP32 through UART.
This reads data from UART1 and echoes it back to the sender.
ESP32 UART Projects
Here are some practical uses:
-
GPS Module → read NMEA data over UART.
-
GSM Module → send AT commands.
-
PC Logging → send sensor data to PC.
-
Two ESP32 Boards → connect with UART2 for board-to-board communication.
Conclusion
ESP32 UART programming with ESP-IDF is easy once you set up pins, baud rate, and drivers correctly. With just a few lines of code, you can send and receive data. Whether you connect a GPS, GSM, or another ESP32 board, UART makes communication simple.
If you are starting your ESP32 journey, try these examples today. For more embedded tutorials, check out ControllersTech.

Comments
0 comment