Tuesday, 28 February 2023

Mains detection

A long story, but I needed to detect the position of the switch in the kitchen that enables the kettle to run off PV surplus. I'd always managed to detect it in software, but I now need the physical position





 Very simple. A 817 opto coupler. A 4n7-10n X/Y cap and 100R in series with the mains. A 1N4148 inverse parallel with the diode. A 22u tant across the output. Pull it high with a 10k to +5 and you have a detector that consumes about 100uW. Sure there's a bit of 50Hz ripple at 0.35V but it's well below CMOS threshold.
..1 month later
Seems I hadn't tested this across a big enough input voltage. At 240V, the opto output was falling between the ESP32 thresholds. A 18k across the 22u tant gives 0.9/2.1V. Just ok. Design needs a re-visit.