Mobirise Website Builder

Networking and Communications



Board design

Mobirise Website Builder
Board A (Host)

In order to try a wireless connection, Board A used ESP32 C3 as its microcontroller and a push button to record the signal manually.

Mobirise Website Builder

Mobirise Website Builder
Board B (Receiver)

Following that, Board B used ESP32 S3 as its microcontroller and pins for LED as output device.

Mobirise Website Builder

Mobirise Website Builder
Fabrication

To make production faster, I merged two boards on the same piece by importing files one after the other. After that, I soldered all the components on it quickly since I intentionally left bigger footage for each joint on my PCBs.

Mobirise Website Builder

Mobirise Website Builder

ESP-NOW Wireless Communication

Mobirise Website Builder
Environment

The two boards were both connected to the same Mac's two USB-c ports to get power and program. On the left is the ESP32 C3 (host) and the right is ESP32 S3 (receiver.)

Mobirise Website Builder
MAC Address

The ESP series is frustrating when it comes to these weird bugs. I need to press the reset button every 5 minutes in order to program it well. Finally, I got the MAC Address of the S3 and it is ready for networking.

Mobirise Website Builder
Connected!

The programming was done in one Mac by sending the data on both sides. Once those boards recorded the data input, I will start pushing the button and see if it reacts on the other side.

Code A: ESP32 C3 (Host)

#include
#include

// Pin Definitions
#define BUTTON_PIN 4 // GPIO 3 for the button

// Message Structure
typedef struct message {
bool buttonPressed; // Simple boolean message
} message;

message myMessage;

// Define Receiver MAC Address (Replace with Actual S3 MAC)
uint8_t receiverAddress[] = {0x24, 0x58, 0x7C, 0xE3, 0xFF, 0xB8}; // Example MAC

void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Enable Internal Pull-Up

// Initialize Wi-Fi
WiFi.mode(WIFI_STA);
delay(1000);
Serial.println("test");
// Initialize ESP-NOW
if (esp_now_init() == ESP_OK) {
Serial.println("ESP-NOW Init success");
} else {
Serial.println("ESP-NOW Init fail");
return;
}

// Register the Receiver as a Peer
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, receiverAddress, 6);
peerInfo.channel = 0; // Default Wi-Fi Channel
peerInfo.encrypt = false; // No Encryption

if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to add peer");
return;
}
}

void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // Button Pressed
myMessage.buttonPressed = true; // Send Button Pressed = true
Serial.println("pressed");
esp_err_t result = esp_now_send(receiverAddress, (uint8_t *)&myMessage, sizeof(myMessage));

if (result == ESP_OK) {
Serial.println("Message Sent: Button Pressed");
} else {
Serial.println("Message Failed to Send");
}

delay(500); // Debounce delay
}
}

Code B: ESP32 S3 (Receiver)

#include
#include

// Pin Definitions
#define LED_PIN 4 // GPIO 4 for the LED

// Define the message structure
typedef struct message {
bool buttonPressed; // Button press status
} message;

message myMessage;

// ESP-NOW Callback Function for Received Data
void messageReceived(const uint8_t* mac, const uint8_t* incomingData, int len) {
memcpy(&myMessage, incomingData, sizeof(myMessage));

// Print to Serial Monitor when button is pressed
if (myMessage.buttonPressed) {
Serial.println("Button Press Detected from ESP32-C3");
digitalWrite(LED_PIN, HIGH); // Turn ON the LED
delay(500); // Keep LED ON for 0.5 seconds
digitalWrite(LED_PIN, LOW); // Turn OFF the LED
}
}

void setup() {
// Initialize Serial Monitor and LED
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // Start with LED OFF

// Initialize Wi-Fi
WiFi.mode(WIFI_STA);
delay(1000);
Serial.println("test");

// Initialize ESP-NOW
if (esp_now_init() == ESP_OK) {
Serial.println("ESP-NOW Initialization Successful");
} else {
Serial.println("ESP-NOW Initialization Failed");
return;
}

// Register Callback for Receiving Messages
esp_now_register_recv_cb(messageReceived);
}

void loop() {
// No continuous tasks needed; everything happens in the callback
}

ESP's button is talking to another
ESP's LED through
ESP-NOW wireless communication

Project Index

AI Website Generator