Electronic – arduino – how to detect power failure and make micro-controller save data in EEPROM


I am using Arduino nano for a project in which I have on a counter which is continuously increasing. And I want to retain count after a power failure. Data is changing more frequently so storing it continuously into EEPROM is not an option as EEPROM has erase/write cycle limitation. Additionally, data is of 4-byte maximum.

please, can anyone suggest an IC or circuit design which can detect a power failure and interrupt Arduino so that it can save data into EEPROM.

I guess I will have to use a capacitor to power Arduino after the power goes down so that Arduino will be able to save data into EEPROM.

Best Answer

This is the principle diagram you need. Values for R1 and R2 depends on the power supply voltage and the maximum input voltage of your CPU pins.
The value of C1 depends on how much current your circuit is using and how long you need to keep the power up and to what level. Adding a regulator after that cap can greatly improve your time allowing you to use smaller capacitors.
To calculate the value of C (Your obvious next question) we need all the data Tony Steward is asking for.


simulate this circuit – Schematic created using CircuitLab