user4245: 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!!

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

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 :

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

user2967: 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.

user4244: 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

4245: <p>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 (<a href="https://www.sparkfun.com/products/337" rel="noreferrer">coin cell</a>, <a href="https://www.sparkfun.com/products/8483" rel="noreferrer">polymer lithium</a>, <a href="https://www.sparkfun.com/products/10512" rel="noreferrer">9V</a>, 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?</p>

<p>Thanks for the help! Every time you help me you save a kitten!!</p>
 3793: <p>I have been looking into this myself.  After getting some advice online I have come up with this circuit :</p>

<p><img src="https://i.stack.imgur.com/CU9E5.png" alt="Comparator">
<a href="http://everycircuit.com/circuit/5059191601364992" rel="nofollow noreferrer">http://everycircuit.com/circuit/5059191601364992</a></p>

<p>The top left power source is the mains supply and the bottom  left is the battery.</p>

<p>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.</p>

<p>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.</p>

<p>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)</p>

<p>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.</p>

<p>Here's where I researched about comparator OPAMPS ... <a href="http://www.dummies.com/how-to/content/electronics-components-how-to-use-an-op-amp-as-a-v.html" rel="nofollow noreferrer">Setting up a comparator OpAmp circuit</a></p>

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

<p>Or if your battery is rechargeable you can try this circuit :</p>

<p><img src="https://i.stack.imgur.com/fXiGI.png" alt="battery Backup Circuit 2">
<a href="http://everycircuit.com/circuit/5232232327282688" rel="nofollow noreferrer">http://everycircuit.com/circuit/5232232327282688</a></p>

<p>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.</p>

<p><strong>Here's a video of it working for me with a 3.7V Li-Polymer Battery:</strong>
<a href="https://www.youtube.com/watch?v=Sv2rjVqQg3U" rel="nofollow noreferrer">https://www.youtube.com/watch?v=Sv2rjVqQg3U</a></p>
 2967: <p>I suggest this "<a href="http://www.adafruit.com/products/1944" rel="nofollow">Battery boost</a>" 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.</p>
 4244: <p>you could set up a relay to work in reverse with the mains power, </p>

<p>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. </p>

<p>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. </p>

<p>hope this helps as i love kittens</p>
