Introduction: Easy Arduino Battery Tester

This is a simple circuit made with a Arduino Uno making a battery tester that returns a battery charge value to the computer.

Supplies

  • 10K Resistors (3)
  • Jumper Wires (12)
  • Red LED Light (1)
  • Yellow LED Light (1)
  • RGB LEB Light (1)
  • Alligator cable/clips (2)
  • Battery
  • Battery case (1)

Step 1: Build the Circuit

Step 2: Write the Code

int value =0; // the "charge" of the battery

void setup() {

Serial.begin(9600);

pinMode(11,OUTPUT);

pinMode(10,OUTPUT);

pinMode(9,OUTPUT); // sets the pins to either output or return values

pinMode(A0,INPUT); }

void loop() {

value=analogRead(A0); //reads the battery value from A0

Serial.println(value); //prints the battery "value" to the computer

if (value>=290) //if the charge is high it turns the light green

{

digitalWrite(11,HIGH);

digitalWrite(10,LOW);

digitalWrite(9,LOW);

} else if (value>=180 && value<=289) //if the charge is in between the two values it turns on the yellow light

{

digitalWrite(10,HIGH);

digitalWrite(11,LOW);

digitalWrite(9,LOW);

} else if (value<=179) //if the charge is low it turns on the red light

{

digitalWrite(9,HIGH);

digitalWrite(10,LOW);

digitalWrite(11,LOW);

} }