Cheap Battery Backup for Raspberry Pi or Arduino

I’ll throw this out real quick as I’m sure others are trying to do the same thing.

Been working on a RPI project that is ‘mission critical’. It cannot fail because it looses power and the file system corrupts. So I put together a battery backup that will provide 5V which can work for either RPI or Arduino.

The theory behind my circuit is very simple. I have a 9V battery and a 12V transformer providing current, both behind diodes. As long as the 12V power is on, the 9V battery is inactive. As soon as the 12V power is removed, the 9V battery provides power.

I use a DC to DC converter to convert 12V or 9V to 5V. My first experiment was with a normal 7805 voltage regulator. First, it got quite hot, even with a heat sink. The RPI draws a good chunk of current. Second, because so much power is wasted, the battery lasts just a few minutes.

I then tried the OKI-78SR-5/1.5-W36-C DC to DC converter, available here for about $4. (Same size as 7805 though the pinout is different). This works great – not only did I get rid of the heat problem, but the 9V battery was able to power my RPI for about 45 minutes.

Here is the schematic:


D3 exists to protect the circuit if I put the battery in backwards. I find this easy to do with a 9V. D4 is a 1A schottky diode which has a low voltage drop. You are starting with 5V, so you don’t want to loose much.

D4 prevents power coming from the RPI back into the circuit. Probably not important if nothing else is connected to the external power supply, but you may not want the RPI powering external circuitry.

A fuse is also highly recommended. I have a resettable fuse here, but it still isn’t quite the one being used by the RPI’s internal power supply. If I can find the same one (through hole), I’ll put it’s part number on as well.

I have the beginnings of a power fail detector circuit that can notify the RPI that it is in a power fail state. It’s just a transistor monitoring the 12V supply (essentially a NOT gate that outputs 3.3V). Once I have it fully functional I’ll add that.

I’m also working on circuitry allow the RPI to turn the battery OFF when it has shutdown so the battery doesn’t fully discharge. That is being implemented with an ATTiny85 and I’ll try to get that documented after it is fully functional as well.

Feb 2016 update:

Stumbled across this site: Safe Power for Raspberry Pi. At the moment I don’t need this, but it looks like a very good solution for providing RPIs with battery backup. So I’ll put a note here of the site.

Here’s another article worth looking at

Battery Backup For The Raspberry Pi

Aug 2016 Update:

Filing this post away for possible future use. The (my) reason for wanting battery backup is to protect the O/S from corruption. The other possibility, covered in this post, is to make the O/S Read-only:



This entry was posted in c-arduino, c-electronics, c-rpi and tagged . Bookmark the permalink.

5 Responses to Cheap Battery Backup for Raspberry Pi or Arduino

  1. Sean Straw says:

    If you’re powering your rpi from a 9V cell, don’t expect much runtime if there are any significant loads.

    Seems you could incorporate the power fail AND the battery shutoff using the ATTiny. An ’85 is likely more than you need for the task. If you drive the power for the ATTiny from a GPIO pin of the rpi, then all you’d need to do is drop the signal, and the ATTiny will shut off.

    ATTiny can drive a logic-level FET to gate the battery power through your regulator/converter and into the PCB.

    I’d run some experiments with a capacitor on the output instead of the rpi and see whether the converter your are using can be backfed from the output or not – I’d expect that it wouldn’t and as such you may not need the schottky on the output anyway, or may be able to put it on the input side, where the voltage drop would be less detrimental.

  2. Sean Straw says:

    I wrote this back in August, but there was a network problem at the time, so I copied it into my journal:

    A typical DC-DC converter circuit will not backfeed the source, so I expect the Schottky isn’t necessary here. You could test by applying 5V (say from an ultracap) to the output side of your DC-DC converter and having a discharged cap in place of your 9V battery – if the cap charges, you have a backfeed situation.

    If you get a chance, you should check out the TI TPS62160 – – It’s a switchmode PS IC which is wonderfully efficient and doesn’t require too many external components (three resistors for feedback, two small ceramic caps, and a tiny inductor – yea, more suited to PCB use than just slapping it into a breadboard). Good for 1A output, it can function to Vin=Vout, and has a low power mode for when there isn’t a draw. I made up a few small PCBs – smaller than a US Dime (inclusive of the berg pin headers for input and output) to use these on breadboards for a few prototyping projects. The resistors allow you to define your output voltage, so say 3.3V for direct uC powering (such as ATTiny projects off of a single LiIon cell), or 5V for general projects, etc. Also has enable input (good for staged power, or for your uC to control power to a subsystem such as a radio) and power good output (generally used for input to the next power stage if you’re using that design).

    I’m a Beagle guy myself, but as I understand it, the RPI B has a max current draw of 700mA at 5V, so if you were making up a power supply PCB, the TI chip would certainly be capable of doing the job.

    Of course, you could go with a 6V or 12V rechargeable setup and have a buck (even the one you’re using) supplying the board directly via the barrel plug connector, and the wallwart maintaining battery charge / providing the current for the buck when there’s mains, then your RPI is operating more like a laptop.

    • Dan TheMan says:

      I’d really like to move to SMD. A year or so ago, I bought an SMD practice kit from Sparkfun, I think, to give it a shot. I discovered just how shaky I am when I tried to place the little MCU on the board. I was very surprised when I was done that the board actually worked.

  3. Sean Straw says:

    If you have a hot air rework station (and if you don’t, time to upgrade – the ‘852D’ model from various manufacturers can replace your temperature-controlled soldering iron and add hot air in one box), you can take old PCBs and practice desoldering components from them, then re-solder them. Certainly a practice kit tells you you’ve done it all right if the device works, but if you practice with functioning, just dated PCBs, you can verify they still work when you’re done. Desoldering adds an extra level of abuse to the devices if not done properly: if you’re dealing with anything much larger than a SOIC8, you want to carefully bring up the temperature of the PCB area around the chip before focusing on trying to remove the individual device.

    There are also stick+air+power supply benchtop models which add a basic power supply to the mix.

    As to steady hand – get your part in place and then hold it down with steady pressure at the centre of the device using your off-hand, with your wrist or a finger (“pinkie”) contacting your workbench, giving you better stability. Then, anchor one lead of the device (a corner if 4+ pins) by flowing the solder on it (soldering iron in your primary hand, and possibly also stabilizing with a finger or two on the workbench). Adjust device positioning if necessary and then anchor a lead opposite the first, and then you can cease holding it down and just continue soldering around starting from a lead ideally not adjacent to the first two you’ve soldered (thus reducing the chance they’ll immediately re-flow and the device shifts). After a few IC’s, you start to get the hang of it.

    For devices a bit larger than the smallest of SMD caps and resistors, there are vacuum pens with tiny suction cups on them. press a button to push the air out, set the sucker on top of a device, release the button, and the pen sucks in and pulls vacuum on the device. I honestly don’t use mine all that often though – I find that they’re much more suited to the larger uCs (ones you can’t span the top of easily with tweezers).

  4. Sean Straw says:

    Just received my C.H.I.P. boards from the NTC kickstarter. These are AKA “the 9 dollar computer”.

    Thought I might mention that they’re an awesome alternative to the RPI for battery-backed applications (at least where you don’t need HDMI): you can plug in a battery to the PCB (via a 2-pin JST-PH connector), and if the device has power from the microUSB, it will charge the battery pack, and the power management IC can seamlessly switch to the battery when USB power goes away. Other plusses are that the PCB is quite small (you can almost fit two of them side by side on a standard credit card), and it includes WiFi on the PCB.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s