I'm working on an automotive project that uses an Arduino Mega 2560.

What I need is a circuit that allows the unit to sense when the external power feed drops (triggering an interrupt?) so that the software can preserve state to the non-volatile memory and then shut down.

I was thinking some sort of capacitor/battery to run it once the eternal feed drops, but the hardware side of things is not my strong skillset - I'm more of a software kinda person.

  • I have been working with the new 47L16 from Microchip for this kind of thing - save state on power loss. It does it all for you (available in DIP for those that don't like surface mount). – Majenko Dec 29 '17 at 11:01
  • That looks like just what I need! Do you know of any tutorials/examples I can look at for hooking it up the the Mega? – Sam Clayton Dec 29 '17 at 13:31
  • No, I don't know of any. I just worked from the datasheet - it has all you need to know, you just have to understand it. – Majenko Dec 29 '17 at 13:32

Consider a battery backup for low power devices. This article from allaboutcircuits.com discusses how to build a 12 to 5 volt power supply with its own battery backup.

In your specific case, run a second 12 to 5 volt regulated signal to one of the processor's digital inputs. When the 12 volts shuts off, the signal to the processor's digital input will go low. Poll this input and when you see it go low shutdown the processor or put the processor into a deep sleep mode to draw as little current as possible from the back up battery.

The ATmega2560 processor may not be the best chose for this. There are processors that can drop down into the nA range and still wake up periodically to check if they should be powered all the way back up.

  • Thanks, I'll do some experiments with my board to see how long it takes to actually shut down after power is cut. – Sam Clayton Dec 29 '17 at 13:33
  • I found a thread about this. Unfortunately it discounts the built in ATmega2560 brownout circuit for the reasons I gave above. If so, I really think the ATmega2560 design is flawed with respect to this feature. – st2000 Dec 29 '17 at 13:36
  • There is also this rather involved thread in the Arduino forums. At one point someone is talking about re-flashing the Arduino boot loader. – st2000 Dec 29 '17 at 13:40
  • The AVR brownout detector only does the minimum needed: It re-sets the AVR and keeps it in reset while VCC is under a certain level to prevent programs going wild - It's not capable to trigger any safety action in the software. – tofro Dec 29 '17 at 13:42
  • Oh, wait - in almost all cars there is a power supply from the battery which is not shut down. This is used for features like car-stereo-theft-prevention and the car-alarms. You could use this as a power source and use your switched-car-power supply to trigger a controlled shutdown. But be very very careful about drawing minimal or no current when shut down. As I doubt there is anything preventing you from draining your car's battery. (I'll change may answer in light of this.) – st2000 Dec 29 '17 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.