Rechargeable Battery Capacity Tester




Posted in TechnologyMicrocontrollers

Introduction: Rechargeable Battery Capacity Tester

Do you have a pile of AA rechargeable batteries in your drawer? Some are old, some are new, but which sets would you bring with your camera on your next trip, and which ones are past their useful life? I like using rechargeable batteries, but I’m certain that some of them are not living up to the stated capacity on the label.

So how good are those batteries? Simple battery testers measure the voltage, but that’s not what we need – we want to find the overall capacity of the battery. How long will a battery last from the time it’s fully charged to the time that the “low battery” indicator comes on your device?

You can see this in action in a video in the last step of this instructable.

Step 1: This Is a Job for a Microcontroller

A simple way to test a battery would be to attach a load resistance to a fully charged battery and monitor the voltage until it drops below its useful value. The amount of time the battery lasts indicates its capacity.
That is a quick solution to the problem, but it involves watching a voltmeter for a few hours. That’s no fun at all. With a microcontroller, like the good old AVR chip, we can make a rechargeable battery tester that does the work for us. My tester puts AA batteries through a discharge test and reports the capacity in milliamp-hours (mAh) so you can compare battery capacity.

Design features
The tester can test multiple cells individually, and display the results on an LCD.
The tester discharges the battery while monitoring the voltage of the batteries. When the low threshold is reached, that cell is done it disconnects the load from the battery. When all tests are complete a series of beeps alerts the user. The tester identifies the type of battery by its initial voltage allowing both NiCd and NiMh batteries to be tested.

The design is based on the ATMega168 (or 328) microcontroller, which has 6 A/D converters on the chip, so these will be used to read the battery voltages and determine the load current. Since each battery will require two A/D converters per cell, the maximum number of cells is three.

I built two of the testers, first using an Arduino board as a development system, and then a standalone device that will be more compact, and free up the Arduino for other projects.

Step 2: Main Parts

Here's what you need:

  • An Arduino board
  • or a ATMega168 or 328p chip and associated parts for the standalone version - see the schematic for details.
  • A Nokia 5110 graphic LCD.
  • Three MOSFETs -- used to switch the resistive load on and off.
  • Resistors to discharge the battery
  • Resistors to interface to the LCD
  • A small speaker typically found in PCs.
  • Circuit Board or breadboard.
  • A holder for AA batteries. This has to be modified so that each cell is wired individually.
  • A case to house the project

Step 3: Circuit Design

The discharging circuit is relatively simple, each battery has a corresponding load resistor that discharges the battery when the FET is switched ON. The switching is controlled by the microcontroller. The microcontroller’s A/D converter is used to monitor the battery’s voltage. A second A/D converter is connected to the FET to determine the current going through the load resistor. The current is calculated by subtracting the FET voltage from the battery’s voltage, which results in the voltage across the resistor. Dividing by the resistance gives the discharge current. Multiply this by the time and you get the milliamp-hour value.

If you look at the code, you’ll notice that the math is not quite this straightforward. The microcontroller reads the battery status every second, calculates the amount of charge drawn during the past second and adds it to the total. In that short amount of time there is only a fraction of a milliamp-hour that has been used, so it would be rounded off to zero if we’re not careful with our integer math. So instead of tallying the number of milliamp-hours, I tally the number of microamp-hours. That will be 1000 times larger so no worries of rounding down to zero. When milliamp-hours are displayed, the charge is divided by 1000.
The code is well commented, so the details can be seen there.

Load resistor
The resistor needs to dissipate a bit of power, so size does matter in this case. Testing NiCd and NiMH batteries (1.2 volts) the power dissipation is under 1 watt, so choose a sufficiently large resistor, or several resistors in parallel. With the relatively large current, be sure to use thick wire for the discharge path.

I considered allowing testing of type 14500 Li-Ion batteries since they are AA size too, but the load resistor would need to be changed to a larger value to accommodate the higher voltage. When the battery is inserted, the program checks the battery voltage, and does not perform the test if detects a Li-Ion battery. If I didn’t do this, the load resistor would draw over 1400 milliamps, which is way over the maximum recommended discharge current of 450 milliamps. The resistor would (in theory) dissipate about 6 watts, and the aroma of smoke would fill the room. This emphasizes the need for your code to test and handle unexpected conditions! I could have designed a circuit to allow testing of Li-Ion batteries by adding an additional FET and load resistor, but I didn’t need this feature.

This component is like a switch. The output from the microcontroller controls the switch. When the output is high to the gate of the FET, it allows current to pass from the positive terminal of the battery, through the resistor, and the FET then completes the path back to the negative terminal. This discharges the battery over a period of time. I used a FET I salvaged from an old PC (partnumber IRL3103S). Any similar device should work as long as the Drain-to-Source On-Resistance is low. The 2M ohm resistor ensures the voltage read from an empty battery holder is zero volts. Without it, the A/D input will produce unpredictable results.

