 What if you made a home security system and the power goes out? Sure you do not want your system to shutdown. Keeping this consideration in mind, it is necessary to add backup battery circuitry to all your projects that require uninterrupted power. There are multiple ways to do this, and I will cover the most important ones below.

Before going further, let us recall some basic laws of battery combination which will come handy later:

• When connected in series, voltages are added.
• When connected in parallel, capacities are added.
• Mixing different batteries, whether in parallel or in series, is a bad idea. Ensure that when combining batteries, they are of the same manufacturer, model, voltage and current capacity. Do not connect old and new batteries together.

For a backup battery circuit, we desire that along with a large primary battery or mains power, there must be a smaller secondary battery (of same voltage) that takes over when the primary source goes below a certain voltage or shuts down.

How do we do that? By connecting the backup battery in parallel with the primary source! But wait. Didn't I just tell you to not connect two sources of different capacity together? However, there is a clever way to do this. If we can prevent the batteries from discharging into each other (which is exactly what happens when you connect two sources of different capacity together) we can connect two sources of different capacity together. To do this we use two diodes, that prevent current from flowing from one battery to another.

This is how our present arrangement looks like:

However, there is one more problem. As both sources are of the same voltage, they will supply the load simultaneously, in the ratio of their capacities. This means both the batteries will get depleted simultaneously. But, we do not want that. We want the backup battery to kick in when the primary dies. To accomplish that, we vary the voltages of the two sources slightly (to be on the safe side, one volt will do). Here is the updated circuit:

The voltage of source A is 11V while source B is 12V. Let us assume that the voltage drop of the diode is 0.7V. Since the voltage of battery B is the greater of the two, battery B is supplying current to the load. The voltage at the load is 12.0 – 0.7 = 11.3V.

The anode of diode A is at 11V (voltage at battery A).
The cathode of diode A is at 11.3V (voltage at the load).
Hence the cathode of diode A is 0.3V higher than its anode. Hence diode A is reversed biased. This ensures that the higher voltage will supply the load.

A 1 uF capacitor can be added in parallel with D2, between battery + and load, to provide the voltage for a fraction of a second for the circuit to change over to battery power.

If you are using rechargeable batteries, you may want to have a current limiting resistor R in parallel with D2 between battery + and primary + that provides a very small trickle charge to the battery. This ensures that the battery will always remain in a charged condition. (Source)

The charge carrying capacity C of the battery determines the value of the resistor R. Databooks recommend the ideal current to be equivalent to the C/10 rating of the battery.

The only consideration left is the voltage drop of the diodes, which is generally between 0.4-0.7 V. If powering a high power circuit, this small voltage drop can cause wastage of power.

If the voltage drop is a problem, ideal diodes with ~0 Voltage drop can be constructed using MOSFETs as explained here.