"Safe shutdown" circuit

Hey all, for a few days now, Im struggeling to come up with a solution to safely shutdown an arduino (let it save all the data it needs when power is lost). Has anyone attempted to build something like that? My circuit consists of a wall psu and a battery. Basic functionality should be: Wall suply stops -> battery takes over -> arduino does what it needs -> it shuts itself down (no power should be consumed when its off) Then, when the power comes back on, it automatically turns itself back on and is ready for another eventual power loss. Problem I was having was the transistor stayed switched on even when the arduino was shut down... Is there a better way, using a fat or something? I would like to get away with not using relay.

Thanks for anything you can think of.

You are writing EEPROM? How much data do you need to write and how often? Or do you have an SDcard to update?

A power control circuit usually is a bit trickier than you'd first imagine - you have to arrange that the external transistor controlling the battery supply is turned on by an Arduino pin being HIGH, which probably forces using two transistors, an NPN to drive a high-side PNP (or logic-level pMOSFET).

When the Arduino is powered down all its pins are clamped at Arduino ground potential by the internal diodes.

Oh. Ive not decided yet, but probably sd card. I guess the time to save everything should never be more than 10s. The data written to the sd would probably be a basic set of weather data (temp, humidity...) + voltage of the battery. Basically a sum of all the data I can meassure. It will be written only once, when the thing is shutting down.

Wojta: Hey all, for a few days now, Im struggeling to come up with a solution to safely shutdown an arduino (let it save all the data it needs when power is lost). Has anyone attempted to build something like that? My circuit consists of a wall psu and a battery. Basic functionality should be: Wall suply stops -> battery takes over -> arduino does what it needs -> it shuts itself down (no power should be consumed when its off) Then, when the power comes back on, it automatically turns itself back on and is ready for another eventual power loss. Problem I was having was the transistor stayed switched on even when the arduino was shut down... Is there a better way, using a fat or something? I would like to get away with not using relay.

Thanks for anything you can think of.

How do you charge the battery?

Battery ---- P N P ---- VIN I N P N ---- GND I Arduino pin should enable battery power as tong as the pin is high. When you put it low it should close the transistors. When Arduino is powered again from other source you will set the pin up waiting until power failure. You need add resistors into bases ofc.

But if you can write the data fast enough you can use cap instead the battery - it will be recharge full everytime the source is connected with no worries you drain it fully when power is lost.

Thanks a lot. I will try it as soon as I can and give some feedback. ;)