Show by Label

Sunday, March 24, 2019

A pretty universal battery profiler

Recently, I had a number of Li-Ion and LiPo cells fail on me, and I also suspected a very poor capacity from many of my NiMh cells. Using a method that I concocted earlier with a Raspberry Pi and an ADC was too much trouble and it did not really give me what I want. That method is described in one of my other posts.

The units you can buy give you a mAh number, but don't give you a graph, which is what I really wanted.
I also did not want to buy something that I can build, so I started a Google tour to find a design to my liking.
It took a while because most designs that I found were too rudimentary. My philosophy is that when you decide to build something, you might as well do it right.

The design that I eventually found that was even beyond my expectations can be found here :

This is a very complete instrument that comes with a very nice PC program to show the discharging graphs, great for documentation, and you can also drive the testing tool with it. I have never written an application that runs on a Windows PC, so I was delighted with this solution. I normally save data in a CSV format and use Excel to create graphs. This program is so much better!

The only initial downside was the hardware in terms of size. I don't have enough room, and I only build instruments in cases when I use them a lot.

Hardware changes and improvements
Very quickly though, I saw some simple improvements to the hardware that John Lowen, the original designer, used. I decided to use an Arduino Nano board as the processor. The good news is that it already comes with a serial to USB interface, and the power for the whole kit can be supplied from this USB link as well. I also wanted to reduce the foot print of the board I was going to use, so instead of a traditional 20x2 LCD, I opted for an inexpensive Nokia 5110 LCD display, that allowed me to display at least 5 lines with 14 characters each with a very small footprint.

I also happened to have two breakout boards with the INA219 from Adafruit already in my stash.
I ordered these a few years ago when I had plans to design my own power supply. (which I did, see an other post) The INA219 is a high-side bi-directional DC current sensor that can also measure the voltage. The chip itself is designed for battery operated devices like PC's, tablets and phones, and helps to figure out how much juice is still available from the cells.

Building a prototype
As is typical for me, I started out with a breadboard version of some of the hardware, and learn from it. After I was satisfied, I started with a protoboard that allowed me to reduce some noise and resistance of the current loop. The INA219 has very jittery readings of especially the current, so I wanted to make the signal path as clean as possible before I did some more drastic work.

Here is a photo of the setup where I did most of the work. In the background is the prototype, beyond that is a simple Li-Ion charger.

One of the reasons for building the prototype was to see how low in voltage the circuit would go. It was designed specifically for Li-Ion cells with a cut-off voltage of about 3.0V and a fully charged voltage of 4.2V. I wanted to go as high as 14V to be able to measure 12V lead batteries, and as low as 0.8V for 1.2V cells like Ni-Mh. That turned out to be no problem at all.

In the partially built version above, I still used a 20x2 LCD screen with an I2C interface, because my Nokia 5110 displays took a long time to arrive from you know where.

The finished hardware
Here is a picture of the finished product running a stress test at a 1Amp discharge current.

Here is a simple circuit diagram that shows what I did in some detail. The Ax and Dx names refer to the Arduino Nano pins.

Note that there is an error in the diagram above: Pin 4 of the Nokia display needs to connect to D4 of the Arduino, not D2.

It was not easy to create the right setting for the back-light of the display to get the picture right. In real life it's much better. The reason why some numbers are difficult to see is that they quickly change and I did not want to speed-up the camera too much due to my room lighting.

The reason I say stress testing is that the maximum current that the heat-sink allows is about 1Amp. With that current, the temperature of the heatsink gets around 60 degrees Celsius. A maximum decharge current of 1Amp is enough for my intended applications, but if you go higher, get a larger heat-sink or use a fan.

Let me explain what you see on the LCD display.
First line is the title and the version number.
Second line is the cell voltage on the left and the dis-charge current on the right.
Third line is the 13-bit PWM number on the left and the "PID" error number on the right.
Fourth line shows the mAh number so far on the left and the running time on the right.
The fifth line is blank and used for error messages and to signal the end of test.

To the right of the display is a beeper, en below it is a trimmer to adjust the back-light level of the LCD.
Furthermore to the right is a fuse and below it the MOSFET on a heat sink.
Next to that are two cell holders, one for normal AA and 14500 types, and next to it a 18650 version.
Below these holders are a LiPo type socket and in blue a 2-wire terminal to connect everything else.
Below the display is the Arduino Nano and to the right the INA219 breakout board.
Below the Nano is a 4-pin connector for the I2C 20x2 LCD and a 100 uF cap for the 5V supply decoupling.
Above the Nano is the 1K2 series resistor to the Gate of the MOSFET, and the 10uF filter to ground.
Below the MOSFET is a 100K resistor that ties the Gate to ground, for safety.

