Serial communication transmits data one bit at a time, sequentially, over a communication channel or computer bus. In the context of Arduino and ESP32, serial communication refers to the transmission of data serially over a single wire or communication line rather than in parallel over multiple wires.
![]() |
Serial communication between Arduino and ESP32 CAM |
The two main types of serial communication are commonly used with Arduino and ESP32:
- Asynchronous serial communication: Data is transmitted without a clock signal in asynchronous serial communication. Instead, each data frame's start and stop bits are used to synchronise the communication. Asynchronous serial communication is commonly used for communication over long distances, such as with modems.
- Synchronous serial communication: In synchronous serial communication, a clock signal synchronises data transmission. It is typically faster than asynchronous serial communication and is often used for communication between devices on a single circuit board or over short distances.
Both Arduino and ESP32 support asynchronous and synchronous serial communication. The Arduino Uno has a single hardware serial port (UART), while the ESP32 has multiple hardware UARTs. Arduino and ESP32 also support software-based serial communication using libraries such as SoftwareSerial (for Arduino) and HardwareSerial (for ESP32).
Circuit diagram of Serial communication between Arduino and ESP32:
The voltage levels of the Arduino Uno and ESP32 are not compatible with direct communication without some form of voltage level shifting. The Arduino Uno operates at 5 volts, while the ESP32 operates at 3.3 volts. If you connect the RX and TX pins of the Arduino Uno and ESP32 directly, you could damage the ESP32 due to the higher voltage.
One way to safely establish serial communication between the Arduino Uno and ESP32 is to use a voltage divider circuit to step down the voltage from the Arduino Uno to a level compatible with the ESP32. A voltage divider is a simple circuit that consists of two resistors connected in series. The voltage at the centre point between the two resistors is given by:
Vout = Vin * R2 / (R1 + R2)
![]() |
Voltage divider |
In this circuit, R1 is a 10K ohm resistor, and R2 is a 4.7K ohm resistor. This results in a voltage of 3.3 volts at the centre point between the two resistors. This voltage is compatible with the ESP32 and can be used to establish serial communication between the Arduino Uno and ESP32.
Remember that you will need to connect the TX pin of the Arduino Uno to the TX pin of the ESP32, similarly, using a voltage divider to step down the voltage from the ESP32 to a level compatible with the Arduino Uno.
After implementing the voltage divider between Arduino TX and ESP32 RX, the circuit will look like the following:
![]() |
Arduino ESP32 Serial Communication with Voltage Divider |
Code for ESP32 CAM:
Here is an example of how you can establish serial communication between an Arduino Uno and an ESP32-CAM:
#include <Arduino.h> void setup() { Serial.begin(115200); // Initialize the hardware serial port } void loop() { if (Serial.available()) { char data = Serial.read(); // Process the received data here // Echo back the data to the serial port Serial.write(data); } }
In the ESP32-CAM code, we use the built-in Serial object to communicate with the Arduino Uno. On the Arduino Uno side, we create a SoftwareSerial object mySerial
and initialize it with the RX and TX pins (in this case, pins 2 and 3). The mySerial
object is used to communicate with the ESP32-CAM.
Code for Arduino
In Arduino, upload the following code:
#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX pins for SoftwareSerial void setup() { Serial.begin(9600); // Initialize the hardware serial port for debugging mySerial.begin(115200); // Initialize the software serial port } void loop() { if (mySerial.available()) { char data = mySerial.read(); // Process the received data here // Echo back the data to the serial port mySerial.write(data); } }
Make sure you have the SoftwareSerial library installed on your Arduino IDE. You can install it by going to "Sketch → Include Library → Manage Libraries" and searching for "SoftwareSerial."
It's important to note that the baud rate, the speed at which the data is transmitted, must be the same on both the Arduino and the ESP32 CAM for the communication to work correctly.
Video documentation on Arduino and ESP32 Serial Communication
Recap
This article is a comprehensive guide for establishing serial communication between an Arduino and an ESP32-CAM module. It offers detailed example code, emphasises the utilisation of the SoftwareSerial library for the Arduino, and underscores the significance of matching baud rates to ensure seamless data exchange. By following the step-by-step instructions outlined in the article, you can establish reliable and effective serial communication, thus unlocking the full potential of Arduino-ESP32-CAM projects.