Projects / ESP-NOW remote button lamp

ESP-NOW remote button lamp

Beginner1.2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Wire the button to the first board

    GPIO4 and GND.

  2. ESP3218.3 mA

    Wire the LED to the second board

    GPIO18 through 220 ohms to GND.

  3. ESP32

    Upload the sender to board one

    The serial monitor stays quiet.

  4. ESP3218.3 mA

    Upload the receiver to board two

    It starts with the LED off.

  5. ESP3218.3 mA

    Press and hold the button

    The LED on the other board lights.

  6. ESP3218.3 mA

    Release it

    The LED goes out within a moment.

  7. ESP3218.3 mA

    Switch off the sender

    The LED stays off.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Sender board: button leg 1GPIO4Button input
Sender board: button leg 2GNDPressing joins GPIO4 to ground
Receiver board: LED long legGPIO18 through a 220 ohm resistorLED output
Receiver board: LED short legGNDReturn path
Both boardsUSB power from a computer or a power bankEach 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.

CheckExpected
Button pressedLED on at the other board
Button releasedLED off after a short delay
Sender unplugged while pressedLED goes off within half a second
Other roomWorks through one or two walls
Two receiversBoth 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 →

Ask Lark AI

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.