I'm working on a project using an ESP32 and I want to connect 5 UART-based sensors to it. I know the ESP32 has multiple UARTs, but I'm not sure if it can handle 5 sensors at the same time.
My questions:
Is it possible to connect 5 UART sensors directly to a single ESP32 without additional hardware?
If not, would I need a UART expander or multiplexer module?
Are there any software-based solutions (like using SoftwareSerial) that could work reliably on the ESP32 for this?
Any advice or suggestions would be really helpful!
Is it possible to connect 5 UART sensors directly to a single ESP32 without additional hardware? Yes if the voltages match!
If not, would I need a UART expander or multiplexer module? You can use one depends on what you are doing.
Are there any software-based solutions (like using SoftwareSerial) that could work reliably on the ESP32 for this? Depends on baud etc and your software.
Basically wiring them in parallel to those UARTs? You do that directly and expect to fry many components. What you are wanting to do is called a wired or. That only works nicely with outputs that are active in only one direct and require a resistor for the other.
All of the sensors operate at 5V and get power through the ESP32's Vin pin. That can be a problem the Arduino is not a power supply. It depends on what sensors you have.
Would that cause any issues with signal collisions or reliability? Big Time YES!
Or is there a clean way to manage multiple UART sensors on the same lines? Yes but it will require some logic and a protocol to either eliminate collisions or detect them.
Multiplexers will only work if you can control when a sensor sends data. Else you have a good chance at data loss / corrupted data.
There are devices/modules that provide two UARTS via I2C or SPI; e.g. https://www.robotics.org.za/CJMCU-752. With 3 of those you will have 6 additional UARTs.
the last time I required a microcontroller six UARTs I used a Microchip PIC24FJ1024GA610 - however, as far as I am aware it is not supported by the Arduino IDE (I used the MPLABX IDE)
possibly look at STM32 microcontrollers?
does the five UARTs include the serial monitor or do you require serial monitor plus five UARTs
the ESP32 has three hardware serial ports (one usually used for serial monitor)
depending on baud rates additional serial ports could be added using EspSoftwareSerial
you need to experiment!
are the sensors available with other interfaces, e.g. I2C, SPI, Canbus, etc
If they are the type of sensor that transmits data at some regular interval, or random intervals, then you will need a hardware serial port for each one and software serial or multiplexers won't work.
If they are the type of sensor that transmits data only when requested by the Arduino, then you can use a software serial port for each sensor, or use multiplexers with a single hardware or software serial port.
A WinnerMicro W80x mcu family has up to 6 UARTs and has an Arduino IDE support package. Honesty speaking, the package porting is not fully finished, but includes most of the standard arduino functions and libraries.
There is another microcontroller than can handle even more UART's than 5
This is the propeller-chip from parallax . The propeller-chip has 8 cores (= 8 micro-controllers in one single DIP-package) This allows to truely execute code in parallel.
each core can handle up to 4 UARTs with 115200 baud
The programming language "SPIN" differs from C++.
You should post a link to the datasheet of your sensors
You should post an overview what you want to do in the end.
as an experiment I implemented this which reads characters from serial monitor and transmits to two hardware and four software serial ports
// ESP32 test four software serial ports
// using library EspSoftwareSerial
// https://www.arduino.cc/reference/en/libraries/espsoftwareserial/
#include <SoftwareSerial.h> // will compile/link EspSoftwareSerial
#define BAUD 74880 //57600
SoftwareSerial swSer1(12, 14);
SoftwareSerial swSer2(26, 27);
SoftwareSerial swSer3(18, 19);
SoftwareSerial swSer4(21, 22);
void setup() {
Serial.begin(115200); //Initialize hardware serial with baudrate of 115200
delay(2000);
// software serial baudrate 115200 fails - 74880 OK
swSer1.begin(BAUD); //Initialize software serial
swSer2.begin(BAUD); //Initialize software serial
swSer3.begin(BAUD); //Initialize software serial
swSer4.begin(BAUD); //Initialize software serial
Serial.println("\nESP32 Hardware/Software serial test started");
Serial1.begin(115200, SERIAL_8N1, 4, 5);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
}
void loop() {
while (Serial.available() > 0) { //wait for data at hardware serial
char ch= Serial.read();
swSer1.write(ch++); //send data recived from hardware serial to software serial
swSer2.write(ch++); //send data recived from hardware serial to software serial
swSer3.write(ch++); //send data recived from hardware serial to software serial
swSer4.write(ch++); //send data recived from hardware serial to software serial
Serial1.write(ch++); //send data recived from hardware serial to software serial
Serial2.write(ch++); //send data recived from hardware serial to software serial
Serial.printf("writing '%c' to serial ports\n", ch);
}
while (swSer1.available() > 0) { //wait for data at software serial
Serial.write("sw1>"); //Send data recived from software serial to hardware serial
Serial.println((char)swSer1.read()); //Send data recived from software serial to hardware serial
}
while (swSer2.available() > 0) { //wait for data at software serial
Serial.write("sw2>"); //Send data recived from software serial to hardware serial
Serial.println((char)swSer2.read()); //Send data recived from software serial to hardware serial
}
while (swSer3.available() > 0) { //wait for data at software serial
Serial.write("sw3>"); //Send data recived from software serial to hardware serial
Serial.println((char)swSer3.read()); //Send data recived from software serial to hardware serial
}
while (swSer4.available() > 0) { //wait for data at software serial
Serial.write("sw4>"); //Send data recived from software serial to hardware serial
Serial.println((char)swSer4.read()); //Send data recived from software serial to hardware serial
}
while (Serial1.available() > 0) { //wait for data at software serial
Serial.write("Serial1>"); //Send data recived from software serial to hardware serial
Serial.println((char)Serial1.read()); //Send data recived from software serial to hardware serial
}
while (Serial2.available() > 0) { //wait for data at software serial
Serial.write("Serial2>"); //Send data recived from software serial to hardware serial
Serial.println((char)Serial2.read()); //Send data recived from software serial to hardware serial
}
}
as a character is written to each serial port it's value is incremented
the ports have loopback links so bytes transmitted should be received and displayed
serial monitor output
ESP32 Hardware/Software serial test started
Serial1>ďż˝
Serial2>ďż˝
writing '1' to serial ports
sw1>1
sw2>2
sw3>3
sw4>4
Serial1>5
Serial2>6
writing '4' to serial ports
sw1>4
sw2>5
sw3>6
sw4>7
Serial1>8
Serial2>9
writing 'a' to serial ports
sw1>a
sw2>b
sw3>c
sw4>d
Serial1>e
Serial2>f
writing '1' to serial ports
writing '2' to serial ports
sw1>1
sw1>2
sw2>2
sw2>3
sw3>3
sw3>4
sw4>4
sw4>5
Serial1>5
Serial1>6
Serial2>6
Serial2>7
looks like the ESP32 using EspSoftwareSerial may do what you require
it is a case of experimenting
If you could change the microcontroller, the RP2040 (Raspberry Pi Pico, Arduino Nano Connect) allows you to emulate up to 4 bidirectional ports or 8 unidirectional ones using PIO, without relying on the processor. Additionally, it has 2 hardware ports, which would give you 6 ports (or 10). This is independent of the USB serial port.
Thanks for the reply and the detailed warning — that definitely makes sense.
Just to clarify, let’s say I have 5 sensors, all of which:
Communicate only via UART
Run at 5V logic and power (powered through ESP32’s Vin, possibly from USB or external 5V)
Require sending a specific address or command to trigger a response (i.e., they’re not spitting out data continuously)
How would you personally connect them to the ESP32 in this case?
Would you still recommend wiring their TX lines in parallel with some kind of logic level shifting and OR’ing setup, or would you go for a hardware UART mux, or something else entirely?
The sensors are not chatty, so polling them one at a time is totally fine, but I do need a clean and safe way to manage the TX lines so nothing gets damaged and no signals overlap.
Curious to hear what approach you'd go with if you had to wire these up practically.
Yes — to clarify, I need five UART connections in addition to the serial monitor, so a total of six UARTs. And let’s assume that the sensors are only available with UART interfaces — no I2C, SPI, or other options.
Out of curiosity — when you used the Microchip PIC24FJ1024GA610 for your project with six UARTs, was that choice specifically because of the ESP32's limitation of having only three hardware serial ports, or was there another reason (e.g., performance, architecture preference, etc.)?
I’m definitely open to exploring other microcontrollers like STM32 if there’s a clean and reliable way to scale up UART connections. Just wondering what led you to that chip in particular.
Thanks for the clarification — that helps narrow things down.
In my case, the sensors are the type that only transmit data when requested by the controller. So based on what you mentioned, it sounds like I could get away with using multiplexers and a single hardware or software serial port to manage all of them, since I can control exactly when each sensor communicates.
That might actually be the way I’ll go, considering the ESP32’s UART limitations.
Thanks for sharing that! I hadn’t heard of the WinnerMicro W80x family before — sounds promising, especially with support for up to 6 UARTs and some Arduino IDE compatibility. I’ll definitely keep it in mind as an option for this project.
Thanks for the suggestion — the Parallax Propeller chip sounds powerful, especially with its multi-core architecture and UART capability. I’ll definitely take a look at it!
That said, my current priority is to stick with the ESP32, mainly because it's widely used and there’s a large community familiar with it — which makes troubleshooting and support easier.
I’m still finalizing the details, but they only communicate over UART and are triggered by request, so I think I can manage them with multiplexers or smart UART routing.
Are the "sensors measuring" and "what I'm doing with the data" critical to solving the UART connection issue?
If it helps, I can definitely share more project context.
That one got me . Now I’m curious if there's actually a sensor out there for that… If I find one, I promise I’ll report back!
Thank you for sharing the code and test results — that's super helpful! It’s great to see a real-world example of the ESP32 working with multiple software serial ports using EspSoftwareSerial.
I’ll definitely give this a try with my setup. Since my sensors only respond when queried, this approach might work well for my needs.
Really appreciate the time you took to test and post this — cheers!