How to Test a Battery




Introduction: How to Test a Battery


How to use Arduino with LEDs to show how much the power remain in the battery.

Material :

Arduino UNO x1 , Breadboard x1, LED x3, Jumper Wire x5, 330Ω Resistor x4, Battery x1

What is this ?

We use three LEDs to show how much the power remain as Low (only one LED lighted), Medium (two LEDs), Full charged(All LEDs). You will learn how to use analog pins to import data from outside of the board.

Step 1: Circuit

Step 2: Example Code

int LED1 = 8; //Set up pin 8,9,10 (the one connected to a LED) to be an output.
int LED2 = 9;

int LED3 = 10;

int Value = 0; //Set up for the value of analog pin.

float V = 0; //Voltage of the bettary

void setup() {

pinMode(LED1, OUTPUT); //The same as "pinMode(8,9,10, OUTPUT);

pinMode(LED2, OUTPUT);

pinMode(LED3, OUTPUT);


void loop() { BettaryRead(); // We're only "calling" the

// function here (telling it to run). The actual function code

// is further down in the sketch.



void BettaryRead(){

Value = analogRead(A0); //Read external voltages on the analog input

//and import the number into Value.

V = Value * 0.0048; //It returns an integer number that ranges from 0 (0 Volts) to 5115 (15 Volts), //so we do this to make the unit into Volt. }

void LED(){

if (V >= 1.5) { //If the voltage of bettary higher than 1.5, light up all LEDs. (High) digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);


else if (V < 1.5 && V >= 0.78) { //If the bettary is slightly used, light up two LEDs. (Mid)

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);


else if (V < 0.78) {

digitalWrite(LED3, HIGH); //If the bettary is almost die, light up one LED. (Low) }

else if (V <= 0) { //If the bettary died, turn all the LEDs off.

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW); }


Step 3:

Key Code :


We use this function to read the value on an analog pin.

What you Should See :

When the battery connected on Arduino, you should see LEDs are stably lighted.

Problems you might have :

1. If the LEDs were not lighted, check your circuit, especially the anode and the cathode of the LED.

2. If your LEDs are lighting randomly, you can use Serial functions to check the imported number from analog pin. The battery might not connect correctly or completely.

Be the First to Share


    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge



    6 years ago

    Good tip :)