Loss of Mains Power Alarm
Warning – For experienced Constructors ONLY
This project involves dangerous Mains Wiring
Why this project? Loss of mains power can lead to food spoilage in the refrigerator. If it happens over night, you may not find out about it until you wake up in the morning. This Mains Off Detector will sound a loud buzzer when the AC mains disappears. Plug it in in your bedroom and it will wake you up if the power goes off.
The impetus for this project was the use of the electric car battery to power the house. The Hyundai Inster provides a 15A 240V V2L (Vehicle to Load) outlet that can be used to power the house lights and computers and refrigerators, but that V2L supply can shut unexpectedly. If the house load exceed 15A the Inster shuts off the supply. The Inster also shuts off the supply once the battery discharges to the set minimum charge you have set.
The house also has a solar/ battery system. Again when powering the house from that battery, the battery will turn off the house supply when the battery has discharged. The house battery has about 8.3kWh capacity. The Inster EV (extended range version) has about 36kWh capacity, more then 4 times the house battery.
When running on the V2L or house battery (or mains), this alarm is used to alert us if the supply shuts off so that we can switch to an alternative source of supply.
This project is also on line at Mains Off Detector
Supplies
(prices as at Dec 2025 excluding shipping)
1 x DFRobot FireBeetle 2 ESP32-C6 SKU: DFR1075 US$5.90 or other micro with build in battery charger and Vin pin
1 x LiPo battery 3.7V 1100mAh 54mm x 34mm or smaller with 2-pin JST-PH connector e.g. Core-Electronics ~US$5.70
1 x 3v3 Buzzer e.g. Jaycar Dual Sound Piezo Buzzer 1-13VDC ~US$6.20
1 x Momentary Push Button e.g. Jaycar IP67 Rated Dome Pushbutton Switch Black ~US$3.10
1 x 3K3 resistor e.g. Jaycar 3.3k Ohm 0.5 Watt Metal Film Resistors - Pack of 8 ~US$0.55
1 x 2K2 resistor e.g. Jaycar 2.2k Ohm 0.5 Watt Metal Film Resistors - Pack of 8 ~US$0.55
1 x USB small power adaptor, e.g. Sparkfun SKU: TOL-15311 ~US$9.50
1 x enclosure, e.g. Jaycar Sealed Polycarbonate Enclosure 82 x 80 x 55mm ~US$9.50
1 x short length Main power cord and plug
1 x vero board e.g. Jaycar Universal Pre-Punched Experimenters Board – Small ~US$3.70
3 x 3mm x 15mm screws e.g. Jaycar M3 x 15mm Steel Screws - Pack of 25 ~US$2.20
2 x 12mm nylon spacers e.g. Jaycar M3 x 12mm Tapped Nylon Spacers - Pack of 25 ~US$6.20 (drill out thread)
Double Sided Mounting Tape e.g. Scotch Mount 13mm x 1.9m Double-Sided Mounting Tape ~US$5.00
hook up wire e.g. Jaycar Hook-Up Wire Pack - 2 metres each ~US$3.70
cable ties e.g. Bunnings Crescent 100 x 2.5mm Black Cable Ties - 25 Pack ~US$0.85
2m Nylon Screws / standoffs e.g. DFRobot White Nylon Screw and Mounting Kit -M2 ~US9.90
Software
ESP32 board support V3.3.0 (V3.3.3 has internal compile errors/warning)
DebouncedSwitch library – Download the DebouncedSwitch.zip file and install via Arduino menu Sketch → Include Library → Add Zip file..
Construction
The circuit is simple. (pdf version)
The USB power supply is dis-assembled and the circuit board removed and remounted (with double sided tape) on the vero-board.
Note: The copper pads under the USB supply have been scraped off.
The USB supply will accept 110V to 240V AC input and so this project can be used with either of those voltages by wiring a suitable power cable and plug to the USB supply board.
Use cable ties to secure the mains power cable and solder the mains lead to the USB supply board.
Wire up the resistors and push button, buzzer and USB 5V output and mount the Firebeetle ESP32-C6 with 2mm nylon screws. The buzzer mounts with a 3m steel screw.
Programming and Operation
Install the ESP32 V3.3.0 board support in the Arduino IDE. Select the DFRobot FireBeetle 2 ESP32-C6 board and program with the MainsOffDetector.ino sketch. This sketch uses the DebouncedSwitch library for both the pushbutton and the Vin monitoring input to ignore transients. The supply capacitor in the USB supply prevents the alarm from being triggered by transient loss of supply.
Plug the power lead into a power point. Turn the power point on to charge the LiPo battery. Test the alarm by turning the power point off. The buzzer should sound. Pressing the push button should cancel the buzzer. Also turning the power point back on should cancel the buzzer.
Conclusion
This project provide an audible alarm when there is a loss of mains power. It is intended to alert you to switch to an alternative source of supply, e.g. car V2L, house battery or mains, when the current supply is not longer operational.