Arduino Battery Tester

The Arduino battery tester is a pretty cool nifty tool that you can use to check how charged a battery is. This is perfect for anyone who wants to know roughly how long a battery has left before it runs out of charge.

This is a pretty barebones beginner Arduino project but it could be extended to be a proper setup.  I go into detail at the end of the tutorial on how you could extend this project one step further.

If you want to see how this done visually then be sure to check out my video below. I go through all the steps required to getting this cool battery project up and going. If you like the video, then please make sure to subscribe so you can get more great Arduino Projects.


The equipment that I use in this Arduino battery tester project are listed below. If you already have a starter kit, then you should have most of the equipment already (With the exception of the Zener diode).

Arduino Uno

1x Green LED

1x Yellow LED

1 x Red LED

1x 5.1k Zener Diode

3x 100 ohm resistors

1x 2.2k ohm resistor


Breadboard wire

Assembling the Arduino Battery Tester Circuit

This battery tester circuit is pretty easy to put together. If you are completely new to the Arduino then I highly recommend check out my guide that explains what an Arduino is. If you have been following my tutorials, then you will notice we’re using a new component called the Zener diode.

The Zener diode will allow you to test batteries that have a voltage greater than 8 volts. A Zener diode works by allowing current to flow in one direction until it hits the breakdown voltage (limit on the diode, in our case it is 5.1 volts). Once it hits this limit it allows voltage to go in the reverse direction. This can help protect parts that can only handle a certain amount of voltage. In our case the Arduino.

The 2.2k ohm resistor reduces the current coming from the battery to something that the Arduino will be able to take in. If your current is too high, then it may damage your Arduino.

The circuit also has 3 different LEDS, each of these LEDs represents roughly how much charge there is left in the battery. Red will represent the battery is low/almost dead. Yellow will represent the battery being roughly half used up. Finally, the green will represent the battery being full. For each of the LEDS we connect up 100-ohm resistor from the ground pin to the ground connection so we don’t burn out the LEDS. This would very similar to what we did in the Arduino traffic light tutorial.

I will now quickly go through the steps of putting this together below. Underneath the instructions you will find a circuit diagram if you find it easier just following that.

1. Wire the ground pin on the Arduino to the ground rail on the breadboard.

2. On the breadboard place the green, red and yellow LED’s. Connect the ground pins to the ground rail.

3. Place a 100-ohm resistor onto positive end of the LEDS then hook a wire from resistor to the relevant pins on the Arduino.

The following LEDS should connect to the relevant pin numbers.

  • Red LED = 4
  • Yellow LED = 3
  • Green LED = 2

4. Now connect from analogue pin 0 (A0) to the breadboard. After this add a 2.2k resistor and the Zener diode (with the line on Zener diode facing towards the Arduino). Finally have a loose wire coming from the other end to diode.

5. Finally have a loose wire connected to the ground rail

Arduino Battery Tester Circuit

The code

The code for this Arduino battery capacity tester project is pretty straight forward but I will explain each bit so you’re able to understand what we’re doing. If you just want the code and no explanations, then you can download it here.

Firstly, we need to setup all our variables, the LED’S variables are all assigned to their relevant pin number mentioned earlier.

The analogueValue variable is where we will be storing the value that comes from the analogue input. We then do a calculation (Which I will explain later) and store the resulting number into a variable called voltage.

Finally, ledDelay is how long you want the LEDS to remain on before switching off.

int greenLed = 2;
int yellowLed = 3;
int redLed = 4;

int analogValue = 0;
float voltage = 0;
int ledDelay = 1000;

The setup function is called once and the perfect place to setup all our pins. In this particular program we only need to setup all our LED pins as outputs.

void setup()
  pinMode(greenLed, OUTPUT);

Inside the loop function we will do a couple of things. Firstly, we read the analogue pin, the value from this pin will be between 0-1023. We will need to do a calculation to convert this to a variable so we simply multiply the analogueValue by 0.0048 to do this.

void loop()
  analogValue = analogRead(A0);
  voltage = 0.0048*analogValue;

This last part we compare our calculated voltage and compare this to our defined voltage values. Whenever the voltage falls between a set of values we simply turn the relevant LED. You can change voltage variables to get the LED’s to display how you like.

  if( voltage >= 1.6 )
    digitalWrite(greenLed, HIGH);
  else if (voltage > 1.2 && voltage < 1.6)
    digitalWrite(yellowLed, HIGH);
  else if( voltage <= 1.2)
    digitalWrite(redLed, HIGH);  
  digitalWrite(redLed, LOW);
  digitalWrite(yellowLed, LOW); 
  digitalWrite(greenLed, LOW);

Once you are done with the circuit simply plug the Arduino into a computer and upload the code. Once this is done we can continue onto testing and checking that it is working correctly.

Testing it all

When you first turn on and deploy the new code to the Arduino you will notice that it keeps jumping between the LED’s. This is because the analogue input wire is floating and picking up noise causing our program to detect false positives. To stop this, you can simply ground the analogue wire to the ground rail when not in use. You can also try grounding the other analogue pins to help reduce amount of noise it’s picking up.

To test it, all you need to do is hook up a battery to the two wires. Place the ground wire to the negative end of the battery and the positive wire to the positive end of the battery. The Arduino should pick up the voltage and tell the relevant LED to light up.

If it doesn’t then have a look at adding some debug lines for the battery input. This should tell you if there is something wrong with reading the input or there is simply a mistake for displaying the LEDS.


Now this tutorial just covers the very basics of this project. You could extend it to be a lot better and to be more of a permanent device that you can use day to day.

You could print the output to an LCD screen connected to the Arduino. This can give you a lot more accurate information since we can write values to a screen. I will be going into how to setup a LCD screen with the Arduino in the near future.

You could also add a proper battery holder instead of using the two wires to check the life of the battery. This will probably make it a bit safer and make it look more like a professional battery tester unit.

To go with the battery holder a nice solid case would work well. Having the ability to 3d print one would be perfect for achieving this.

Having a battery pack for the Arduino so that it could be portable would make it perfect for anyone who needs test batteries but aren’t near a local power source. Like the LCD screen I will be going into depth soon how you could set this up.

I hope you have been able to build this basic but cool Arduino battery tester. If you have come across any issues or anything else you would like to share then feel free to drop a comment below.

Subscribe & Get 21 Awesome Arduino Projects

Enter your email below to get instant access to 21 amazing Arduino projects.

Please check your inbox or junk mail for a confirmation email!