If you are doing continuous tasks with Raspberry Pi like logging, calculating or controlling things, then you shouldn’t rely only on power adapter. If main power fails, your device will also fail and there will be no excuse of you loose your data and work progress. In such cases you should take care of power back-up.
Repairhub suggests his battery power backup system for raspberry Pi. This is actually an external circuit attached to boards GPIO power and control pins. His circuit does the following:
- charges battery when mains is on;
- generates signal to GPIO when power goes off;
- software detects power down and few minutes shuts down computer;
- after shutdown power circuit is shut off to preserve battery from discharging;
- pi logs events with timestamps.
Circuit detects power off by using optocoupler. Signal from its output is sent directly to RasPi GPIO8. Power cutoff circuit part is constructed by using couple MOSFETs.