I used a LCD from a old Nokia 5110 cell phone which was a pain to wire up, but the good news is that the display is available in an easy to use board from Sparkfun - along with the other materials. The Arduino is running at 5 volts, but the display and the control lines need no more than 3.3 volts. There are several ways to accomplish this – I chose using resistors to form a voltage divider. The 1800 ohm and 3300 ohm resistors form a pair that divide the 5 volt outputs from the Arduino to the desired 3.3 volts. In the standalone version I kept the design the same. I could have lowered the microcontroller’s voltage - the AVR chip will run at a lower voltage - but that would cause other design changes, so I kept the same design. The display has a back light, so I wired it up through a current limiting resistor. The Nokia display is a bit mapped display, so I took advantage of that and made animated battery icons to show the status of the three cells. The PCD8544 library makes controlling the display a snap

The above diagram is a simplified schematic showing one of the discharge circuits controlled by the Arduino.

Step 4: Full Schematics

These schematics show the complete design - one design with the Arduino board, and one as a more compact and inexpensive standalone design.

Disclaimers and other notes

♦The accuracy of the tester won't be perfect, but it does give reasonable results that can be used and compared with other batteries so you can determine whether you want to keep a battery or get rid of it. Please dispose batteries properly.
♦The voltage drop across the FET should be negligible.
♦After the battery test is complete, the tester continues to display the voltage of the batteries – since the load is removed, the voltage will return to what will seem to be an acceptable voltage, but it the battery is really discharged.

♦ The pin numbering for the LCD has confused some readers - note that the LCD I used was pulled from an old cell phone, but if you buy an LCD from sparkfun it will have different numbers. Even comments in the PCD8544 library indicate another different numbering scheme - so just match the signal names and ignore the pin numbering.

Step 5: Source Code

I've uploaded the source code (.PDE file) for you to view and use.
(Update - the .PDE extension is what early Arduino development used. You can rename this to .INO for compatibility with the more recent development environment)
I have placed comments in the code for readability.

Step 6: Design of the Case

A case makes the project complete, and you can find many acceptable metal or plastic boxes. I chose to make one out of wood for a unique custom look. See the video at the end of this instructable for more info.

This part of the project took quite a long time, but I like how it turned out.

Step 7: Feature Upgrade - Because a Home Project Is Never Quite Done!

It was only a few days after completing the project that I realized I needed the ability to handle physically larger cells - in particular, the sub-C cells that I used in one of my other instructables. So I added a connector to the bottom of the device that simply gives access to the wires on two of the battery holders. So now I can test batteries that won't fit in the AA battery holder. When not in use, the alligator clips simply pull out from the recessed connector

Step 8: Video

Step 9: Other Sources for Battery Testing

This project was designed for electronics/microcontroller enthusiasts who wanted to make something that is also practical. However, not everyone has the time, interest and/or ability to build something like this, but do want the ability to test batteries.

The good news is that you can buy something similar like this for about $40. I have seen two such devices advertised on Amazon.
They both do battery discharge testing - and also serve as a charger.

AccuPower IQ-328 Battery Charger Analyzer Tester (AA AAA NiMH NiCd)
La Crosse Technology BC-700 (NiCd & NiMH AA/AAA)

I have no experience on either of these devices - so I won't personally recommend either them, but the Amazon reviews are generally positive.

6 People Made This Project!


  • Microcontroller Contest

    Microcontroller Contest
  • Woodworking Contest

    Woodworking Contest
  • Make it Move Contest

    Make it Move Contest

We have a be nice policy.
Please be positive and constructive.




I made this and made a couple of modifications; like others I modified the code to use the calculated VCC voltage as a reference but I used a decent quality regulator that output 4.998V which gives good results. I added some LED's as well to indicate battery & test status at a distance.

It works quite well but the biggest problem with accuracy was the voltage drop on the battery holder contacts and the wiring to the PCB. There was a drop of 300mV in some cases but even with this its enough to determine if a battery is bad or not. Good quality holders and thick wires would help improve it.

Great project!


I fully recreated your project. I have a lot of Ni-Mh rechargeable batteries that I want to test. My next challenge is to create another one for Lithium batteries. I updated the code using VREF Voltage as suggested in comments. I just need to test it properly and verify the accuracy of the tester! Thank you again to share you project.


Thanks guys for the helpful info. I wanted to ask if anyone has tried the project with a different type of LCD and which one they used

I suspect the method is flawed. You're sampling the voltage at each end of the load resistor: FET drain end and also battery end. I think you use the difference to calculate the V drop across the load. I accept that this is correctly going to give you the V drop across the load, but I don't think that's the information you need. I suspect you really need the total V drop across the load and the FET all the way down to ground. The ground is, of course, 0V. So the Vdrop need only be measured at the cell itself. I don't see the need for the voltage measurement at the FET drain. I think we can get better results with only a single ADC per cell.

1 reply

Ahhh. Unless your FET's not grounding the resistor?

hi, this is great project

does author or anybody have modification this code for 16x2 lcd or 20x4? or can modify it and share? it could be only for one battery for me
i am beginner and try do this but no results

Wondering if anyone could offer me advice - wired as diagram - 2.2ohm load resistor, 1.25V NiMH AAA battery (voltage measured by multimeter), F12N1OL FET.