The Nokia LCD display uses a 5-wire SPI and 3V3 power connection to the Nano.
The INA219 is fed by 5V coming from the Nano/USB port, and connects to the Nano with a 2-wire I2C connection.
The MOSFET I use is the same type as John uses, an IRL2203N Logic Level MOSFET, but I tried a few others like the BUK956R1 and they work just as well, as long as they are Logic Level.

Changing the MOSFET mode of operation
Apart from using another display and the Nano, the only major deviation I made to John's circuit is to increase the size of the filter capacitor to the Gate of the MOSFET, and add a 100K safety clamp to ground. John used a 100nF filter, and used PWM to drive the Gate, in an attempt to switch the MOSFET on and off. This is the preferred method to regulate power (and save energy and heat), but I found that the INA219 does not really like that. By increasing the capacitor value to 10uF, you create a crude ADC and the resulting DC voltage will drive the MOSFET into it's linear mode, and is than really acting as a variable resistor.

Improving the PC side of things
Together with John Lowen, we worked on some of the changes I suggested for the original PC program, to make it accept other cell technologies as well and turn it into a universal cell tester. He was very helpful and responsive and I think the program is now a lot better and supports all my particular wishes. One of the nice touches he added was a minimum cut-off voltage based on the various cell technologies. While te test is running the graph also shows the Min and Max values for that particular technology.

This post is based on version 1.2 of John's Batterytester software. He and I worked together to create this 1.2 version. In the mean-time, he has made some changes to the code and is now at version 2.1. I have not upgraded the Arduino code below to stay compatible! As a minimum, the write_to_pc function needs to be changed. You can easily do that by using the code from John's program, and merge it with my version.  

Testing some cells
Below is an example of a test report. This is a poor cell that I rejected. Although it still performs pretty well, it has less than a third of the specified capacity left. If it ever had that. I now do incoming inspections on all arriving cells.

Because I needed extra 18650 cells, I ordered two UltraFire 4.200mAh 3.7V cells from a distributor. When they arrived, there was a nice note in the package saying that the UltraFire cells were not performing to their expectations, so they send me two German made M2 TEC 8.800mAh cells, specified to deliver 11.8Wh. This translates to a discharge current of over 3Amps. I charged and tested them 5x to obtain their maximum capacity. I used the maximum 1Amp with the tester, and lo and behold, even these German manufactured cells did not get above 1.200mAh. They weighted 35 grams, seems a little low to me. This is the reason I wanted this tester in the first place! And yes, I did send the distributor the test reports. Haven't heard back yet...

Note the jittery lines for the current and voltage after about 5 minutes into the test. I suspect this is due to the chemical reaction of the cell during the discharge. Some cells display a very nice line, and some very jittery. I don't think that this effect is a good sign for the quality of the cell. When the voltage is jittery, the current will be jittery too, because the program tries to keep the current constant.

Here is another test,this time of a 14500 Lithium cell, where I suspected the capacity very much.

The cell weight is a good give away for the vastly overrated capacities that are advertised, so this is a nice touch from John to add it into the documentation. His intention for this feature is to slap an unscrupulous or oblivious vendor with this proof to get replacements or his money back.

Are more expensive cells better than considerably less expensive cells?
There is only one way to find out.
Below is a test made with the latest version of the tester software using an inexpensive IKEA LADDA AAA HR03 1.2V NI-MH cell with a capacity of 900 mAh :

Inexpensive does not have to mean poor performance is what you can see here.

Is a much more expensive Panasonic BK-4HCCA 1.2V Eneloop AAA Ni-Mh 900mAh is any better?

Trying to improve on the original Arduino code
While testing, playing and learning about the Arduino code, I decided to try a real PID routine to see if I could improve the current loop. It was very jittery and I saw some room for improvement. I experimented for a few days with different methods while learning the subject, because I'm pretty much a noob with PID methods. In the end, I got one working pretty good, after making considerable changes to the original code, but it did not improve much. John's method seems to be good enough.  The root cause I think is the INA219 measured current "noise" in combination with the fluctuating voltage level of the cell. It almost looks like the chemicals inside the cell are "boiling", creating tiny effects on the output voltage. That combined with the jittery current readings from the INA219 is in my opinion the reason.

I also experimented with a version of my software low frequency filter program (IIR) that I used in my milli-Volt DMM code (see my post about that) to filter and tame the 24-bit ADC output. It worked in this application as well, but had some side-effects without improving much so it went in the bit-bucket as well. I think we need to leave "good enough" alone, and be satisfied with it.

