Building my ESP32 Smart Switch: from prototype to custom hardware
Relay control, firmware, debugging and custom PCB design.
Javed Hussain
Founder of CoachingsNearMe.in · Teghra, Bihar
Why Regional Power Needs Custom Smart Switch Hardware
Living in Teghra, Bihar, power fluctuations, brownouts, and rapid restarts are daily realities. Most off-the-shelf smart switches rely on cloud servers in distant data centers. When Wi-Fi drops, you cannot even turn off a light from the wall switch. I set out to engineer a bulletproof, offline-first 4-channel controller using an ESP32 microchip.
Galvanic Isolation and Mains Safety
Connecting a 3.3V microcontroller to 230V mains is dangerous without proper isolation. I utilized optocouplers (PC817) to create complete optical barrier isolation between the ESP32 GPIO logic and the electromagnetic relay coils. Flyback diodes were placed across each coil to suppress back-EMF spikes when switching inductive loads like ceiling fans.
Zero-Chatter State Machine and Hardware Debouncing
Physical toggle switches introduce contact bounce (several milliseconds of electrical noise). I implemented an RC low-pass filter combined with a software state-machine running on FreeRTOS that ignores spurious transitions. When power restores after an outage, the switch reads the exact state from non-volatile flash (NVS) without flickering.