## Introduction: How to Test a Battery

INTRODUCTION

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

LED();

}

//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); }

}

Key Code :