Changing the PWM counter resolution
The most significant improvement I got however was when I realized that the 10-bit PWM counter that John used was too course for the current loop regulation. A single digit change caused too much of an effect. If you realize that the Gate voltage to turn on the MOSFET and regulate it as a resistor is all done within a very small Voltage range.  Typically within 100-200mV. A 10-bit counter with a 5V maximum output has a bit level resolution of 5V/1024 bits=4.8mV. My observations were that this is not fine enough. John maybe wasn't aware of the trick you can use to get higher resolution counters. I experimented with 12, 13 and 14-bits and settled on 13, giving me a bit resolution of 5V/8192 = 620 microVolt.

Most of the other software changes I made were to create a nice way to display the results on the Nokia display by making numbers right justified.

Finally, I added some code changes to better terminate the loop when an error occurs, or when the test finishes normally.

I also have no use for running the tester all by itself, so there is no method to try to input the test parameters other than by using the PC. All that code is gone. I also don't see a need to have an LED signalling the end of test, that's what the display and beeper are for, so that went out as well.

There are a number of added comments and additional documentation in the code, so my changes should be self-explanatory.

The code can be found on my Github site here :

John changed his PC program to version 2.1. This requires a change in the write_to_pc function of my code. This new function was provided by jdr (Jan) from Dutchtronix and can be found at the very end of the code section.

This tester is very easy to build, and the project was already very well documented. If you consider building a very good battery tester or profiler, you now have two options to choose from. I can highly recommend either one.



  1. I've always wanted a device like the one you built, and I'd like to make one myself. can you post the electrical diagram?

  2. The diagram is listed on the website from John. The link is at the very top of this post. The difference in connections is listen in the text and in the source code.

  3. And when it is time to dispose of these batteries you will find that there are recycling programs which can help to safely dispose of the harmful matter in the batteries before a brand new battery is made.How To Recondition A Car Battery

  4. This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post. I will visit your blog regularly for Some latest post. check this link

  5. I'm glad to see the great detail here!. view here

  6. Paul,
    many thanks for sharing your battery tester modified from the one of John Lowen. I received thre IRL2203 today, and its work. I use an arduino Duemilanove, IRL2203, INA219 and Nokia 5110. But I had to change the default value for "int pwm = 0;"
    Maybe "fast pwm" works differently on an Arduino 2009? Have you an idea about that point?
    The Signal on the gate is more stable with a 10µF capacitor.

    Many thanks,

    1. Hi Philippe,
      Thank you for the compliment.
      I have no further information about the fast pwm, sorry.
      Yes the 10uF seems to be the better solution for this application.

      I'm sure you'll like this nice kit as much as I do.



  7. Respected sir,
    I build both versions works fine, also I need compiler name and complete pc program (discharging graph) files. I wants to edit as per my own project please share.

    Thanks in advance
    Asif Ehsan

  8. Hi Paul,
    thats awesome! I've build one today but did not get a Graph with the PC software.
    Any ideas or something which points me in the right direction?

  9. Hi Unknown,
    Unfortunately, no.
    You have to be much more precise en elaborate in your fault description to let others help you.

    1. Hi Paul i already fixed it.
      There is an difference in the code for the write_to_pc() function.

      Your code did not sent the day like the original sketch. So i merged both sketches and got a working version with PC integration.

      Did you use a different version of PC software?

      Btw. i like your project :)

    2. Hi,
      Thank you Paul for this amazing project, it is absolutely brilliant.
      I just want to know how "Unknown," got the graph with the PC working, I have the same problem.
      Thank you for any advice. ;)

    3. Johan, have a good look at the section called Important!

    4. Also look at the post just below this one...

  10. Hi Unknown, I'm glad you fixed it!
    I looked into what could be the problem, and I think I found it. I'm using version 1.2 of the Batterytester software, and John is now at version 2.1.
    I need to update my code to stay compatible.
    Thanks for the hint!


  11. Please put part list and schematic since you used arduino nano and the other is 328chip

  12. Unknown, the nano is a drop-in replacement, and I used exactly the same ports and connections. I never bothered do do what John did and remove a bunch of parts that are not needed in my version.

    1. But can you please give us some sketch of your version. I'm into electronics as hobby but not so versatile as you. Thanks.

  13. Unknown, I spend some of my precious time (;-)) to give you enough of an idea of what I did. As you can see, it is very simple and you should be able to follow that with the description and the source code. The circuit diagram is in the post.