Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.
Small project, big list of ways it can go wrong
A relay on a web page is the "hello world" of home automation, and it is also where most real-life problems appear. The first is what the relay does at power-up. Some ESP32 pins pulse during boot, and your kettle clicks on and off at every reset. Pick a pin that is stable, and write the last state to flash so that after an outage the device returns to what you expect.
Checklist before it goes into a wall
Use a relay module with an optocoupler and a separate supply for the coil; many modules need 5 V for the coil and 3.3 V for the signal, check which one yours is.
A physical button should work even when Wi-Fi is gone. Debounce it in software.
Put a token or a password on the page. An open HTTP switch is visible to everyone on the local network.
For motors and transformers add a snubber across the load; arcing wears the contacts fast.
The same sketch becomes a lamp controller, a gate pulse generator or the output of a bigger scheme such as the router watchdog.
Comments
No comments yet. Share your experience or ask a question.