Battery charging: a maximum power point tracker with an Arduino


The purpose of this Arduino experiment is to build a general purpose charger that uses a maximum power point tracking strategy. The design originally considered a 150mAh 9V NiMh battery, later I redesigned it so that anything under 1000 mAh can be charged, either with a NiCd or a NiMH battery up to the limits of the used current regulator (an LM317). Initial designs were based on a constant current charger and a timer, but this is not a fail-safe method that can lead to overheated batteries. So I started adding timers and temperature control circuits, but this did not give me what a maximum power point tracker can achieve.  So what does a charger actually do? The charger should put a constant current through a number of cells. The voltage that you get to see across any cell would look like what is shown in figure 1:

Fig 1: Charge curve for a 9V 150 mAh battery

Figure 1 shows what a 9V 150 mAh NiMH battery does during a charge cycle. In the first 20 minutes or so the voltage runs up till you get a plateau, this level is maintained for a while until we see that the voltage peaks to 10.8 Volt. After the maximum power point at 140 minutes since the charger started you see that the voltage drops because the efficiency of the charging process deminishes. This is the point where the batteries get hotter, and it is a good practice to stop after you have reached the maximum power point. The datasheet actually warns against temperatures greater than 40 to 50 degrees.

The charger itself, and in particular its current regulator, also gets warm during the process. This depends on the voltage difference across current regulator. At 7.5V across the battery the regulator has to dissipate at least 11V – 7.5V  times 85 milliamperes = 298 mW. In this case you can simply mount the LM317 on  a piece of circuit board with a 3mm nut and bolt. But at 266 mA (the high setting) you need more, so I mounted a piece of aluminum on the lm317 and I drilled some holes into the case so that the temperature stays well under 90C.

Batteries are by definition a current source, the capacity is expressed in milliamp hours, a value of 150mA.h means that 150 milliampere could be delivered for 1 hours. To compute the charge level  of a battery you have to add up all time intervals times times the current. The charge process has a certain efficiency, not all the charge that we put in affects the electrolytic reaction within the battery. In figure 1 we see  that 215 mAh was put into a 9V NiMh cell that was good  for 150 mAh.

We speak about trickle charging when the current is below 1/10th of its capacity. For example, a 150 mAh battery is charged with 15 mA so that you need at least 10, and probably more like 16 hours. This is a perfectly safe method since nothing can go wrong. But if you are impatient then C/2 or C is also possible. If you read the datasheets of a battery then fast charging is a process that needs to be carefully controlled. So the idea was, let’s do this with an atmel328p microcontroller that keeps an eye on this process.

When you discharge a battery you get the see a curve as shown in figure 2 where voltage is shown over time.

Fig 2: Discharge curve for a 1.2V NiMh cell.

During discharge you get to see a rapid decrease in voltage in the first 2 hours (the data comes from the GPS tracker, it draws 50 mA from a 800mA pack), until we hit a plateau that is maintained for the coming 8 hours, after 10 hours the voltage gradually falls until the cell is depleted. Running an cell empty is something you should try to avoid, for older batteries this usually means that you killed the poor thing. It is actually a common problem in cars, UPS’s, notebooks and a lot of other consumer electronics. So, handling batteries is something delicate, in the end you always lose. A battery management system can help to extend to lifetime.

The charger

This design consists of a microprocessor, an atmega328p, which is the same as found in an Arduino UNO, an N-channel power MOSFet, a current limiter, an EEPROM and a LCD screen. The EEPROM is used for recording voltages, so this is how I make graphs like figure 1 and 2.

Schematic of the charger
Design before it had heat sinks and a fast charging option. (Design completed in February 2014)
The circuit board, now with heat sinks and a 4.7 Ohm + 10 Ohm resistor for the LM317. By a switch you can short circuit the 10 Ohm resistor, this implements the fast charge. The LM317 law is I=1.25/R where R is here 4.7 or 10+4.7 Ohm, so that I=265 or I=85 milliAmp.
Rear side of the circuit board, I put it here so that I can check the board in case I run in trouble.
Typical use of the charger, add it to a lab power supply, connect a battery, all via 5 mm plugs. Two push buttons are included, left turns the back light on and off, right is used to start and to cycle between different screens while charging.


