Power supply to trip interrupt on power off

I’ve been looking for awhile, but can’t find an article. I know it’s been done!

Is there a better way to trip an interrupt for when the power is turned off so some work can be done? This seems like it might just pull a bunch of current and turn it into heat on the 7805. Or does it only pull what is needed by the output?.

Note: there’s other electric items being run off the 12v, so it’s a bit noisy… (lights, etc)

power trigger.JPG

Use a simple transistor with a base resistor and a 9V zener, set the interrupt for rising edge. when incoming power drops below 9.7V the interrupt will trigger. The 9.7 comes from ~.7V base-emitter forward drop plus the zener voltage of 9V. This gives you 2.3V of noise immunity to cope with load regulation on the 12V supply.

Cool! Thanks for the quick reply. So basically this circuit? I could even go with a 6v zener to have even more play/safety.

power trigger.JPG

Emitter to ground, base resistor and zener are in series with cathode toward +12V, collector to arduino pin 0 and a pullup resistor tied to 5V.

Awesome. The pic helps a lot. Thank you for the help.

Alternatively, just use two resistors to make a voltage divider feeding the analog comparator negative input pin (AIN 1), program the analog comparator to compare this value with the internal bandgap reference, and enable the analog comparator interrupt. See the atmega328p datasheet or http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272923299 for the details.

So useful picture!It makes understanding easier! :grin:

I built it and it works! In case anyone wants more info, here’s my as-built schematic and test sketch. I still went with the diode and cap across the power just to keep it running a bit longer (to update a display saying “shutting down” or that kind of thing).

volatile boolean isStopping = 0;

void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
pinMode(10, OUTPUT);
pinMode(2, INPUT);
attachInterrupt(0, PowerDown, RISING);
}

void loop() {
if (isStopping == 0)
digitalWrite(10, HIGH);
if (isStopping == 0)
delay(200);
digitalWrite(10, LOW);
if (isStopping == 0)
delay(200);
}

void PowerDown() {
isStopping = 1;
digitalWrite(13, HIGH);
}

power trigger.JPG