We all know by now (should know) that a reliable and solid 5V supply is critical for the Pi. Especially if you use the earlier non + versions without the improved USB power. Many WIFI USB adapter problems can be solved by a good and solid supply.
Also, if the power has brown-outs during write operations to the SD card, it can become corrupted.
Here is a very simple supply that covers these requirements.
First of all, most wall-warts have difficulty supplying 5V to the Pi at 500mA or more. This is either due to the design of the wall-wart if it was designed to charge your phone or tablet, or there is a significant voltage drop from the wall-wart to the Pi through the cable. You’ll be surprised how thin the actual conductors are in most cables. The best way to see if the Pi gets the full power it needs is to make sure you measure 5.0V between TP1 and TP2 on the Pi circuit board.
One simple way to make sure the Pi gets what it needs is to use a DC-DC step-up convertor, and adjust the output such that the voltage between TP1 and TP2 is indeed 5V0. These convertors can be had for less than $10 on eBay or Amazon.
The simple, albeit somewhat destructive method is, to cut your wall-wart cable to the micro USB plug, and put the step-up convertor in the middle. This preserves the mico USB input to the Pi, and keeps everything else the same.
If you decide to power the Pi through the GPIO connector, you need to supply a (resetable) fuse and if possible a transient suppressor, because that is what you’ll be bypassing.
To add back-up power to the Pi so it can survive brown-outs of the mains, you can rather easily add a battery. If you restrict the battery to non-rechargeable 1.5V AA cells, you’ll need 3 (not more!) of those and two Schottky Diodes to combine the two supplies. In that case, you must eliminate D1 and R3 !
If you use 1.2V NiMH or NiCAD’s you can also add a simple trickle charger to maintain the charge. This only takes two more parts (D1 and R3), and the following diagram shows how to do that for 3 cells. [Edit] Three cells is the maximum, because we will need about 1.4 Volt per cell to charge them. If you use 3 cells in a 4 cell battery holder, you can bridge the empty space with a wire.
Unless you know what you're doing, I suggest that you stay away from Lithium-Ion batteries, because the charging of those is non-trivial and potentially dangerous. They can explode if mishandled.
The concept of the circuit relies on the fact that the wall-wart will normally supply the power to the Pi, through the step-up convertor. If there is a brown-out, the batteries will take over through the Schottky diode OR circuit ( D2 and D3) and that allows you to run the Pi until the cells deplete below the threshold for the step-up convertor, which is somewhere between 2.8 and 3.0V.
If you would like to shutdown your Pi to preserve the SD card after a certain amount of time, you need the circuit of R1, R2 and C1 (10uF is maximum) to tell the Pi that the mains is gone. Your program can put the Pi in the Halt state whenever you want (after a delay) by issuing a sudo halt or sudo shutdown. There are many examples available on this forum. With fully charged cells, the UPS can power the Pi for a few hours. Note that it can take at least 30 seconds for the Pi to reach the Halt state.
If/when the power comes back after you issued the shutdown, you’ll have to restart the Pi manually to let it reboot from the Halt state. This will be an abbreviated boot process. Making this restarting fool-proof and fully automatic is not trivial, I suggest you look at some of my other postings on this forum to see an example on how to do that.
Enjoy!
Paulv