Lithium Ion 18650 Battery Capacity Checker

Posted on 23/01/2016 by Adam

I created this fairly simple circuit and Arduino sketch to check the labeled capacity of Lithium Ion 18650 batteries. It could easily be adapted to other types of batteries and discharge more than one battery at a time. If you power your arduino from a computer and monitor the serial port you can obtain results as it goes along and create pretty graphs of the results. http://admw.uk/iB

The Code…

[code]
/*
* Battery Capacity Checker
* Uses Nokia 5110 Display
* Uses 1 Ohm power resister as shunt – Load can be any suitable resister or lamp
*
* YouTube Video: https://www.youtube.com/embed/qtws6VSIoYk
*
* http://AdamWelch.Uk
*
* Required Library – LCD5110_Graph.h – http://www.rinkydinkelectronics.com/library.php?id=47
*/

#include "LCD5110_Graph.h"
LCD5110 myGLCD(5, 6, 7, 9, 8); // Setup Nokia 5110 Screen SCLK/CLK=5, DIN/MOSI/DATA=6, DC/CS=7, RST=9 Chip Select/CE/SCE=8,
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];

#define gatePin 10
#define highPin A0
#define lowPin A1

boolean finished = false;
int printStart = 0;
int interval = 5000; //Interval (ms) between measurements

float mAh = 0.0;
float shuntRes = 1.0; // In Ohms – Shunt resistor resistance
float voltRef = 4.71; // Reference voltage (probe your 5V pin)
float current = 0.0;
float battVolt = 0.0;
float shuntVolt = 0.0;
float battLow = 2.9;

unsigned long previousMillis = 0;
unsigned long millisPassed = 0;

void setup() {

Serial.begin(9600);
Serial.println("Battery Capacity Checker v1.1");
Serial.println("battVolt current mAh");

pinMode(gatePin, OUTPUT);
digitalWrite(gatePin, LOW);

myGLCD.InitLCD(); //initialize LCD with default contrast of 70
myGLCD.setContrast(68);
myGLCD.setFont(SmallFont); // Set default font size. tinyFont 4×6, smallFont 6×8, mediumNumber 12×16, bigNumbers 14×24
myGLCD.clrScr();

myGLCD.print("Battery",CENTER,0);
myGLCD.print("Check",CENTER,12);
myGLCD.print("Please Wait",CENTER,24);
myGLCD.print("AdamWelch.Uk",8,40);
myGLCD.update();
delay(2000);
myGLCD.clrScr();
}

void loop() {

battVolt = analogRead(highPin) * voltRef / 1024.0;
shuntVolt = analogRead(lowPin) * voltRef / 1024.0;

if(battVolt >= battLow && finished == false)
{
digitalWrite(gatePin, HIGH);
millisPassed = millis() – previousMillis;
current = (battVolt – shuntVolt) / shuntRes;
mAh = mAh + (current * 1000.0) * (millisPassed / 3600000.0);
previousMillis = millis();

myGLCD.clrScr();
myGLCD.print("Discharge",CENTER,0);
myGLCD.print("Voltage:",0,10);
myGLCD.printNumF(battVolt, 2,50,10);
myGLCD.print("v",77,10);
myGLCD.print("Current:",0,20);
myGLCD.printNumF(current, 2,50,20);
myGLCD.print("a",77,20);
myGLCD.printNumI(mAh,30,30);
myGLCD.print("mAh",65,30);
myGLCD.print("Running",CENTER,40);
myGLCD.update();

Serial.print(battVolt);
Serial.print("\t");
Serial.print(current);
Serial.print("\t");
Serial.println(mAh);

delay(interval);
}
if(battVolt < battLow)
{
digitalWrite(gatePin, LOW);

finished = true;

if(mAh < 10) {
printStart = 40;
}
else if(mAh < 100) {
printStart = 30;
}
else if(mAh <1000) {
printStart = 24;
}
else if(mAh <10000) {
printStart = 14;
}
else {
printStart = 0;
}

myGLCD.clrScr();
myGLCD.print("Discharge",CENTER,0);
myGLCD.print("Voltage:",0,10);
myGLCD.printNumF(battVolt, 2,50,10);
myGLCD.print("v",77,10);
myGLCD.setFont(MediumNumbers);
myGLCD.printNumI(mAh,printStart,21);
myGLCD.setFont(SmallFont);
myGLCD.print("mAh",65,30);
myGLCD.print("Complete",CENTER,40);
myGLCD.update();

delay(interval * 2);
}
}

[/code]

Schematic
arduino-lithium-capacity-checker-v1-0_schem
You’ll have to forgive the simple nature of this schematic – It’s my first time using Fritzing schematics.

Parts list (Ebay affiliate links)

Nokia 5110 Module: https://goo.gl/vl9rY9
Arduino Nano Clone: https://goo.gl/lgAAdC
1 Ohm 10w Resistor: https://goo.gl/enzsns
Aluminium Clad Power Resistor: https://goo.gl/21t4VI
IRF3205 Mosfet: https://goo.gl/eepYsc
Prototyping PCB: https://goo.gl/hSqjwP
Terminal Blocks: https://goo.gl/GmWAVr