share
Raspberry PiHow do I build a UPS-like - battery backup - system?
[+105] [11] Riku L
[2012-07-31 05:24:20]
[ power-supply alternative-power ]
[ https://raspberrypi.stackexchange.com/questions/1360/how-do-i-build-a-ups-like-battery-backup-system ]

As we all know, the Raspberry Pi doesn't really use that much power (5v + 700mA is the spec).

I'd like to build a battery backup for power outages in a DIY-ish fashion. I don't need surge protection or any other fancy options, just security from minor power outages and brownouts.

How can I put a battery backup between the Raspberry Pi and the phone charger I'm using to run it?

(4) How long is a minor power outage? - John La Rooy
I think this is best implemented as a LiPo expansion board. - Alex Chamberlain
I would define a minor power outage as a few seconds of complete lack of power, enough to make a normal desktop computer reboot. - Riku L
(2) @AlexChamberlain, LiPo complicates things as they do not tolerate trickle charging. NiMH or lead acid make life a lot easier in this case. I think electronics.stackexchange.com is a better place to ask this question - John La Rooy
Could you power the board in parallel with a big capacitor? - Alex L
(1) ok so what do you think about this: ebay.com/itm/… or that: amazon.com/9000mAh-Capacity-Portable-Rechargeable-Camcorder/‌​dp/… to keep it connected to charger and raspberry continously - user8523
(2) It's actually possible to use a USB power bank as UPS. My Pi is continuously running for about half a year now this way. I've summarized the details at raspi-ups.appspot.com - emkey08
(3) @MathiasKunter I tried that but had a hard time finding a USB power bank that could be charged while it is charging a device. - Riku L
Check www.wugrobot.com/products/pion/, it should help. - Park Huang
FWIW, here's a link to a very similar project that someone did: "Single SuperCapacitor UPS for Raspberry Pi" <br>*"A last gasp Uninterruptible Power Supply for any Raspberry Pi computer."* - jacobq
[+61] [2012-07-31 09:03:59] Piotr Kula [ACCEPTED]

You question is more suited for the Electrical Design Stackexchenge site [1] - Because you can always rely on the Gurus there, like Oli, to help design easy, up to date circuits.

I think that this question will be asked by many more Raspberrians to come so this is actually a very good place to answer your question.

My answer will go more into engineering your own circuit so that you can have full control of what you want it to do.

The circuit should handle...

  1. Initially deciding what kind of circuit you need. Powered by USB 5V? or maybe by a 12 volt source? You can also power it from a lower power source like 3.3V/1.5V but is very inefficient in converting power. This decision also fundamentally contributes to what kind of voltage regulator you are going to use... if any.
  2. Keeping the battery charged up during normal operation (also each type of battery requires have charging characteristics, Lead Acid, Ni-Cd, Li-Ion, etc)
  3. The circuit needs to sense when primary power (USB +5V) stops providing power or similar.
  4. The backup circuit to charge your type of battery and an embedded circuit to possibly route power back into the main circuit when the main power is off.
  5. Optional. Build a trigger into the circuit that connects to the Raspberry PI's I/O system to send you and email,text message, make a phone call, trigger an alarm or turn of your kitchen lights.

Searching around the internet most UPS circuits and schatics will include a transformer to reduce 110V/220V down to DC 12 Volts.


  • Here is a very simple circuit used with Lead-Acid batteries (They are easy to charge and they keep charge for a very long time) Do not attempt to charge any other kind of battery with circuit... they will blow it up!

Lead-Acid UPS

Part List:

  • R1 - 39 ohms 1/2W
  • D1, D3, D4 - 1N4001 or similar diode
  • D2 - 13V zener rated 1W
  • C1 - 220uF electrolytic capacitor rated 25V
  • C2 - 10uF electrolytic capacitor rated 10V
  • IC - 7805 or similar 5V regulator
  • BAT - 12V lead acid battery rated 1.2Ah minimum
  • DC Input - 12 Volt DC

Recycled notebook UPS


USB charged UPS


Do not feel like building your own circuits? There is this MUPS available [4] for purchase (gone, sorry) that does pretty much what the final circuit design outlines.

MUPS

References

[1] https://electronics.stackexchange.com/questions/36930/some-advice-on-charging-circuit-used-in-simple-ups
[2] http://ic1520.wikispaces.com/Li-ion+battery+UPS
[3] https://electronics.stackexchange.com/a/36938/4160
[4] http://avtech.com/Products/Monitor_-_Sensors/MUPS.htm
[5] http://www.simple-electronics.com/2012/02/5v-ups-circuit.html
[6] https://electronics.stackexchange.com/

(4) I don't see why this circuit wouldn't recharge the battery. Also, if you replaced the regulator with a LM2940CT-5.0 (5V low drop-out regulator) you could use a 6V lead acid gel battery instead, which would result in much less heat generated by the regulator since it's only dissipating up to 1.6W of energy (2.2V * 700mA) rather than 5.9W (8.4V * 700mA). Of course I'd recommend a 7.2-7.5V regulated supply for your input, so you can safely "float-charge" the battery (7.5Vs of the supply - 0.7Vf drop of D1 = 6.8V at the positive terminal of the battery). - Doktor J
Nice comment. I think it will recharge it but only a lead acid battery as commented, NOT lithium ion! be very carful it could blow the battery up. This circuit needs revising for lithium ion. - Piotr Kula
Excellent point -- the above circuit should ONLY be used for a lead-acid battery! A Li-Ion battery could be very seriously damaged or catch fire in a circuit like this, and even NiCd or NiMH batteries may not be safe in this circuit. For such batteries you'd need a more robust charging circuit. - Doktor J
It seems like something that could be rally beneficial out there not just for Rpi... :) - Piotr Kula
Yes, I'm actually designing a similar circuit for an emergency LED lighting system for my home (we live in SE Massachusetts, and are occasionally subject to hurricanes, blizzards, and other storms that induce extended power outages)! The difference is my circuit is designed so the lights don't come on unless the power's out. They also have an override "off" switch so you don't waste the batteries during the day or while you're not home. - Doktor J
thge circuitry need some extra things in there- ni-cd and li-ion batteries are very fragile to over charging and there needs to be a way to use the batteries power when the mains fails.. so some kind of sensing circuit.. i added another schematic that might nail it on the head with a few tweaks - Piotr Kula
This answer is great factually, but really needs cleaning up. - Alex Chamberlain
Your MUPS link is now broken. - Ruslan
Sorry.. its been 6 years.. wow. They don't sell it any more. also the simple electronics is down.. added webarchive link. - Piotr Kula
As an alternative to the 7805 shown there (and its supporting capacitors), you could use a much more efficient buck converter board, they can be had very cheaply on eBay now... can put out 5V at several amps (more than enough for the Pi and anything plugged into it) without breaking a sweat, as opposed to the linear regulator that will double as a space heater trying to dissipate 10-25 watts of heat from dropping 12V->5V or let the smoke out in spectacular fashion if not adequately heatsinked. - Doktor J
FYI Marcellus' answer below is a simple buck converter circuit if you're more inclined to build your own rather than buy a prebuilt buck converter board. - Doktor J
1
[+20] [2012-08-01 06:52:34] Marcellus

I have built a converter from 12v to 5v

That's enough for RaspberryPi's 5v requirement. IT also gives power for fan with adjustable thermostat (12v) and even active usb hub (in the future). Everything (Raspberry Pi, converter and thermostat) is enclosed in a router-box (I even have space for an additional 2.5" hdd, 3G modem and/or GPS unit ;) )

Such a converter can convert power from a battery pack (for example from 5 or more AA batteries) and SAFELY give 5V for Raspberry (watch out for voltage!). The converter is pretty small (i think 3 x 10 x 1.5cm). But if you are good at soldering and building circuit boards you can do it smaller.

This is the converter I use with a sample schematic.

enter image description here

enter image description here

It works great, you can attach from 7 to 40V from batteries. And we got max 3 amps on 5v side.

If you need to switch between phone charger and battery pack, you must build a switch (when power from charger goes down, the battery-pack power is connected and vice versa). I think that's pretty simple (transistor, capacitor... just few elements). Or do it manually ;)


(1) Hello- Thank you for you input it is really appreciated! As a new user please quickly read the site rules found under "faq" and "about" at the top. You do not have to apologise or thank in answers. You can always edit your answer later. You can easily upload pictures while editing to. Please do not worry about your language or spelling. Somebody will always be happy to edit and fix it up for you. Welcome to RaspberryPI SE! - Piotr Kula
(1) That is fantastic mod! I am sure it could be used in the suggested circuit from Engineering forum are just as it... :-) I love it! - Piotr Kula
You can get modules based on the LM2596 on ebay for $2 shipped. There are also modules based on LM2576, but they are more expensive - John La Rooy
2
[+14] [2012-07-31 19:17:54] WillyWonka

I found the question very interesting but my self am not really interested in soldering and fiddling with resistors and stuff and I am sure other people might stumble upon the OP question with hope of a ready product.

So I did find this which for my needs would actually be great. Buy, wait a few days, plug in and viola.

enter image description here

I found it on DX.COM [1]

As pointed out in comments. It seems like there could be an issue with high power consumption.. so end of day it looks like it will have to be opened and messed about with. But it is suitable for the Model A.

[1] http://www.dealextreme.com/p/direct-ac-recharge-usb-backup-power-pack-with-cell-phone-adapters-3600mah-4284

Does it have a battery inside? Looks something like we are talking about yea.. thanks. - Piotr Kula
(4) Only problem is, the user was looking to do something "in a DIY-ish fashion"... this is about as far from DIY as it gets ;) - Doktor J
The current rating is a bit lower than the RPi, but perhaps it can be modified. I have been running the RPi from a USB port on my laptop with no problems so far anyway :) - John La Rooy
Currently your answer does not explain how it answers the question. Please add an explanation or I will be forced to delete it. Thank you for your cooperation! - user46
It would work as a low power usp as it can sit on charge and you can run the RPi off the 3500mAh battery at 500mA at 5.3V but really one with a USB output: DC 5V, 700mA would be better. - Hellonearthis
There are other devices such as this one which will output 5V at 1A. dealextreme.com/p/… - Kibbee
(1) But what if I can't viola (I don't own one)? - XTL
The problem with regular battery packs is that the output voltage dips enough to reboot the raspberry each time the powerpack input is connected or disconnected. - Riku L
3
[+5] [2013-12-03 12:50:20] avra

Any external USB battery pack with built in overcharging protection will help your Pi survive power outage. It will simply work as a poor man UPS for your Pi. http://www.google.com/search?ie=UTF-8&oe=utf-8&q=usb+battery+pack [1]

[1] http://www.google.com/search?ie=UTF-8&oe=utf-8&q=usb+battery+pack

(1) We must simply find a USB external battery that will stand being continuously connected to the input supply. Surprisingly enough, many battery systems, specially lowest quality ones, will not stop charging the battery, which heats the battery and shortens its life. - Raúl Salinas-Monteagudo
@RaúlSalinas-Monteagudo Check out emkey08's comment to the question. He provides a link to a page where he mentions a usb UPS which seems to be what you (and I) want. Just ordered it =) - Rotareti
The problem with regular battery packs is that the output voltage dips enough to reboot the raspberry each time the powerpack input is connected or disconnected. - Riku L
exactly what I first thought... - akostadinov
4
[+2] [2013-01-14 08:38:59] Chris Jones

Here is a UPS for the Raspberry PI: http://www.eevblog.com/forum/projects/raspberry-pi-server-with-diy-ups/

Also, with sufficient changes and safety circuits, lithium rechargeable cells can be float charged. In this case it is best to use a single cell and a boost converter so that balancing circuits are not required. Here is some info on float charging lithium cells: http://www.electronicsweekly.com/Articles/01/02/2006/37528/Float-charging-lithium-ion-cells.htm


5
[+2] [2013-04-30 04:40:51] user7165

So you want a SIMPLE reliable DIY ups like powersupply for your RPi:

  1. get a sealed 12v Pb battery ( I use a 5Ah battery)
  2. get a 220Vac to 12v switched mode power supply (I use 12v 4A )
  3. get a car lighter to usb plug (8v--24v input, out = 5v 2A) switched mode
  4. get a diode which can handle 4A and a 0.5 ohm 5 watt resistor to limit the current by empty battery recharging
  5. get a usb to universal cellphone charge cable it has 10 different plugs with short cables, 1 goes to power the RPi,an other one for the usb hub , an other for whatever jumps in mind.....still many left

Wire it as follows:

  • from the +12v of the power supply to the anode of the diode

  • from the cathode of the diode to the 5Ah Pb sealed battery, this protects against the power supply draining the battery when no 220v

  • Then from the + of the battery to the "lighter plug to usb " +5v 2A

, plug in the usb cable

I was liking to put a picture of all parts needed, but i'm not allowed by this website until received 10 points... when this will happen, then i will post the picture

Results of running the RPi(running ssh,wospi,lighttpd) + Davis VPro2+ console (console added 300mA) + usb hub : after 20 hours on the battery , the battery voltage was dropped from 13.08v to 11.77v ! considering 10v as empty this means enough juice for at least 32 hours on a 5Ah battery total costs 30 usd, everything brand new


user7165, 11.7 V o/c is usually considered full discharge for a 12 V lead-acid. Discharging to 10 V will do it no good at all. - scruss
Simple and effective. Very nice +1 but just to add, those converters are very inefficient draining more battery than it should. - Piotr Kula
6
[+2] [2014-06-08 21:22:49] slado76

Here [1] is a supercapacitor based UPS solution for brown-outs and safe shutdowns.

