Single Cell Battery Tester
Fun projects from beginner to advanced

 
Single Cell Battery Tester

Single Cell Battery Tester

Sick of wondering if your battery is flat or not? Build this battery tester for AA, AAA, C, & D cell batteries.

This device takes a reading from the ultrasonic sensor. The Arduino then processes that information and outputs the preset distances onto the LED's and also outputs an audible sound.
Warning!! This battery tester can only test 1.5v batteries!
This project needs:
* Arduino Uno x 1
* Breadboard x 1
* LED's x 3(1 red,1 yellow,1 green)
* Resistor 560 ohm x 3
* Resistor 2.2k ohm x 1
* Assorted jumper cables
* Battery holder (optional)

Connecting it up

Single Cell Battery Tester

Electrical Diagram

Simple Distance Sensor Electrical Diagram


Programming
You can copy and paste this code into the Arduino IDE or write it yourself.

/*
* Single-Cell Battery Tester 
* :-this program takes the voltage level of the battery
* and shows a green led for full charge, yellow and green for ok, 
* yellow for medium charge, and red for no charge.
* Code by intRobotics
* references: http://www.instructables.com/id/Arduino-Battery-Tester/
*/

#define greenLED 4  // green LED pin
#define yellowLED  7  // yellow LED pin
#define redLED 8  // red LED pin

int ledtime = 100; //time led stays on for (milliseconds)
int analogBatteryValue = 0; // analog read input
float voltage = 0; //calculated voltage

void setup()
{
  pinMode(greenLED, OUTPUT);  //setup led pins
  pinMode(yellowLED, OUTPUT);
  pinMode(redLED, OUTPUT);
}
void loop()
{
  /*
  * arduino = 5v 
  * therefore 5 volts/1024 analog values = 0.0048 
  * 0.0048*analog input = voltage
  */
   analogBatteryValue = analogRead(0); //read analog data and store in variable
   voltage = 0.0048*analogBatteryValue; //calculate voltage
  
   if ( voltage >= 1.6 ) //if voltage is good display green
  {
    digitalWrite(greenLED, HIGH);
    delay(ledtime);
    digitalWrite(greenLED, LOW);
  } 
     
  else if ( voltage < 1.6 && voltage >= 1.5 ) //if voltage is almost full display green and yellow
  {
    digitalWrite(yellowLED, HIGH);
    digitalWrite(greenLED,HIGH);
    delay(ledtime);
    digitalWrite(yellowLED, LOW);
    digitalWrite(greenLED,LOW);
  } 
  
   else if ( voltage < 1.5 && voltage > 1.4 ) // if battery is half full display yellow
  {
    digitalWrite(yellowLED, HIGH);
    delay(ledtime);
    digitalWrite(yellowLED, LOW);
  } 
  
  
   else if ( voltage <= 1.4 ) //display red if voltage is below 1.4 volts (ie. flat battery)
  {
    digitalWrite(redLED, HIGH);
    delay(ledtime);
    digitalWrite(redLED, LOW);
  }
}


Technical stuff
Warning!! This battery tester can only test 1.5v batteries!
This battery tester is a simple example of inputs and outputs on the arduino board. The 3 LEDs are outputs and the Positive pin on the battery is the input.

Lets start with the input:
To read the voltage of a 1.5v battery we need to do a few things:
* limit the current flow from the battery to the arduino board
* setup an analog pin to get a voltage reading

We need to limit the current flow from the 1.5v battery because we are feeding an external voltage supply into the arduino board. So we'll put a current limiting resistor in the circuit to make sure that our board doesn't go up in smoke.
We are using a 2.2K ohm resistor here because it will make the current flow small enough not to worry about.
Some simple math:
*1.5v battery (average voltage)
*2.2K ohm resistor
rule: I = V/R
I = 1.5/2200
I = 0.00068 amps

Now we have limited the current flow we can connect the battery up to the analog input pin on the Arduino board.
The analog inputs have a raw value range of 0-1023 (1024 values), this is determined by a voltage scale of 0-5 volts (0v=0, 5v=1023).
Because we will be reading a raw value we need to convert that back into voltage.
Some more simple math:
* Arduino = 5v
* 1024 analog values
therfore:
5/1024 = 0.0048
Now we have our scalar = 0.0048
To work out the battery voltage we multiply the scalar by the analog input value
analog read value x 0.0048 = battery voltage

example:
if we get an analog reading of "320"
we do our equation 320 x 0.0048 = 1.536 volts


Lets look at the Outputs:
The LEDs are simple, all we are saying to the arduino is "turn on this LED when the voltage of the battery is this voltage"
So we have set it up as:
* 1.6v = New battery (green LED only)
* 1.5-1.6v = slightly used battery (green and yellow LED)
* 1.5v = used battery (yellow LED only)
* 1.4v = flat battery (red LED only)

You can make this scale as accurate as you want, you can add more LEDs, and more statements for voltage levels.

Project complete!
Now you can test any 1.5v battery you want!

PCB - Arduino UNO

References

* Arduino Battery Tester: http://www.instructables.com/id/Arduino-Battery-Tester/

 
     

© Copyright intRobotics. All Rights Reserved.