ActiveEmbeddedMechatronics

Smart Light Switch

ESP32-based servo-actuated wall switch with WiFi scheduling

RoleDesigner and Builder
Timeline2026
UpdatedMarch 9, 2026
MCUESP32
ActuationServo-driven physical toggle
InterfaceLocal WiFi AP + web scheduler
Smart Light Switch
Breadboard diagram Open
Schematic Open
Overview

A mechatronic retrofit for a standard wall switch. An ESP32 drives a servo that physically actuates the toggle, a web interface running off the ESP's own WiFi access point handles scheduling, and the whole thing installs in place of the existing switch plate. No cloud, no app. Just a local scheduler that works.


The problem

Retrofit a standard wall switch with programmable scheduling while keeping it fully self-contained and not dependent on any external service.

Constraints
  • Must fit within a standard single-gang wall box
  • Must work without any internet connection or cloud service
  • Servo actuation needs to reliably toggle the physical switch without slipping or stalling
Design decisions
  • ESP32 hosts its own WiFi access point. The scheduler is accessible from any device on the local network without a router.
  • Servo bracket designed to accommodate the small tolerances of consumer switch plates
  • Web UI stored in ESP32 flash, no external hosting
Build process
  1. 01

    Servo bracket prototyped and iterated in PLA for fit before final fabrication

  2. 02

    ESP32 firmware: FreeRTOS task for servo control, separate task for web server

  3. 03

    Scheduling logic stores events in NVS (non-volatile storage) so they survive power cycles


Result

Works. Reliably schedules the physical switch toggle. Web UI loads in under 200ms on the local network.

What went wrong / what I learned
  • Servo torque needs significantly more margin than the nominal spec when actuating against spring-loaded switches

Build logFull log →
2026-03-10

ESP brownout: traced to servo voltage spikes

What

Tracked down why the ESP32 would accept a firmware upload exactly once, then become completely unreachable on every subsequent attempt.

Result

Root cause: the servo was generating voltage spikes on the shared power rail that were browning out the ESP immediately after it started driving the servo. The ESP wasn't crashing or locking up. It was losing power. Confirmed by decoupling the servo from the rail: ESP stayed up indefinitely. Fixed with a dedicated supply for the servo and a decoupling capacitor on the ESP rail. The fix took about ten minutes once the cause was known; finding the cause took much longer.

Tools & Methods

ESP32FreeRTOSFusion 360PLA 3D printingWeb UI (ESP-hosted)

Specs

MCU
ESP32
Actuation
Servo-driven physical toggle
Interface
Local WiFi AP + web scheduler