Build it step by step
0 of 6 doneFind the MAC
Print the receiver's MAC address and note it for later.
Upload the receiver
Test it by holding a pin high on the relay line.
Upload the remote
Press button 1 and hear the relay click.
Test the failsafe
Switch off the remote and check the relay drops within half a second.
Use other buttons
Add actions for buttons 2 to 4 for lights or a robot.
Measure the delay
Compare the press and the click on a phone video at 120 frames per second.
How do you build an ESP-NOW remote control?
A handheld with buttons controls a relay on another ESP32 over ESP-NOW with very low delay and a failsafe. You need ESP32 DevKit V1 × 2, Tactile push button 6 mm × 4, Relay Module 5V and Li-Po battery 3.7 V 1000 mAh. It takes 6 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 4
Parts list
- Development BoardsBuyESP32 DevKit V1 × 2
- SwitchesBuy
- InterfacesBuyRelay Module 5V × 1
- BatteriesBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Remote: buttons 1 to 4 | ESP32 GPIO12, GPIO13, GPIO14, GPIO27 and GND | Inputs with pull-ups |
| Remote: LiPo battery | ESP32 board's battery connector or a 5 V USB bank | Portable power |
| Receiver: relay module IN | ESP32 GPIO26 | Relay control (active low module) |
| Receiver: relay module VCC, GND | ESP32 VIN (5V), GND | Power |
| Receiver: USB cable | ESP32 USB | Power |
Code
Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". (version 3.x of the ESP32 core for the receiver callback shown). The default here sends to the broadcast address so no pairing is needed; for a private link set the receiver's MAC address (print WiFi.macAddress() on it) and enable ESP-NOW encryption, since broadcast messages can be heard by any nearby ESP32. The relay switches only a low-voltage test load here; any mains load must be wired by a qualified electrician. If the link drops for half a second the relay turns off by itself.
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).
// ---- Remote sketch (ESP32 with the buttons) ----
#include <WiFi.h>
#include <esp_now.h>
uint8_t peer[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // broadcast; replace with the receiver's MAC to send to it alone
const byte BTN[4] = { 12, 13, 14, 27 };
uint8_t lastState = 255;
void setup() {
for (byte i = 0; i < 4; i++) pinMode(BTN[i], INPUT_PULLUP);
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_peer_info_t p = {};
memcpy(p.peer_addr, peer, 6); p.channel = 0; p.encrypt = false;
esp_now_add_peer(&p);
}
void loop() {
uint8_t s = 0;
for (byte i = 0; i < 4; i++) if (!digitalRead(BTN[i])) s |= 1 << i;
esp_now_send(peer, &s, 1); // send the button bits every 50 ms
delay(50);
}
/* ---- Receiver sketch (ESP32 with the relay), for Arduino ESP32 core 3.x ----
#include <WiFi.h>
#include <esp_now.h>
const byte RELAY = 26;
volatile unsigned long lastRx = 0;
volatile uint8_t buttons = 0;
void onData(const esp_now_recv_info_t *info, const uint8_t *data, int len) { if (len == 1) { buttons = data[0]; lastRx = millis(); } }
void setup() {
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH); // off
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_register_recv_cb(onData);
}
void loop() {
bool linkOk = millis() - lastRx < 500; // failsafe: relay off if the link drops
digitalWrite(RELAY, (linkOk && (buttons & 1)) ? LOW : HIGH);
delay(10);
}
*/Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Hold button 1 | Relay on |
| Release | Relay off |
| Remote switched off | Relay off within half a second |
| Range of 10 m indoors | Still works |
If it does not work
Relay never clicks
Check both are in station mode and that ESP-NOW starts without error.
Compile error on the callback
Use core 3.x, or change the callback arguments for 2.x.
Relay is inverted
Swap the HIGH and LOW writes.
Short range
Move away from metal and keep the antenna side clear.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the ESP-NOW remote control?
ESP32 DevKit V1 × 2, Tactile push button 6 mm × 4, Relay Module 5V and Li-Po battery 3.7 V 1000 mAh.
How long does the ESP-NOW remote control take to build?
About 60 minutes for a beginner maker, in 6 steps.
How do I know the ESP-NOW remote control works?
Hold button 1: Relay on. Release: Relay off. Remote switched off: Relay off within half a second.
Relay never clicks: what should I check?
Check both are in station mode and that ESP-NOW starts without error.
Compile error on the callback: what should I check?
Use core 3.x, or change the callback arguments for 2.x.
Relay is inverted: what should I check?
Swap the HIGH and LOW writes.
Short range: what should I check?
Move away from metal and keep the antenna side clear.
