Fix “SoftwareSerial.h: No such file or directory” on ESP32
The ESP32 core has no SoftwareSerial — it doesn’t need one. Use a spare hardware UART: HardwareSerial gps(2); gps.begin(9600, SERIAL_8N1, RX, TX);
Community draft — report a mistake
What you see
GpsTracker.ino:1:10: fatal error: SoftwareSerial.h: No such file or directory
1 | #include <SoftwareSerial.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: SoftwareSerial.h: No such file or directoryGpsTracker.ino:1:10: fatal error: SoftwareSerial.h: No such file or directory
1 | #include <SoftwareSerial.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: SoftwareSerial.h: No such file or directory
SoftwareSerial exists on the Uno because the ATmega328P has only one UART. The ESP32 has three hardware UARTs and can connect them to almost any pin, so its core doesn’t include SoftwareSerial at all.
HardwareSerial gps(2); // UART2
void setup() {
Serial.begin(115200);
gps.begin(9600, SERIAL_8N1, 16, 17); // baud, format, RX pin, TX pin
}
void loop() {
while (gps.available()) Serial.write(gps.read());
}Quick fix — try in order
- 1
Use a hardware UART instead
Replace
SoftwareSerial gps(16, 17);withHardwareSerial gps(2);and in setup()gps.begin(9600, SERIAL_8N1, 16, 17);— RX pin first, then TX. - 2
Keep the rest of the code
gps.available(),gps.read(),gps.print()work the same, so TinyGPS++, SIM800L and HC-05 code needs no other change. - 3
Pick free pins
The ESP32 can route UART2 to almost any GPIO. 16/17 are common on DevKit V1; avoid 6–11 and use 34–39 only for RX.
- 4
Mind the voltage
The ESP32 is 3.3 V. Feeding a 5 V module’s TX straight into an ESP32 RX pin needs a divider (e.g. 1 kΩ / 2 kΩ).
Why it happens
Why no SoftwareSerial?
The ESP32 has three hardware UARTs (UART0 is USB/Serial). With pin routing, two are free for modules — more reliable than bit-banging. A third-party EspSoftwareSerial library exists if you truly need a fourth port.
Serial2 already exists
On the classic ESP32 you can use the predefined Serial2: Serial2.begin(9600, SERIAL_8N1, 16, 17);.
ESP32-C3 has fewer UARTs
It has two: UART0 (often free when USB CDC is used for Serial) and UART1. Use HardwareSerial gps(1);.
Board-specific notes
ESP32: GPS wiring with a hardware UART: NEO-6M GPS; GSM: SIM800L (needs its own 4 V supply).
ESP8266: The ESP8266 core does ship SoftwareSerial, because the ESP8266 has only one full UART.
Did this fix it?
Thanks — that helps us keep this page right.