Detecting momentary loss of power with Arduino

Hi all!
I am working out a control circuit for a light fixture to educate myself about the workings of smart bulbs.

To the best of my knowledge, smart bulbs usually require the light switch on the wall to be left ON, otherwise the bulb gets no power and cannot do its smart things. And they often have functionality for detecting when the light switch is turned OFF and then quickly back ON, so that they can be manually turned on when needed.
This requires that an Arduino can detect momentary loss of power when the light switch is turned OFF and then back ON, and respond appropriately.

My solution to detecting power loss is to split the output from a transformer into two lines, one is turned into 5V DC and another remains at 12V DC.

The 12V line can power the Arduino via the Vin pin or barrel jack. It has a capacitor so that the Arduino stays on during momentary power loss. I understand that the Arduino will stay on until the capacitor drops to something like 6.2V, which is the minimum for the Vin pin?

The 5V line is connected to a digital pin. When there is momentary power loss, the 5V line drops to 0V and then back to 5V when power is restored. My reasoning is that this power loss can be detected via the digital pin as HIGH-LOW-HIGH.

Will this approach work? Am I missing anything important, such as something that could damage the digital pin?
Am I overlooking a simpler way to do this? All I want is to power the arduino from a transformer, and be able to detect momentary power loss to the transformer caused by turning a light switch OFF and back ON.

Instead of the 5V regulator, use a voltage divider. Cheaper and more direct (regulators require capacitors.

You can also feed the Arduino with 5V and use an alalog input to measure the voltage; use the internal 1.1V reference and again use a voltage divider to bring the maximum down to the internal reference voltage of 1.1V.

Thank you! I modified the schematic according to your first suggestion, I hope I did it correctly.

Does ground for the voltage divider go straight into one of the Arduino ground pins?

Most likely I already have some suitable combination of resistors to give 5V or slightly under according to the voltage divider formula.

What power source wii feed the controller during the time the light switch is off?

I have a capacitor (size to be determined) charged up to 12V.

It's not much, but should be enough to keep the Arduino powered on for the second or two that the light switch is off.
If the light switch is kept off for too long and the Arduino runs out of power, I believe everything will run OK again (albeit from the very start of the code) once the light switch is turned on again.
It should be fine, because the Arduino is not keeping track of time or anything like that, simply listening for a signal via a 433MHz radio receiver saying to turn the light bulb on or off via a relay.

The other part of the circuit, with the radio input and relay output:

A transformer outputs AC. What you mean seems to be a 12V power supply (wall wart...) that typically can bridge a power loss of several seconds. Quick on/off/on switching will have no effect. Find out yourself...

Similar for the 5V regulator, it will output 5V as long as the 12V supply stays above 6V. The suggested voltage divider may work better, provided the 12V are DC, not AC, or you poll for the maximum AC value and cut off the negative half period.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.