Very simple Arduino Lithium-ion battery capacity tester/discharge monitor


This is a very simple capacity tester. It consists of single resistor that discharges battery. Arduino measures the voltage drop across resistor. According to Ohm’s Law current = voltage/resistance. Every second value of current is divided by 3600 and summed up to get the capacity expressed in Ah (Amp per hour).

I have used two parallel connected resistors that total resistance is 6.9 ohm. Make sure that they have proper power rating, if You don’t want them to convert to smoke. If voltage across 6.9 ohm resistor is  3.7 V, then current – 0.54 A, power ~ 2W.

Discharging of battery is manual process so please keep eye on it to make sure that battery is not overheating.

After start of discharging information about progress is transmitted via serial port and look like this.

Li-ion battery voltage will drop constantly to about ~ 2V. Li-ion batteries have integrated circuit to protect a cell that cuts off circuit to prevent from over discharging.

After voltage drop to 0, please disconnect battery, measurement is over.

During process of measurement please do not disconnect terminal from serial port, because Arduino could reset.

This method also can be used to measure a capacity of NiMh batteries, but these type of batteries doesn’t have IC, so user must manually stop measurement when voltage of one cell drops to 1.0 V or else batteries can be ruined.

A reference voltage of ADC of Arduino is 5V, so make sure that batteries voltage is bellow that value, or use voltage divider.

Program code bellow:


// Very simple Arduino Lithium-ion battery capacity tester
// from electronicsblog.net

#define LED 13
#define resistor 6.9

float capacity=0, value,voltage,current, time=0;

void measure (void) {

  value= analogRead(0);

  voltage=value/1024*5.0;

  current = voltage/resistor;

  capacity=capacity+current/3600;

  time++;

  Serial.print("Voltage= ");
  Serial.print(voltage);

  Serial.print("V Current= ");
  Serial.print(current);

  Serial.print("A Capacity= ");
  Serial.print(capacity);
  Serial.print("Ah ");

  Serial.print("Discharging time= ");
  Serial.print(time);
  Serial.print("s ");

  Serial.print("\n");
}

boolean x=false;

ISR(TIMER1_OVF_vect) {
  TCNT1=0x0BDC;
  x=!x;

  measure();

}

void setup() {

  pinMode(LED, OUTPUT);

  TIMSK1=0x01; // enabled global and timer overflow interrupt;
  TCCR1A = 0x00; // normal operation page 148 (mode0);
  TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
  TCCR1B = 0x04; // start timer/ set clock

  Serial.begin(256000);

};

void loop () {

  digitalWrite(LED, x);

};

Code here is  formatted by  using Arduino Code Syntax Highlighting Plugin.

1 second cycle is powered by hardware timer.

I had tested several used Li-ion batteries:

  • Nokia BL-4C 860 mAh: tested capacity 680 mAh, cut off voltage 2.25 V
  • Nokia BL-5J 1320 mAh: tested capacity 1100 mAh, cut off voltage 2.23 V
  • Panasonic DMW-BCG10E 895 mAh : tested capacity 880 mAh, cut off voltage 2.02 V
  • Unknown battery from chinese mp4 player: tested capacity 200 mAh, cut off voltage 2.54 V
  • TrustFire 18650 Lithium Battery 2500mAh from Dealextreme: tested capacity 2030 mAh, cut off voltage 1.10 V
  • Unknown battery from chinese keychain spy camera 8080 #8, acording to the manual 280 mAh: tested capacity 180 mAh, cut off voltage 2.53 V.
  • Michal

     Hi, I try to measure a battery with your program, but it doesn’t work. I copy your program to arduino enviroment, I connected a battery with resistor by your picture and when I open the program Terminal and I choose a right COM port and set baud rate and other things for communication I see nothing. The program writse nothing. The LED diode on the port 13 doesn’t light. Where is problem?
    Please, could you help me? Thank you.

    Michal

    • http://www.electronicsblog.net/ Darius

      Which Arduino board you are using?

      • Michal

         arduino duemilanove

        now I changed your code

        // Very simple Arduino Lithium-ion battery capacity tester
        // from electronicsblog.net
         
        #define LED 13
        #define resistor 7.9
         
        float capacity=0, value,voltage,current, time=0;
         
        void measure (void) {
         
          value= analogRead(2);
         
          voltage=value/1024*5.0;
         
          current = voltage/resistor;
         
          capacity=capacity+current/3600;
         
          time++;
         
         
         
         
        }
         
        boolean x=false;
         
        ISR(TIMER1_OVF_vect) {
          TCNT1=0x0BDC;
          x=!x;
         
          measure();
         
        }
         
        void setup() {
         
          pinMode(LED, OUTPUT);
         
          TIMSK1=0×01; // enabled global and timer overflow interrupt;
          TCCR1A = 0×00; // normal operation page 148 (mode0);
          TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
          TCCR1B = 0×04; // start timer/ set clock
         
          Serial.begin(9600);
         
         
         
        };
         
        void loop () {
         
          digitalWrite(LED, x);
         
          Serial.print(“Value= “);
          Serial.print(value);
         
          Serial.print(“Voltage= “);
          Serial.print(voltage);
         
          Serial.print(“V Current= “);
          Serial.print(current);
         
          Serial.print(“A Capacity= “);
          Serial.print(capacity);
          Serial.print(“Ah “);
         
          Serial.print(“Discharging time= “);
          Serial.print(time);
          Serial.print(“s “);
         
          Serial.print(“n”);

        };

        now it works for Ni-mh battery, but when I connect Li-Ion battery, it doesn’t measure and sometimes it measures something, or it writes in program Terminla some unread charts

        where is a problem?

        • http://www.electronicsblog.net/ Darius

           Maybe voltage on Arduino analog input exceeds 5V?

          • Michal

            I found it depents on type of battery. If I use a battery Olympus 3.7V 1000mAh, it works, but if I use a battery Hama 3.7V 1000mAh, Atmel on the Arduino board is very hot and it doesn’t work. I think you right analog input exceeds 5V.

  • Pingback: Tester baterii Li-Ion – już prościej się nie da … | YWD - blog

  • Pingback: Prosty tester baterii Li-Ion | Arduino

  • Pingback: DIY Li-Ion capacity tester and discharge monitor with Arduino « freetronicsblog