Hugo Richmond
Project write-up

ESP32 Smart Home

Servo light switches, a servo door lock and a keypad, five ESP32 boards talking over ESP-NOW and controlled from my phone. No cloud, no smart bulbs.

The project in 3 minutes: planning, printing, wiring and the whole system working.
5 ESP32sone hub, four nodes
ESP-NOWdirect radio packets, no router
2 bytesper command: device + action
3 minto enter the code after a remote unlock
01

What it does

I wanted to control my apartment's lights and front door from my phone without replacing anything. Instead of smart bulbs and a smart lock, small servos press the existing light switches and turn the existing deadbolt.

  • Phone control: a web page with on/off buttons for the bed light and the kitchen light, and unlock/lock for the door.
  • Remote unlock: one button unlocks the door for someone, turns both lights on and starts a 3-minute countdown on the keypad. If the right code isn't entered in time, the buzzer sounds.
  • Keypad by the door: D unlocks when leaving and re-locks 10 seconds later, B and C toggle the lights, and during a countdown it takes the code.
Everything on the bench: the light-switch servos, keypad, LCD and the control page.
The phone control page next to a mounted switch.
02

How it works

I planned it on paper first: one hub that speaks both Wi-Fi and ESP-NOW, and four nodes that are "dumb actuators". The hub is a translator: HTTP from the phone comes in, ESP-NOW packets go out. ESP-NOW sends raw packets between ESP32 boards by MAC address, with no router and no IP addresses involved, so a command reaches a servo almost instantly.

The phone and Project Qwen talk HTTP to the ESP32-S3 hub, which sends ESP-NOW packets to two light-switch nodes, the door-lock node and the keypad node Phonecontrol web page Project Qwenrobot, joined later HTTP / Wi-Fi HTTP: lights, door, events Hub · ESP32-S3 Wi-Fi web server HTTP in → ESP-NOW out keypad event log for Qwen ESP-NOW Node 1 · bed lightESP32-C3 + servo Node 2 · kitchen lightESP32-C3 + servo Node 3 · door lockESP32-C3 + MG996R Node 4 · keypadESP32 + 4×4 keypad16×2 LCD + buzzer the keypad also talks back: events to the hub, commands to the other nodes
Figure 1. System layout. Every command is the same tiny packet; the node checks the device number and moves its servo.

Every command is the same two-byte packet. A node ignores anything not addressed to its device number:

typedef struct {
  uint8_t deviceId;   // 1, 2, 3 = servos, 99 = keypad event
  uint8_t action;     // 0 = OFF / LOCK, 1 = ON / UNLOCK
} Command;

if (cmd.deviceId != DEVICE_ID) return;              // not for me
servo.write(cmd.action == 1 ? ON_POS : OFF_POS);   // e.g. 45 deg

Remote unlock is a short sequence on the hub:

void s3on() {
  sendCommand(NODE3_MAC, 3, 1);                   // unlock the door
  delay(1000);
  sendCommand(NODE1_MAC, 1, 1);                   // bed light on
  sendCommand(NODE2_MAC, 2, 1);                   // kitchen light on
  sendCommand(KEYPAD_MAC, 99, KP_REMOTE_UNLOCK);  // start countdown
}
03

Hardware

NodeBoardParts
HubESP32-S3 DevKitWi-Fi web server and ESP-NOW
1 · bed lightESP32-C3servo on a 3D-printed switch-plate mount
2 · kitchen lightESP32-C3servo on a 3D-printed switch-plate mount
3 · door lockESP32-C3MG996R servo in a printed mount that grips the deadbolt's thumb-turn
4 · keypadESP32 DevKit4×4 keypad, 16×2 I²C LCD, buzzer, printed enclosure
04

Design and build

I designed the mounts in CAD and 3D-printed them. The door-lock mount is a round base with four prongs that grip the deadbolt's thumb-turn, so the servo turns the existing lock. The light switches get a plate that holds a small servo right next to the switch lever.

The plan: components, boards and the "hub as translator" idea.
Door-lock mount in Fusion 360.
Printing the mount.
Door lock: MG996R in the printed mount.
Light switch: servo on the switch plate.
Keypad and LCD in their enclosure.
An ESP32-C3 node being wired up.
05

Making it reliable

When I later connected the keypad to my robot, its events sometimes never reached the hub. Two causes, two fixes:

  • Lost broadcasts. ESP-NOW broadcasts aren't acknowledged, so one dropped packet meant a missed event. Keypad events now go to the hub as unicast, which the radio acknowledges and retries, and each event is sent three times with a sequence number so the hub can drop the duplicates.
  • A sleepy hub. With Wi-Fi power saving on (the default), the hub's radio dozed between beacons and missed packets that arrived meanwhile. Turning it off fixed it: WiFi.setSleep(false).
void sendHubEvent(uint8_t event) {
  HubEvent ev = { 99, event, ++hubEventSeq };     // one seq for all copies
  for (int i = 0; i < HUB_EVENT_REPEATS; i++) {   // 3 acknowledged unicasts
    esp_now_send(HUB_MAC, (uint8_t*)&ev, sizeof(ev));
    delay(20);
  }
}

One more gotcha: ESP-NOW only works when every board is on the same Wi-Fi channel as the hub's router, since the hub has to stay on that channel to serve the web page.

06

Working with Project Qwen

When I built my home robot, Project Qwen, I connected it to this system instead of starting over. The hub gained a few HTTP routes for the robot (door and lights on their own, cancelling the countdown) and a small event log the robot polls. Now pressing D on the way out arms Qwen's security mode, Qwen turns the lights on when it sees an intruder, and after a remote unlock it locks the door again once it recognizes my face.

07

What I'd improve

  • Security: the control page has no login and the ESP-NOW packets aren't encrypted. It only works on my home network, but both are the next things to add.
  • Feedback: the nodes don't report back, so the page can't show whether a light is actually on.

Back to top ↑