Arduino reads around 0.9V and calculated current to be around 380mAh - measured current is 125ma with multimeter and battery voltage around 1.25V.

Load resistor confirmed at 2.2Ohm on multimeter.

Total resistance battery --> load resistor -->fet --> ground (when fet held at 5v manually) is 6Ohms

Tried adjusting ardunio programme to 6Ohm load but didnt make any more accurate with voltage.

What am I doing wrong?

many thanks

4 replies

What is the Battery Tester telling you? Is it reporting "Test complete" too soon? What does it report as mAh capacity.

You mentioned that you were testing AAA battery - that may require a different load resistor.

I couldn't find any specs on the FET you are using - what is the "Drain-to-Source On-Resistance" rating? It should be very low (the part I used has a 16 milli-ohm rating).

I see that the F12N10L spec says 200 milli-ohms and the FQP30N06L says 35 milli-ohms. I would think this is probably OK.

You said "Total resistance battery --> load resistor -->fet --> ground (when fet held at 5v manually) is 6Ohms"

How did you get this number?

Since you are testing lower capacity AAA batteries instead of AA batteries, I would try reducing the load by changing the resistor to 7 ohms (the 2.5 ohms is drawing too much power) This will reduce the drain to about 171 mA which is more appropriate for the smaller cell. Be sure to change the code to match the resistor's actual value (not the sum of resistor plus FET).

This would explain the lower than expected voltage displayed, and why the tester is stopping early (this is protection from over-discharging which is bad for batteries). I would expect about 300mAh for Ni-Cads and 600 to 800 for NiMh AAA calls (depending on manufacturer and age). Also: Be sure to use thick wire for the discharge path.

Thanks for your advice.

I changed the resistor to a 10ohm one and updated the LOAD_RESITANCE to 10 accordingly. (I am using a 1M ohm resistor rather than 2M as a pull down)

At rest, the multimeter reads the AAA battery as 1.26v (NiMH 550mAh)

Using F12N10L:

The arduino program reads 0.78V after the 'detecting' phase (multimeter reads 1.25v) which pretty much instantly ends with the screen saying 0 mAh and then jumps to 1.33-1.34 at the 'test complete' phase (multimeter back to 1.26v).

If I apply 5v manually to the gate and measure current flow from the battery, draw is about 60mA

If I run 5v through the gate while the arduino is in the 'test complete' phase, the arduino calculated voltage is displayed at 0.3-0.6v whilst the multimeter reads a steady 1.25v on the battery.

Using the FQP30N06L, the same thing happens though it reads a voltage of 0.439v at the test phase before rapdily stopping and reading 1.36v

I really can't figure out what I'm doing wrong.

Nice project!

But there is a little indistinctness:

It is assumed that the VREF Voltage is permanently 5V, but this would never happend! (Depends on the power supply....)

Remedy: Use the internal VREF 1.1V and use the variable:

Code getting the real internal voltage (sorry, original author is unknown to me):

long readVcc() {

// Read 1.1V reference against AVcc

// set the reference to Vcc and the measurement to the internal 1.1V reference

#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);

#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)

ADMUX = _BV(MUX5) | _BV(MUX0);

#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)

ADMUX = _BV(MUX3) | _BV(MUX2);


ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);


delay(2); // Wait for Vref to settle

ADCSRA |= _BV(ADSC); // Start conversion

while (bit_is_set(ADCSRA,ADSC)); // measuring

uint8_t low = ADCL; // must read ADCL first - it then locks ADCH

uint8_t high = ADCH; // unlocks both

long result = (high<<8) | low;

result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000

return result; // Vcc in millivolts


So with this function you get back a int value like 4988 (4,98V), so you have to exchange in the code the lines like:

[482] return map(analogRead(battery[batteryNum].batteryVoltagePin), 0,1023,0,5000);


return map(analogRead(battery[batteryNum].batteryVoltagePin), 0,1023,0,readVCC());

2 replies

Hi matthiasl2,

Great modification, much more accurate and easier than changing 5000 in code !

I modified like this

long readVcc() {
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
long result = (high<<8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
return result; // Vcc in millivolts


return map(analogRead(battery[batteryNum].batteryVoltagePin), 0,1023,0,readVcc());


return map(analogRead(battery[batteryNum].fetVoltagePin), 0,1023,0,readVcc());

Thx !!!! :)

Would it be possible for You to post the entire code with the changes?

This looks like a similar product:

Want to ask if this circuit (project) charges and then discharges the battery? And if yes, can I make multiple desired amount of cycles of charging discharging process?

1 reply

It does not charge the battery. It discharge it.

By discharging, it can measure the battery capacity.


I was able build it, however when not using 1 battery (1 transistor) it shows the other 2 are not connected, but it shows nore than 1V and the mAh start to increment even if there's no battery in the compartment.

Any help will be appreciated.


1 reply

hi, im doing this project too and have a arduino uno. I have download the pde but when i try upload to arduino apear this:
can help?

Sem T&#65533;&#65533;tulo-1.jpg