The power connector on the left (pin is positive, edge is negative, 5mm diameter) accepts anything from a laptop charger which is typically 16 Volt DC and upwards which is needed because the current regulator steals 1.25V, while two Silicon diodes take away 1.4 Volt. To obtain 11V at the battery you need 13.65V at least as input. The battery connector on the right takes on the positive lead the output of the LM317 current regulator (via a Si diode) and at its negative lead a IRL540N N-channel MOSFet. Essentially the latter is a switch or a solid state relay. One could design all of this with smaller components in an SMD design, yet the game was here prototyping on a standard Velleman circuit board, it is a DIY activity.


Screen 1: shows charge supplied.
Screen 2: shows three voltages discussed in the text

Figures screen 1 and screen 2 show two screen shots of the charger.

In screen1: H means that we are charging with a high current, and L would mean a low current. This is controlled by a switch near the battery connector on the right side. High means 266 mA (calculated as 1.25/4.7 according to the LM317 datasheet) and low means 85 mA (=1.25/14.7) . The low setting is good for 9V 150mAh NiMh batteries,  high is good for anything above 500 mAh such as a pack of 1,5 AAA or AA penlite cells welded in series. For most of my experiments I use four 1.5V AAA NiMh cells, with a capacity of 800mAh. In figure 5 you see another example of 10 NiCd cells of 1.2V each with a capacity of 900 mAh.  The H of L in figure 6a follows from the calculated charge delivered to the battery. The second line shows R 99:33, meaning that we are running for 99 minutes and 33 seconds, and T=262 is a temperature indicator. The 262 refers to a voltage across a 10k ntc between null volt in series with a resistor of 10k which is mounted close to the heat sink of the LM317 current regulator in the schematic. Below T=130 the temperature goes above 90C and the microcontroller interrupts the charging until it has cooled off to above T=160. Actually, the LM317 has an internal circuit that already protects overheating, but it recommends to stay under 125C.

Screen 2: This display shows what the tracker is doing. P14639 on the top rows means that we reached a maximum voltage of 14639 millivolt at T10, thus 10 seconds ago. The most recent lowest voltage was L14150 thus 14150 millivolt. This reading is taken just after the each relax window that lasts 5 seconds. Every 2 minutes we shortly interrupt the process to measure the voltage drop across the battery, 14150mV is the value that we recently obtained, and C14614 is the actual measured voltage (14614 millivolt).

The problem with charging any type of battery is that you have to watch the point where the most recent measured voltage does not exceed the maximum (or peak) voltage found by the tracker, also, that the peak occurred not too long ago. The end of charge condition is determined by three factors: 1) The highest voltage point occurred 900 seconds ago 2) We are 25 millivolt below the peak point, 3) Alternatively, more than 1000 mAh  was delivered.

After the peak voltage, the charging process becomes ineffective since the supplied current is not used anymore to feed the chemical reaction in the battery, instead the electrolyte starts to heat it up. If you would extend this indefinitely then the battery will die at some point. This is a problem with all chargers, if the algorithm runs  too short and you miss capacity, if it runs too long you damage the batteries. The standard solution is to apply a C/10 or C/20 trickle charge which lasts a day or so.  This will result in a steady equilibrium where usually no damage is done. In a fast charger the design has to include an algorithm to track the maximum power point, and to stop after this point to avoid thermal damage.


In it is explaining how batteries behave during charging and discharging. One design hurdle is that the peak voltage is temperature, battery age and charge condition dependent. With analog only electronics the peak power point is hard to find. As a compromise you can preset a maximum voltage (as I did in earlier designs), but it is not an optimal design. The maximum power point discussion follows from Volt against Time graphs on the battery datasheet. In professional designs battery power management is handled by a dedicated IC such as the LT3652HV from linear technology, see
Last update 23-july-2014

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s