Arduino Power Unit

Arduino Power Unit

I needed an uninterruptible power supply for an Arduino Microcontroller.

I wanted the Arduino to be powered by a 9V wall adapter with a backup 9V battery.

When AC power is available the unit will draw power from the wall adapter, if there is a power cut the unit will seamlessly switch to the battery as a power source and back when power is available.

I wanted various indicator lights as well such as during a power cut an LED will be lit to alert the user that mains power is not available. There will also be an LED to warn the user when the batteries are low.

The basic schematic below shows the principle of how the device will work. The device uses diodes to switch between mains and battery power. It will always use the side with the highest voltage and since the wall adapter will always have a higher voltage (≈9.3V) it will draw from that and not the battery (≤9V) but when the power goes out the adapter voltage falls to 0V and it draws from battery. There should be little to no leakage from the battery using this method.

The schematic below shows the final circuit on a breadboard. A0 is used to monitor the battery voltage level. D2 is used to light the battery low warning LED. When the power goes out the transistor acts as a NOT gate and powers a flashing LED to warn the user that the main power is gone.

The circuit requires:

  • Red LED
  • Flashing Red LED (or Red LED)
  • TIP120
  • 1Kohm Resistor (x4)
  • 220ohm Resistor
  • 1N4001 Diode (x2)
  • DC Barrel Jack

Below is the final circuit diagram which was designed in EAGLE.

I used EAGLE to design a Printed Circuit Board (PCB). EAGLE files:

I etched the PCB (I might write a post about how I did this in the future). Printable PDFs of the etching mask: full mirror.

The finished board can be seen below.

In order to use the battery monitoring and warning system the following code must be incorporated into your project.

#define Z1 1000.0
#define Z2 1000.0

const int batteryLed = 2;

void setup() {
pinMode(batteryLed, OUTPUT);
digitalWrite(batteryLed, LOW);

void loop() {
//The arduino uses a voltage divider to measure the voltage of the batteries used in the event of a power cut
//Measure the voltage of the 9V (Arduino) battery
float batVout = analogRead(A0) * (5.0/1023.0);
float batVin = (Z1 + Z2)/(Z2) * batVout;
//If the battery voltage is <=2V turn on the 9V battery low LED
if(batVin<=2){ digitalWrite(batteryLed, HIGH); } //If the battery voltage >2V turn off the 9V battery low LED
else if(batVin>2){
digitalWrite(batteryLed, LOW);


The schematics and code can be seen at


As always if you have any questions please don’t hesitate to ask,



This project was originally published on GitHub ( in July 2016.

From time to time I will republish some of my previous projects with extra information in order to maintain a consistent publishing schedule.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: