Build it step by step
0 of 7 doneWire the button to the first board
GPIO4 and GND.
Wire the LED to the second board
GPIO18 through 220 ohms to GND.
Upload the sender to board one
The serial monitor stays quiet.
Upload the receiver to board two
It starts with the LED off.
Press and hold the button
The LED on the other board lights.
Release it
The LED goes out within a moment.
Switch off the sender
The LED stays off.
How do you build an ESP-NOW remote button lamp?
Press a button on one ESP32 board and an LED lights on a second board across the room, with no router and no Wi-Fi password. ESP-NOW sends tiny messages straight between boards. You need ESP32 DevKit V1 × 2, Tactile push button 6 mm, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 70 minutes.
- Level
- Beginner
- Time
- About 70 min
- Parts
- 6
Parts list
- Development BoardsBuyESP32 DevKit V1 × 2
- SwitchesBuy
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Sender board: button leg 1 | GPIO4 | Button input |
| Sender board: button leg 2 | GND | Pressing joins GPIO4 to ground |
| Receiver board: LED long leg | GPIO18 through a 220 ohm resistor | LED output |
| Receiver board: LED short leg | GND | Return path |
| Both boards | USB power from a computer or a power bank | Each board has its own USB lead |
Code
The file holds two separate sketches, one for each board, so copy each into its own Arduino window. ESP-NOW is a radio feature of the ESP32 that sends short messages straight from one board to another, without a router. To keep things simple the sender broadcasts to every board in range, so you do not need to look up any addresses. It repeats the button state ten times a second, so one lost message does not leave the lamp stuck, and the receiver switches the LED off if it has heard nothing for half a second. Because a broadcast is open to any board nearby, treat this as a lamp toy and never as a lock or a safety switch. The receiver callback uses the newer core 3 form, and a comment shows the older form if you use core 2. Once it works, try walking to another room and see how far it goes, and then think about what you would need to send a number instead of a single on or off.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// ===== SENDER (upload to board one) =====
#include <WiFi.h>
#include <esp_now.h>
const uint8_t BUTTON_PIN = 4;
uint8_t broadcastAddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // anyone in range
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW failed to start"); return; }
esp_now_peer_info_t peer = {};
memcpy(peer.peer_addr, broadcastAddr, 6);
peer.channel = 0;
peer.encrypt = false;
esp_now_add_peer(&peer);
}
void loop() {
uint8_t state = (digitalRead(BUTTON_PIN) == LOW) ? 1 : 0; // 1 while pressed
esp_now_send(broadcastAddr, &state, 1); // repeat the state, so a lost message heals
delay(100);
}
/* ===== RECEIVER (upload to board two, as a separate sketch) =====
Copy everything below into a new sketch for the second board. */
/*
#include <WiFi.h>
#include <esp_now.h>
const uint8_t LED_PIN = 18;
unsigned long lastHeard = 0;
// Core 3.x callback. On core 2.x use: void onReceive(const uint8_t *mac, const uint8_t *data, int len)
void onReceive(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
if (len >= 1) {
digitalWrite(LED_PIN, data[0] ? HIGH : LOW);
lastHeard = millis();
}
}
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW failed to start"); return; }
esp_now_register_recv_cb(onReceive);
}
void loop() {
if (millis() - lastHeard > 500) digitalWrite(LED_PIN, LOW); // sender gone, switch off
delay(20);
}
*/Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Button pressed | LED on at the other board |
| Button released | LED off after a short delay |
| Sender unplugged while pressed | LED goes off within half a second |
| Other room | Works through one or two walls |
| Two receivers | Both LEDs follow the button |
If it does not work
Compile error about the callback
Use the core 2.x callback form shown in the comment.
LED never lights
Check the LED direction and the pin number.
Works only when close
Move the boards away from metal and keep the antenna end clear.
Button seems reversed
Check it goes to GND, not 3V3.
Upload fails
Hold the BOOT button while it connects.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the ESP-NOW remote button lamp?
ESP32 DevKit V1 × 2, Tactile push button 6 mm, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the ESP-NOW remote button lamp take to build?
About 70 minutes for a beginner maker, in 7 steps.
How do I know the ESP-NOW remote button lamp works?
Button pressed: LED on at the other board. Button released: LED off after a short delay. Sender unplugged while pressed: LED goes off within half a second.
Compile error about the callback: what should I check?
Use the core 2.x callback form shown in the comment.
LED never lights: what should I check?
Check the LED direction and the pin number.
Works only when close: what should I check?
Move the boards away from metal and keep the antenna end clear.
Button seems reversed: what should I check?
Check it goes to GND, not 3V3.
