Multi-Purpose Smart Outlet
An outlet that can be switched on/off via WiFi, Radio, or an onboard button
The Story Behind the Project
My Motion Activated Lamps have been very convenient, consisting of two outlet boxes that are switched via a specific transmitter radio. But over the last two years, I've found myself occasionally wishing I could repurpose an outlet box, but that has been difficult because they are programmatically tied to the single transmitter, the microcontroller is difficult to access, and the only special hardware they have is a radio.
So I decided to make another switchable outlet that is much more flexible to use. This one contains a radio as well as WiFi and an onboard button and RGB LED. This means it can be switched via radio or MQTT via WiFi (internet page on a phone, IOT device, etc), or the onboard button. The LED indicates WiFi/configuration portal status, and holding the button down allows the user to launch the configuration portal at any time. The configuration portal (in addition to controlling WiFi settings) allows me to update the firmware wirelessly without having to take apart the box -- so I can easily change the radio address or add new functionality in the future. The portal also lets users set 10 custom parameters, such as MQTT topic, radio address, and times to switch on/off automatically.
It's first use is for the fairy lights in my room. Now my roommate and I can turn off the lights before we go to sleep from our phones without getting out of bed, and (coming soon) via a button on our bedside table that can use the radio to be battery powered, lacking any time and power intensive WiFi functions. In lieu of the button, currently there is a laser shooting over our beds that by waiving your hand above your head while lying down you can break the beam and trigger a radio to toggle the outlet. TBD on whether the convenience of this outweighs the definitive lack of aesthetic appeal.
This project also marks my first serious use of a PCB designer! The PCBs are custom manufactured by JLCPCB and make assembly time much faster and without wiring mistakes. Additionally, it allowed for the AC wiring to be simpler -- the routing through the relay and to the power supply is taken care of on the board so it just has two pads for power in and power out. The custom silkscreen also allowed for some simple instructions on the board, as well as a QR code on the back, linking to this webpage for complete info & code.
Features
Three methods of switching work simultaniously: Radio, WiFi, Button
Firmware can be updated wirelessly without having to take apart the box
Overcurrent protection built in -- if current draw exceeds a 5 amp average for 5 seconds, the MCU will switch off the relay and rapidly flash the indicator light, disabling the outlet until it's unplugged and plugged back in.
Configuration portal times out with inactivity and can be re-launched at any time by holding the button. This way it is not constantly broadcasting a network
WiFi is non-blocking, so even if it is disconnected or not configured, radio switching still works
Configuration portal allows setting 10 custom parameters that are saved to EEPROM
Code available at https://github.com/BlaineAtkins/GenericOutletBox