How to Exchange Data between Arduino and ESP32 using Serial Communication?

Serial communication

Serial communication is a process of data transmission sequentially through a communication channel or bus. In serial communication, the data is sent one bit at a time. The serial transmission can be perform using only a single wire and not more than four wires. Serial communication is also known as UART or USART communication.

Serial communication is also known as UART or USART communication
Serial Communication

Arduino Serial Pins:

In every Arduino board, there is at least one serial pin available. The pins are named TX and RX pins. TX stands for transmitting, RX stands for receive. 

In Arduino Uno, there a one TX and one RX pin available. The digital pins 0 and 1 used as serial pins. 

In Arduino Mega, there are additional three serial pins. That means there is a total of four serial communication pins available in Arduino Mega.

ESP32 Serial pins:

ESP32 boards also come with TX and RX pins. Depending on the model, the number of serial pins may vary.

Communication between Arduino and ESP32:

To establish serial communication between Arduino and ESP32, we can cross-connect TX and RX pins of Arduino with ESP32. There should be a common ground. So, we will connect Arduino GND Pin with ESP32 GND Pin

Serial Communication between an ESP32 and an Arduino
Serial Communication between an ESP32 and an Arduino

To exchange data between ESP32 and Arduino, the baud rate should be the same in both programs.

Exchange Data between Arduino and ESP32 using Serial Communication
Exchange Data between Arduino and ESP32 using Serial Communication

In this tutorial, we are going to use Arduino UNO and ESP32 dev module. We are going to use Arduino d1 as TX pin and d0 as RX. In ESP32, GPIO 16 as RX pin and GPIO 17 as TX pin which is marked as RX1 and TX1 pin in ESP32 board.

Arduino Code for URT communication:

// this sample code provided by www.programmingboss.com
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("Hello Boss");
  delay(1500);
}code-box

ESP32 Code for URT communication:

// this sample code provided by www.programmingboss.com
#define RXp2 16
#define TXp2 17
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXp2, TXp2);
}
void loop() {
    Serial.println("Message Received: ");
    Serial.println(Serial2.readString());
}code-box

Video Instruction and demonstration

Summary

Among different data communication, Serial data communication is a very popular communication protocol. Data communication between ESP32 and Arduino can be done by serial communication. Most of the microcontrollers can transmit and receive data between them using UART communication.

3/Post a Comment/Comments

  1. Thanks for sharing.
    What about voltages?
    If I remember well, Arduino is working at 5V, while ESP32 is working at 3.3V.
    I think you are risking to burn your ESP32.
    Wouldn't be better to use a bi-directional voltage level shifter module?
    This, for example: https://www.sparkfun.com/products/12009

    Thanks
    Daniele

    ReplyDelete
  2. es grande maravilloso genial diferentes comunicaciones de datos, la comunicación de datos en serie es un protocolo de comunicación muy popular. La comunicación de datos entre ESP32

    ReplyDelete
  3. There are so many sites, books, and other options for learning programming that it can be overwhelming for even the most determined learners. JetBrains Academy removes this issue by providing a holistic approach to learning with a full hands-on programming experience. It allows you to study theory and immediately put it into practice as you create applications step by step. Whether you want to learn Java, Python, Kotlin, or frontend development, you’ll get the advantage of:

    Numerous projects that can strengthen your GitHub profile.
    Personalized study plan to keep you on track and focused on your goal.
    Integration with JetBrains IDEs to learn programming in a professional development environment.
    Community of 330,000+ learners that are always there for you whenever you are stuck or need motivation.

    ReplyDelete

Post a Comment