Execute a function when the power source is cut off

I have a Servo motor and I am able to perform operations with no issues.

I connect my power supply, and the motor rotates to 90 degrees (if it was not at 90 degrees initially).
My problem is, I want the motor to rotate back to 0 degrees when the power supply is cut off. I know I will need another power supply to do this in the end (maybe a battery), but I am confused as to how to do it.

How can I do this?

Run a small relay with the servo power (5v) when you have mains supply to drive your circuit through the common and n/o contacts.

When the main supply drops, have a battery supply connect from the common to the n/c contacts.

Plus you will need to tell it to go to zero.

Changeover.jpg

Changeover.jpg

Put a diode into the positive main and backup supply, the combined cathodes to the servo. Then the servo will always use the supply with the higher voltage. Use Schottky diodes for low voltage drop.

monitor power
with loss, signal the servo to close

  • not all motors close with loss of power.

use a supercap, that can power the
arduino and motor for longer than it takes to close

use a supercap, that can power the
arduino and motor for longer than it takes to close

this, but add: main power source to the barrel connector. use one digital pin to monitor status of voltage at the barrel regulator. if you lose power at the barrel initiate the shutdown and park function.

supercap into the 5V feed. put a resistor in line with the 5V to the supercap, so the entire board does not turn into one glorious fuse when the cap charges up the first time.