IoT/ESP32 B.Tech/Diploma Beginner

ESP32 CYD with ESP-NOW: Control Multiple ESP32 Boards

Use ESP-NOW with the ESP32 CYD Board to control the GPIOs of multiple ESP32 boards. The CYD board acts like a remote control to send commands to other boards to control their GPIOs.

  • Suitable forB.Tech/Diploma IoT/ESP32 students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Learn how to use ESP-NOW with the ESP32 CYD Board (Cheap Yellow Display) to control the GPIOs of multiple ESP32 boards. The CYD board acts like a remote control to send commands to other boards to control their GPIOs. We’ll control two ESP32 boards, and two GPIOs from each one. This can be easily extended to control more ESP32 boards or more GPIOs.
New to the ESP32 Cheap Yellow Display?
Start here:
Getting Started with ESP32 Cheap Yellow Display Board – CYD (ESP32-2432S028R)
Table of Contents
Project Overview
Prerequisites
1) Preparing the Receiver Boards
2) ESP32 CYD ESP-NOW Controller/Sender Board
3) Demonstration
Project Overview
Here’s an overview of the project we’ll build.
In this project, the ESP32 CYD board will control two GPIOs from two other ESP32 boards.
The ESP32 CYD board will act as an ESP-NOW sender that sends data to control the GPIOs of other ESP32 boards. We’ll control GPIOs 2 and 4 on ESP32 #1, and GPIOs 20 and 21 on ESP32 #2.
The CYD board acts as an ESP-NOW sender, and the other boards act as ESP-NOW receivers.
The CYD sender (controller board) sends messages to a specific board by referring to its MAC address.
To control the boards, the CYD interface shows two tabs, one for each ESP32 board. Each tab has two toggle switches to control two GPIOs from each board.
New to ESP-NOW communication protocol?
Read this guide:
Getting Started with ESP-NOW (ESP32 with Arduino IDE)
Prerequisites
Before proceeding, make sure you follow the next prerequisites.
You must follow all steps, otherwise, your project will not work.
1) Parts Required
For this project, you need the following parts:
ESP32 Cheap Yellow Display Board
2x ESP32 boards of your choice (we’re using one
DOIT DevKIT V1 Board
, and one ESP32S3 Freenove ESP32-CAM)
4x LEDs
4x 220 Ohm resistors
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
2) Install ESP32 Boards in Arduino IDE
We’ll program the ESP32 using Arduino IDE. Make sure you have the ESP32 boards installed. Follow the next tutorial:
Installing ESP32 Board in Arduino IDE 2 (Windows, Mac OS X, Linux)
3) Get familiar with the ESP32 Cheap Yellow Display
The
ESP32-2432S028R
development board has become known in the maker community as the “
Cheap Yellow Display
” or CYD for short. This development board, whose main chip is an ESP32-WROOM-32 module, comes with a 2.8-inch TFT touchscreen LCD, a microSD card interface, an RGB LED, and all the required circuitry to program and apply power to the board.
If this is your first time using the ESP32 Cheap Yellow Display, make sure to follow our getting started guide:
Getting Started with ESP32 Cheap Yellow Display Board and LVGL
4) Install TFT and LVGL Libraries
LVGL
(Light and Versatile Graphics Library) is a free and open-source graphics library that provides a wide range of easy-to-use graphical elements for your microcontroller projects that require a graphical user interface (GUI).
Follow the next tutorial to install and configure the required libraries to use LVGL for the ESP32 Cheap Yellow Display using Arduino IDE.
Get started with LVGL using the ESP32 Cheap Yellow Display Board (ESP32-2432S028R)
1) Preparing the Receiver Boards
Getting the MAC Address of the ESP32 Boards
To communicate via ESP-NOW, you need to know the MAC address of your receiver boards. To get your boards’ MAC address, upload the following code to each of your boards.
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
#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(){

}
After uploading, open the Serial Monitor and reset the ESP32. Its MAC address will be printed. Save it because you’ll need it on the ESP32 CYD sender code.
Get the MAC address for all your receiver boards.
For example, in my case, I get:
ESP32 Receiver Board 1:
30:ae:a4:f6:7d:4c
ESP32 Receiver Board 2:
34:85:18:40:2f:cc
Wiring the Circuit
We’ll control two GPIOs on each ESP32 board. We’ll control GPIOs 2 and 4 on our ESP32 DOIT board, and GPIOs 20 and 21 on our ESP32S3. You can control any other GPIOs.
We’ll connect an LED to each GPIO we want to control.
ESP32 #1
ESP32 #2
GPIO 2
GPIO 20
GPIO 4
GPIO 21
Here’s an example diagram showing how to connect two LEDs to your board.
Code – ESP-NOW ESP32 Receiver Boards
Upload the following code to each of your receiver boards. This code will work for any GPIOs you want to control.
/*********
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*********/
#include <esp_now.h>
#include <WiFi.h>

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
int gpio;
bool state;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("Setting GPIO: ");
Serial.println(myData.gpio);
Serial.print("state to: ");
Serial.println(myData.state);
// Control GPIO
pinMode(myData.gpio, OUTPUT);
digitalWrite(myData.gpio, myData.state);
Serial.println();
}

void setup() {
// Initialize Serial Monitor
Serial.begin(115200);

// Initialize WIFI STA interface
WiFi.mode(WIFI_STA);

// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}

// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
}

void loop() {

}
How Does the Code Work?
Let’s take a quick look at how the receiver code works. Alternatively, you can
skip to the next section
Include Libraries
First, include the
esp_now.h
and the
WiFi.h
libraries (required to initialize the Wi-Fi station interface to use ESP-NOW).
#include <esp_now.h>
#include <WiFi.h>
Data Structure to Receive Data
Create a structure to receive the data. We call it
struct_message
. This structure should be the same as that defined in the sender sketch. The structure will contain the data received via ESP-NOW. The data contains the GPIO number that we want to control (
int gpio
) and its state (
bool state
).
typedef struct struct_message {
int gpio;
bool state;
} struct_message;
After creating the structure, create a
struct_message
variable called
myData
, where we’ll store the data r

Technologies used

ESP32ESP32-CAMESP8266ArduinoWiFiBLELCDArduino IDE

Hardware components

  • ESP32
  • ESP32-CAM
  • ESP8266
  • Arduino
  • SD Card

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.