This tutorial will guide you step-by-step on how to set up two ESP32 microcontrollers and program them to communicate with each other. The guide covers everything from installation of necessary software to writing and uploading code for wireless communication.
Materials Required:
Two ESP32 microcontroller boards
Breadboard and jumper wires
USB cables to connect each ESP32 to your computer
Computer with Arduino IDE installed (or PlatformIO for more advanced users)
Optional sensors or peripherals (for adding functionality)
Pinout of the ESP32 (ESP32-WROOM-32D)
You may have a different ESP so PLEASE CHECK
Step 1: Wiring
Choose one esp32 as your transmitter and the other as your receiver, here are the diagrams for wiring and the physical pictures. Esp32 types can vary but the same pins are used.
Transmitter:
Push Button: Connect one terminal to Pin 4 and the other to Ground.
Potentiometer: Connect the power pin to 3.3V, the ground pin to Ground, and the signal (orange wire) to Pin 34.
(Note: You can modify the pins for the button and potentiometer in the code if needed.)
Receiver:
LED: Connect the positive lead to Pin 2 and the negative lead to Ground.
Servo: Connect the power pin to 3.3V, the ground pin to Ground, and the signal (orange wire) to Pin 13.
Step 2: Setting up esp32 on Arduino
If you're new to using the Esp32 with the arduino ide,
then you’ll need to download esp32 by Espressif
on your board manager, install it.
Step 3: Get Mac Address
The transmitter requires the mac address of the receiver esp32 in order to transmit data to it. To obtain the receiver's mac address, copy this code into the arduino ide and run it on the receiver esp32 to get its mac address.
You should get an output similar to this on the serial monitor (you may need to restart the esp32 to get the output):
#include <WiFi.h>
#include <esp_wifi.h>
void readMacAddress(){
uint8_t baseMac[6];
esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac);
if (ret == ESP_OK) {
Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
baseMac[0], baseMac[1], baseMac[2],
baseMac[3], baseMac[4], baseMac[5]);
} else {
Serial.println("Failed to read MAC address");
}
}
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.STA.begin();
Serial.print("[DEFAULT] ESP32 Board MAC Address: ");
readMacAddress();
}
void loop(){
}
Step 4: Transmitter Code
Replace the question marks (??) with your corresponding Mac Address value. You don't need to worry about the rest of the code unless you want to change the pins. Copy and Paste the code and upload it to the transmitter esp32.
Download the Transmitter code from HERE.
You should see data being sent on the serial monitor, it includes the potentiometer, button, and servo degree values:
Step 5: Receiver Code
In order to run the servo you need to download the
ESP32 Servo Library, you can find it directly in the
library manager. Install it.
Now, download the code from here. For the receiver. You can change the pins for the servo or led if you need to.
Step 6: Testing
Power both your esp32’s, you should be seeing data coming in from the receiver on the serial monitor:
Turning the potentiometer should move the servo and pressing the button should turn on the led: