I have an arduino project that will work while plugged into a generic outlet. But I want to connect a battery in case the power goes out. I know there are various power sources (coin cell, polymer lithium, 9V, etc.). But if I code my project to use the backup power if the main power goes down, would that mean the backup always has to be running? How would I go about this?

Thanks for the help! Every time you help me you save a kitten!!


you could set up a relay to work in reverse with the mains power,

have your backup battery connected to the gate contacts of the relay, and then use the mains power running your project to open the relay and keep it open as long as there is power. if the mains turns off, then the relay closes and the battery is connected.

you might want to put something in line with the power to the arduino to make sure you don't get any spikes when things switch.

hope this helps as i love kittens

  • Thanks! I have to look into the code, but this sounds like a great possibility! Oct 6 '14 at 16:28
  • 1
    I doubt if a relay would work. It would cause a drop-out in power as it switched from mains to battery.
    – Duncan C
    Oct 7 '14 at 11:13
  • 2
    This needs a big capacitor, to survive the time it takes for the relay to throw.
    – Jasmine
    Oct 14 '14 at 22:55
  • @Jasmine what farad value would you recommend OP?
    – user400344
    Feb 14 '17 at 18:33
  • The cap would slowly eat the battery charge :/
    – user400344
    Feb 14 '17 at 23:21

I suggest this "Battery boost" circuit from AdaFruit. It's designed to do exactly what you describe. An Arduino needs a smooth, steady 5 V supply with no "blips". The AdaFruit unit does just that, and charges the battery while on Mains supply.


I have been looking into this myself. After getting some advice online I have come up with this circuit :

Comparator http://everycircuit.com/circuit/5059191601364992

The top left power source is the mains supply and the bottom left is the battery.

A voltage divider is connected to both that then feeds into an OPAMP comparator. For illustrative purposes there is a switch at the top left you can toggle to see the circuit in action.

When the mains power gets cut off the op amp comparator sends a logic level signal through the diode and into the mosfet which enables the battery circuit. the capacitor is there to keep power while the comparator makes the switch.

The link on every circuit is interactive, so feel free to have a play about with it. The LED represents your Arduino. The OpAmp is powered by the Positive and negative rails of thi diagram (impossible to draw on EveryCircuit)

Be sure to attach a voltage regulator to this circuit (at the input of the Arduino) so that the voltage doesn't change to your Arduino.

Here's where I researched about comparator OPAMPS ... Setting up a comparator OpAmp circuit

The LM358 is a good very cheap OPAMP for this circuit. All parts well sourced will cost you about £1 (or less).

Or if your battery is rechargeable you can try this circuit :

battery Backup Circuit 2 http://everycircuit.com/circuit/5232232327282688

Again this is just for illustrative purposes. You will need a 5V step-up converter to get 5v from a 3.7v battery. Also the battery I am using has a builtin protection circuit, if yours doesn't it's important you include it in your schematic.

Here's a video of it working for me with a 3.7V Li-Polymer Battery: https://www.youtube.com/watch?v=Sv2rjVqQg3U

  • Three problems: First, what powers the op-amp? Not that it can't be resolved, but you haven't specified. Next, you appear to back-drive the mains supply when it is unpowered - that may or may not work, for example, it may load the battery supply. Finally, you appear to be supplying either 5v or 9v, but the typical arduino does not have any power input which can accept both of those values and function as intended. Oct 7 '14 at 15:31
  • It's highly simplified due to a lack of components on Every Circuit. I would probably attach a voltage regulator in there. The OpAmp gets powered by the battery, the mains or the capacitor depending on the situation (ie its power is from the negative and positive rails on the diagram). I'm new to electronics, but I based this circuit off examples and advise from around the internet.
    – David Kerr
    Oct 8 '14 at 19:14
  • The point is that this can't be used without changes. Oct 8 '14 at 19:58
  • Feel free to draw up a circuit diagram for my benefit and for those reading this post.
    – David Kerr
    Oct 10 '14 at 13:45

You could solve this very simply with some diodes or get creative with a bridge rectifier. Connect both positive sources to the ac input one on each leg. then the positive side of the bridge rectifier would be your positive source. the grounds need to be all tied together


You can use https://www.regaldreamtech.com/micro-ups/ for the backup 5V power supply to Arduino in absence of main power. It has 5000mAh battery and 5V 2A output. It will handle the switching on its on between main and battery power.

Disclosure: We manufacture this product.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.