Your ESP32 has a hidden superpower: ESP-NOW. It lets one ESP32 send data straight to another ESP32 using the built-in Wi-Fi radio, without a router, without a Wi-Fi password and without internet. In this CircuitMagic tutorial you will make two ESP32 DevKit boards talk: press a button on Board A and an LED lights up on Board B. Then we will make it two-way and show how to broadcast to many boards.

What is ESP-NOW?
ESP-NOW is a connectionless communication protocol made by Espressif, the company behind the ESP32. Instead of joining a Wi-Fi network, each board sends small packets directly to another board’s MAC address (its unique hardware address). It is already inside the ESP32 chip, so there is nothing extra to buy or install.
- No router or internet: boards talk directly to each other.
- Fast and light: no Wi-Fi connection to set up, so messages go out almost instantly. Great for battery projects that wake up, send and sleep.
- Small messages: up to 250 bytes per message is supported on every ESP-NOW device. (Newer ESP-IDF versions add ESP-NOW v2.0 with up to 1470 bytes, but older devices cannot receive those, so 250 bytes is the safe size.)
- Up to 20 paired peers: a board can store up to 20 peers for direct (unicast) messages, fewer if you turn on encryption. Broadcast messages have no peer limit.
- Delivery report: for direct messages the sender gets a callback telling you if the other board’s radio acknowledged the packet.
Good for: wireless buttons and remotes, sensor nodes that report to a hub, robot controllers, doorbells, and lights that switch together. Not ideal for: large files, video, or talking to a phone or website (use normal Wi-Fi or Bluetooth for those).
Required components
- 2 ร ESP32 DevKit boards (any ESP32 with Wi-Fi works, including ESP32-S3 and ESP32-C3)
- 1 ร push button
- 1 ร LED and 1 ร 220 ฮฉ resistor (optional: many ESP32 DevKit V1 boards already have an LED on GPIO2)
- Breadboard, jumper wires and two USB data cables
Pin connections
Unplug USB power before wiring. The button uses the ESP32’s internal pull-up resistor, so it needs only two wires. Always check your board’s printed pin labels.
| Board | ESP32 pin | Connect to |
|---|---|---|
| Board A (sender) | GPIO4 | One leg of the push button |
| Board A (sender) | GND | Other leg of the push button |
| Board B (receiver) | GPIO2 | 220 ฮฉ resistor โ LED long leg (anode) |
| Board B (receiver) | GND | LED short leg (cathode) |
For the two-way version later in this tutorial, wire a button on GPIO4 and an LED on GPIO2 on both boards.
Arduino IDE setup
Install the esp32 by Espressif Systems board package (version 3.x) from Boards Manager, select ESP32 Dev Module (or your board) and the right port. No extra library is needed: WiFi.h and esp_now.h come with the board package.
Heads up: many older ESP-NOW tutorials no longer compile. In Arduino-ESP32 3.x the receive callback takes an esp_now_recv_info_t pointer, and from version 3.3 the send callback takes a wifi_tx_info_t pointer instead of a MAC address. The code below handles both, so it works on 3.0 and newer.
Step 1: Find each board’s MAC address
ESP-NOW sends to a MAC address, so first find out the MAC address of each board. Upload this sketch to each board, open Serial Monitor at 115200 baud, and write the address down. Put a sticker labelled “A” and “B” on the boards so you don’t mix them up.
#include <WiFi.h>
#include <esp_mac.h>
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.mode(WIFI_STA);
uint8_t mac[6];
esp_read_mac(mac, ESP_MAC_WIFI_STA);
Serial.printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Serial.printf("Copy into code: {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
void loop() {
}
You will see something like MAC address: 30:AE:A4:9B:5E:D8. Your numbers will be different. The second line is already formatted to paste into the next sketch.
Step 2: Sender code (Board A)
Paste Board B’s MAC address into receiverMac, then upload to Board A. It sends a message every time the button changes, plus a “heartbeat” every 2 seconds.
#include <WiFi.h>
#include <esp_now.h>
// Board B's MAC address (from Step 1)
uint8_t receiverMac[] = {0x30, 0xAE, 0xA4, 0x9B, 0x5E, 0xD8};
const int BUTTON_PIN = 4; // button between GPIO4 and GND
// The message. Must be IDENTICAL on sender and receiver.
typedef struct {
uint32_t counter;
bool buttonPressed;
float uptimeSeconds;
} Message;
Message msg;
bool lastPressed = false;
unsigned long lastSend = 0;
// Runs after each send. The signature changed in Arduino-ESP32 3.3.
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 3, 0)
void onDataSent(const wifi_tx_info_t *info, esp_now_send_status_t status) {
#else
void onDataSent(const uint8_t *mac, esp_now_send_status_t status) {
#endif
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivered" : "Delivery failed");
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
WiFi.mode(WIFI_STA); // radio on, no network needed
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
while (true) delay(1000);
}
esp_now_register_send_cb(onDataSent);
esp_now_peer_info_t peer = {};
memcpy(peer.peer_addr, receiverMac, 6);
peer.channel = 0; // 0 = use the current Wi-Fi channel
peer.encrypt = false;
if (esp_now_add_peer(&peer) != ESP_OK) {
Serial.println("Failed to add peer");
while (true) delay(1000);
}
Serial.println("Sender ready");
}
void loop() {
bool pressed = digitalRead(BUTTON_PIN) == LOW;
if (pressed != lastPressed || millis() - lastSend > 2000) {
lastPressed = pressed;
lastSend = millis();
msg.counter++;
msg.buttonPressed = pressed;
msg.uptimeSeconds = millis() / 1000.0;
esp_err_t result = esp_now_send(receiverMac, (uint8_t *)&msg, sizeof(msg));
Serial.printf("Sending #%lu (button %s): %s\n",
(unsigned long)msg.counter, pressed ? "DOWN" : "UP",
result == ESP_OK ? "queued" : "error");
}
delay(20); // simple debounce
}
Step 3: Receiver code (Board B)
Upload this to Board B. It does not need the sender’s MAC address: any board can send to it. The LED follows Board A’s button.
#include <WiFi.h>
#include <esp_now.h>
const int LED_PIN = 2;
// Must match the sender exactly
typedef struct {
uint32_t counter;
bool buttonPressed;
float uptimeSeconds;
} Message;
Message incoming;
uint8_t senderMac[6];
volatile bool newMessage = false;
// Runs when a message arrives. Keep it short: just copy the data.
void onDataRecv(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
if (len != sizeof(Message)) return; // ignore unexpected packets
memcpy(&incoming, data, sizeof(Message));
memcpy(senderMac, info->src_addr, 6);
newMessage = true;
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
while (true) delay(1000);
}
esp_now_register_recv_cb(onDataRecv);
Serial.println("Receiver ready, waiting for data...");
}
void loop() {
if (newMessage) {
newMessage = false;
digitalWrite(LED_PIN, incoming.buttonPressed ? HIGH : LOW);
Serial.printf("From %02X:%02X:%02X:%02X:%02X:%02X #%lu button=%s uptime=%.1fs\n",
senderMac[0], senderMac[1], senderMac[2],
senderMac[3], senderMac[4], senderMac[5],
(unsigned long)incoming.counter,
incoming.buttonPressed ? "DOWN" : "UP",
incoming.uptimeSeconds);
}
}
Expected output
Power both boards and open Serial Monitor for each (two Arduino IDE windows, or one board on a phone charger). Press the button on Board A and the LED on Board B lights up instantly.
// Board A (sender)
Sending #12 (button DOWN): queued
Delivered
// Board B (receiver)
From 30:AE:A4:1C:7F:02 #12 button=DOWN uptime=24.3s
How the code works
WiFi.mode(WIFI_STA)switches the radio on. ESP-NOW needs the Wi-Fi radio running, but it does not connect to any network.esp_now_init()starts ESP-NOW.esp_now_add_peer()(sender only) saves the receiver’s MAC address so you can send to it.esp_now_send()sends the bytes of theMessagestruct.- The send callback reports whether the receiver’s radio acknowledged the packet. The receive callback runs when data arrives. Callbacks run in the Wi-Fi task, so they only copy data and set a flag; the real work happens in
loop().
Using a struct keeps the data organised. Add or remove fields as you like, but keep the struct identical on both boards and under 250 bytes.
Make it two-way
Every ESP32 can send and receive at the same time. Upload this one sketch to both boards. The only difference: on each board, set peerMac to the other board’s MAC address. Now each button controls the LED on the other board.
#include <WiFi.h>
#include <esp_now.h>
// The OTHER board's MAC address (different on each board!)
uint8_t peerMac[] = {0x30, 0xAE, 0xA4, 0x9B, 0x5E, 0xD8};
const int BUTTON_PIN = 4;
const int LED_PIN = 2;
typedef struct {
uint32_t counter;
bool buttonPressed;
} Message;
Message outgoing;
Message incoming;
volatile bool newMessage = false;
bool lastPressed = false;
unsigned long lastSend = 0;
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 3, 0)
void onDataSent(const wifi_tx_info_t *info, esp_now_send_status_t status) {
#else
void onDataSent(const uint8_t *mac, esp_now_send_status_t status) {
#endif
if (status != ESP_NOW_SEND_SUCCESS) Serial.println("Delivery failed");
}
void onDataRecv(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
if (len != sizeof(Message)) return;
memcpy(&incoming, data, sizeof(Message));
newMessage = true;
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
while (true) delay(1000);
}
esp_now_register_send_cb(onDataSent);
esp_now_register_recv_cb(onDataRecv);
esp_now_peer_info_t peer = {};
memcpy(peer.peer_addr, peerMac, 6);
peer.channel = 0;
peer.encrypt = false;
esp_now_add_peer(&peer);
Serial.println("Two-way ESP-NOW ready");
}
void loop() {
// Send when our button changes (plus a heartbeat every 2 s)
bool pressed = digitalRead(BUTTON_PIN) == LOW;
if (pressed != lastPressed || millis() - lastSend > 2000) {
lastPressed = pressed;
lastSend = millis();
outgoing.counter++;
outgoing.buttonPressed = pressed;
esp_now_send(peerMac, (uint8_t *)&outgoing, sizeof(outgoing));
}
// Show the other board's button on our LED
if (newMessage) {
newMessage = false;
digitalWrite(LED_PIN, incoming.buttonPressed ? HIGH : LOW);
Serial.printf("Peer #%lu button=%s\n", (unsigned long)incoming.counter,
incoming.buttonPressed ? "DOWN" : "UP");
}
delay(20);
}
Send to every board at once (broadcast)
Want one remote to control many boards without collecting all their MAC addresses? Send to the special broadcast address FF:FF:FF:FF:FF:FF. Every ESP-NOW board in range on the same channel receives it, and the receiver code above works unchanged. In the sender sketch, replace the MAC line with:
uint8_t receiverMac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Broadcast packets are not acknowledged, so “Delivered” only means the packet left the radio, not that someone received it. Broadcast also cannot be encrypted.
Troubleshooting
- Compile error about “invalid conversion” in
esp_now_register_send_cboresp_now_register_recv_cb: you are using callback code from an older tutorial. Use the callbacks from this page, and update the esp32 board package to 3.x. - “Delivery failed” every time: check that the MAC address in the sender is Board B’s (not Board A’s), that Board B is powered and running the receiver sketch, and that both boards are on the same Wi-Fi channel.
- Works until one board connects to your home Wi-Fi: joining a router moves that board to the router’s channel. ESP-NOW peers must be on the same channel, so either connect both boards to the same router or set the other board to the router’s channel.
- Receiver prints nothing: make sure the
Messagestruct is identical on both boards. The receiver ignores packets with a different size. - LED never lights: check the LED direction (long leg towards the resistor and GPIO2). Some boards use a different pin for the built-in LED.
- Short range or dropouts: keep the antenna end of the board clear of metal and your hand, and avoid placing the boards right next to a Wi-Fi router.
Try next
Replace the button with a real sensor (temperature, motion or soil moisture) and build a wireless sensor node. Add deep sleep so a battery board wakes up, sends one ESP-NOW message and goes back to sleep. Or make a hub board that collects data from up to 20 nodes. See more CircuitMagic electronics projects for related ESP32 tutorials.