The main difference to other UPS-like circuits is that there is no need to use batteries. This helps to avoid a lot of problems, like recycling the batteries after end of life, the energy is stored in the supercaps which are soldered to the PCB. Why not, when the lifetime of the supercaps is equal to the lifetime of the whole circuit board? You don't have to care about overcharcharging and all the temperature issues, like charging only at temperatures above zero. Supercaps hav no memory effect. They don't need discharge and charge cycles to keep them healthy.

On the other side: supercaps don't have the energy density of batteries, but the circuit should only backup short-term power failures or brown-outs. You really don't need a battery with 2000mAh capacity to backup 1A for a few seconds. Let us evaluate: 700mA for 30 seconds is 5.9mAh capacity you need at 5V. Have you ever seen a battery with this little capacity? Even if it would exist, you would never be able to draw 700mA out of such a small battery. In other words: battery based UPS for short time backup times ALWAYS use batteries with extremly oversized capacity. A supercapacitor is able to source a current of a few Amps even at very small capacities. I think therefore are batteries not the optimal energy storage device in this case.

One thing is bit complicated using supercapacitors: The voltage at the supercapacitor depends on the state of charge, so the need of a step-up/step-down converter makes the use a bit complicated if you think about DYI.

[1] http://www.juice4halt.com

(1) Welcome to Raspberry Pi! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. - Steve Robillard
7
[+1] [2013-01-22 07:24:30] ergosys

The LiPo Rider Pro [1] was meant for solar applications, but the USB port can also charge the battery, so you don't really need a panel. Coupled with a larger LiPo battery, it should keep the Raspberry Pi alive for a number of hours.

[1] http://www.seeedstudio.com/depot/lipo-rider-pro-p-992.html

(1) Yes I can confirm a lipo rider pro board from seeedstudio works like a charm. It has usb in + batter + solar charge if so desired. Single usb out. Basically takes main in if available, otherwise battery. All for under 20 dollars including battery. The only downside is its only 1amp out so if you have some usb devices drawing power, it may not supply enough. - David Lee
8
[+1] [2015-02-14 21:53:00] Mel

I'm kinda cross-posting this to all the UPS questions on this Stack Exchange because I was looking for something similar, and could never find any answers I liked, so I ended up researching it myself. You can use a standard, off-the-shelf UPS, and the Network UPS Tools (NUT) package to allow a Pi to shut itself down when the power goes out. I have just posted an article I wrote with step-by-step instructions for setting it up:

https://melgrubb.wordpress.com/2014/09/05/raspberry-pi-home-server-part-15power-failures/

Of course, if what you were really after was a DIY hardware project, then I'm afraid this doesn't involve any soldering.


Also running a RPI with a regular UPS is kinda like attaching a 5000 gallon tank in your Miata, when all you wanted was a Jerry can of extra gas for emergencies. - Riku L
9
[0] [2014-06-12 00:22:35] jet

You can try one of these, and use battery instead of super capacitor.Large Capacitor Replaces Backup Battery


According to Maxim's data-sheet the "690" is only capable of sourcing 50mA from Vout and it does not have a BATT_ON output that could be used to operate an external semiconductor switch (MOSFet ?). There are other ICs in the same product range that might be better suited to this role. - SlySven
10
[0] [2018-03-06 09:18:03] user149408

As others have stated, a USB power bank is an easy and fairly cheap solution. Be sure to get one which supports charging and discharging at the same time (which, unfortunately, isn’t usually indicated—you will have to figure that out).

The Pi typically draws anywhere between ~200 to north of 500 mA; for later models the maximum is 2000 mA. So a 6000 mAh power bank will give you anything from 3 hours to a day’s worth of battery power; make sure you get a power bank with sufficient capacity.

Plug your Pi into the output of your power bank and the charger into its input. If the power goes out, your Pi will keep on running until power is restored or the battery runs out.

Limitations are that the Pi has no way of knowing whether it’s running on AC or battery power, or how much battery power is left. Consequently, if the battery runs out before power is restored, the shutdown will be an unclean one.

A more advanced solution, also involving a power bank, is described at https://raspi-ups.appspot.com/en/index.jsp. It includes a daemon which uses the Ethernet connection to determine if it is running on AC—if the Ethernet connection drops, it assumes it is running on battery power. It measures the power consumption of the Pi and estimates the charge level of the battery based on consumption and total capacity (which needs to be configured beforehand). When power runs out, it shuts down the Pi cleanly.

As a variation of the above, if you have some USB peripheral hooked up to the Pi that runs on AC power, you could modify the daemon to use that as a power indicator.


11