Project showcase

Simple Arduino Battery Capacity Tester © GPL3+

This tester can be used for NiCd, NiMh, and all flavors of Li-Ion rechargeables.

  • 12,202 views
  • 0 comments
  • 20 respects

Components and supplies

11113 01
SparkFun Arduino Pro Mini 328 - 5V/16MHz
Can be gotten just about anywhere online.
×1
20x4 LCD white on blue, with backlite
Original project used Nokia 5110 LCD. I don't have any on hand. I do have several of these....
×1
Fairchild semiconductor fqu13n06ltu image 75px
Power MOSFET N-Channel
Close enough, I used what I had on hand, an AO D3N50 HEXFET.
×1
I2C/twi/spi interface module for 20x4 LCD
Saves pins, and libraries work quite well with these.
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
Pppc081lfbn rc sml
Female Header 8 Position 1 Row (0.1")
Close. I bought several 20x1 sticks from eBay, and cut what I needed from them.
×1
terminal block two position
generic screw terminal block
×2
8 ohm 2w resistor
Needs to be at least 2W.
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×2
10722 01
Speaker: 0.25W, 8 ohms
×1
prototyping pc board
×1
wire
×1

Necessary tools and machines

09507 01
Soldering iron (generic)
solder
diagonal cutters

Apps and online services

About this project

This is actually a derivative work from one I found on the web. Just needed to get that out of the way. The original project can be found at: http://lazyelectronics.com/index.php/en/item/3-battester-en

Overview

I have, for a long while, avoided the use of Li-Ion type batteries, owing to the cost and special charging profiles needed. Now that the technology is more mature, I am venturing into their use.

Since my supply of cells will be primarily used stock from various recycle streams, I needed to come up with the tools to test each cell. With that in mind, here's my derivative of this tester.

What I did

The main changes I did are the 20x4 LCD rather than buying a Nokia 5110 that the original author used. I also used the I2C/TWI/SPI interface board for the LCD screen.

Note that the SCL and SDA pins are NOT broken out on the pro mini, they are on the A5 and A4 pins, as noted in the sketch.

Any MOSFET capable of 2.5A constant current or better can be used, best to use one with the lowest Rds on that you can. The one used here actually has a fairly high Rds on of 2.4 Ohm typical. This may actually skew the mAh results. This means that my cells may have a slight bit higher storage capacity than indicated. I had these on hand, left over from a previous project. This particular HEXFET/MOSFET is SMD, but the gate and source pins line up with the .1" spacing on a protoboard. Easy to solder, and even gives a few vias under the drain tab to add a heat sink under the board if needed.

Bad pic, and bad solder job... got it twisted a bit. The resistor is a pull-down on the gate.

The odd headers for the speaker and LCD are recycled from an old printer I tore apart. I used a 6 position female header section for the load resistor, so I can change the load if I need to. I just have to remember to change the code to match whatever I use. 3 position on each end are paralleled, so I can match resistance to whatever load mA I want to use according to the type of cell I'm testing.

Lower right screw block is for 5V power in, upper left block is test cell connection.

The rat's nest of point to point wiring to make the connections. Maybe I should have used several different colors to make it easier to trace should I have a problem later on.

The I2C/TWI/SPI interface board. Cheap on eBay, or Aliexpress, as long as you don't mind waiting 4-6 weeks for delivery. Can be bought anywhere worldwide online.

Second view of the LCD, showing the changes from the title image.

Still to do is a case for it, might even need to change the screw blocks out for something else.

Conclusions

Another thing I'm currently working on in this project is changing the button routine from polling to interrupt driven. I'm not a huge fan of using the delay function in coding unless absolutely needed. In this case, there are better ways to code for button presses. I'll also be looking for better ways to update the LCD.

If you build one of these, and make changes to the code along these lines, please let me know. We can compare notes, and make this a better project!

Code

Battery_Capacity_Check.inoArduino
/*
 * Li-Ion capacity tester.
 * set up:
 * 8 Ohm discharge load
 * ~190mA discharge rate.
 * I2C LCD.
 * MOSFET for discharge control.
 * 
 * software from e-battle.blogspot.com
 *
 * SCl pin = A5
 * SDA pin = A4
 *
 */


#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

//LCD set-up
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line lcd

// definitions

#define STATE_WAITING 0
#define STATE_MEASURING 1
#define STATE_MEASURING_ENDED 2
#define BAT_LI 0
#define BAT_NI 1
#define BAT_UNREC 2
#define BAT_LI_DISCHARGED 3

//variables

float vtgBatLoaded; //shows the drop in cell V under load
float vtgBatUnloaded; //cell V for no load
float vtgLoad;
float vtgDropOnLoad;
float vtgDropRin; 
float rLoad=8; //resistanse of the load in Ohms
float rIn; //calculated cell internal resistance
float batCurrent;
float mAh; //running total cell capacity
uint8_t FET_Base=7; //otherwise known as the Gate.
uint8_t button = 6; 
uint8_t speaker= 5;
uint8_t state=STATE_WAITING;
float LiChargedVtg=4.35;
float LiCutoffVtg=2.9;
float NiChargedVtg=1.45;  
float NiCutoffVtg=1.1;
float cutoff;
uint8_t BatteryType;
boolean DischargeAllowed=false;
String BatTypeString;

void setup()
{
  pinMode(FET_Base,OUTPUT);
  pinMode(button,INPUT); //can be changed in the circuit to active low,
                         // will need to turn on the internal pull-up
  pinMode(speaker,OUTPUT);
  digitalWrite(FET_Base,LOW);
  noTone(speaker);
  lcd.init();
  lcd.backlight();
}

void loop()
{
   if (state==STATE_MEASURING)
   {
  
  vtgBatUnloaded=analogRead(0)*5.0/1024.0; //get the voltage of UNLOADED battery
  
  if (vtgBatUnloaded<cutoff)
  {
    state=STATE_MEASURING_ENDED;
    DischargeAllowed=false;
    for (uint8_t i=0;i<4;++i)
    {tone(speaker,2000,500); delay(500);noTone(5);delay(300);}
  }
  digitalWrite(FET_Base,HIGH); //turn the MOSFET on
  delay(1000);
  vtgBatLoaded=analogRead(0)*5.0/1024.0;   //get the voltage of LOADED battery
  vtgLoad=analogRead(1)*5.0/1024.0;
  digitalWrite(FET_Base,LOW);//turn the MOSFET off
  vtgDropOnLoad=vtgBatLoaded-vtgLoad;
  if(vtgDropOnLoad>0) batCurrent=vtgDropOnLoad/rLoad;
   else batCurrent=0;
  vtgDropRin=vtgBatUnloaded-vtgBatLoaded;
  if(batCurrent>0) rIn=vtgDropRin/batCurrent;
  else rIn=0;
  mAh+=batCurrent/3.6; //*1000.0/3600.0;
  lcd.clear();
  lcdState();
    lcd.setCursor(0,0);
    lcd.print(" Bat   Load    I ");
  lcd.setCursor(0,1);
  lcd.print(vtgBatUnloaded); lcd.print("V  ");lcd.print(vtgBatLoaded); lcd.print("V  ");lcd.print(batCurrent); lcd.print("A");
  lcd.setCursor(0,2);
  lcd.print("Rin= "); lcd.print(rIn); lcd.setCursor(11,2); lcd.print(" Ohm");
  lcd.setCursor(0,3);
  lcd.print("Cap= "); lcd.print(mAh); lcd.print(" mA/h"); 
  delay(500);
   } 
   else if (state==STATE_WAITING)
   {
     digitalWrite(FET_Base,LOW);//turn the MOSFET off
     vtgBatUnloaded=analogRead(0)*5.0/1024.0; //get the voltage of UNLOADED battery
     DefBatteryType();
     lcd.clear();
     lcdState();
     lcd.setCursor(0,0);
     lcd.print("Bat= "); lcd.print(vtgBatUnloaded); lcd.print(" V");
     lcd.setCursor(0,1);
     lcd.print(BatTypeString);
     lcd.setCursor(0,2);
     lcd.print("Test ");
     if (DischargeAllowed) lcd.print("allowed");
     else lcd.print("denied");
     CheckButtons();
     delay(500);
   }
   else if (state==STATE_MEASURING_ENDED)
   {
     digitalWrite(FET_Base,LOW);//turn the MOSFET off
     vtgBatUnloaded=analogRead(0)*5.0/1024.0; //get the voltage of UNLOADED battery
     lcd.clear();
     lcdState();
     lcd.setCursor(0,0);
     lcd.print("Bat= "); lcd.print(vtgBatUnloaded); lcd.print(" V");
     lcd.setCursor(0,1);
     lcd.print("Cap= ");lcd.print(mAh); lcd.print(" mA/h");     
     CheckButtons();
     delay(500);
   }
}

void CheckButtons(void) {
   
   if (digitalRead(button)==HIGH){ // if changed to active low.....you know what to do!
    switch (state){
      
    case STATE_WAITING : DefBatteryType();
    if (DischargeAllowed){ mAh=0; state=STATE_MEASURING;
    tone(speaker,1000,500); delay(500);noTone(5);}
    break;
    
    case STATE_MEASURING : state=STATE_MEASURING_ENDED;
    break;
    
    case STATE_MEASURING_ENDED : state=STATE_WAITING;
    break;
   }
 }
 }


void lcdState(void){
   String stateString;
   lcd.setCursor(0,0);
   if(state==STATE_WAITING) stateString="Waiting       ";
   if(state==STATE_MEASURING) stateString="Measuring     ";
   if(state==STATE_MEASURING_ENDED) stateString="Measuring done";
   lcd.print(stateString);
 }
    
void DefBatteryType(void){
   
       if (vtgBatUnloaded>LiCutoffVtg&&vtgBatUnloaded<LiChargedVtg)
       {BatteryType=BAT_LI; DischargeAllowed=true;BatTypeString="Li-ion battery";cutoff=LiCutoffVtg;}
       if (vtgBatUnloaded>NiCutoffVtg&&vtgBatUnloaded<NiChargedVtg)
       {BatteryType=BAT_NI; DischargeAllowed=true;BatTypeString="Ni-MH battery ";cutoff=NiCutoffVtg;}
       if (vtgBatUnloaded<LiCutoffVtg&&vtgBatUnloaded>NiChargedVtg)
       {BatteryType=BAT_LI_DISCHARGED; DischargeAllowed=false;BatTypeString="Li-ion battery";}
       if (vtgBatUnloaded<NiCutoffVtg||vtgBatUnloaded>LiChargedVtg)
       {BatteryType=BAT_UNREC; DischargeAllowed=false;BatTypeString="UNKNOWN bat   ";}
 }

Schematics

battery tester
fritzing file for breadboard. I haven't changed it from the original with the Nokia 5110. I will need to make the part in fritzing, along with the I2C/TWI/SPI interface board.
BatTester.fzz

Comments

Similar projects you might like

High Precision Scale with Arduino

Project showcase by mPelectronic

  • 2,840 views
  • 11 comments
  • 19 respects

WIZnet S2E Deadbolts

Project tutorial by S2E Lock

  • 1,103 views
  • 2 comments
  • 7 respects

Super-Go: An Industrial IoT bot

Project tutorial by KS

  • 489 views
  • 2 comments
  • 5 respects

GPS Tracking System for Vehicles

Project showcase by Sustainable Living Lab

  • 3,906 views
  • 1 comment
  • 17 respects

Automatic Watering System

Project tutorial by Manson Hau

  • 5,481 views
  • 11 comments
  • 28 respects

DIY Photogrammetry Turntable

Project showcase by alfiosky4

  • 3,561 views
  • 5 comments
  • 10 respects
Add projectSign up / Login