Lithium-Ion Battery Charger

This is a tutorial of a DIY Lithium-Ion battery charger implemented on Arduino with several advanced features like state-of-charge estimation, EEPROM logging and command-line interface. It uses the Constant Current Constant Voltage (CC-CV) charging method with end-of-charge detection based on multiple criteria. The same design can be used for charging Lithium-Polymer (LiPo) batteries.

The rationale behind this project was to upgrade the depleted battery pack and charger of an old cordless drill from Nickel-Cadmium (NiCd) to Lithium-Ion (Li-Ion) technology.

Warning: Lithium-Ion batteries are hazardous devices. Overcharging, short-circuiting or otherwise abusing Lithium-Ion batteries may result in a fire and/or a violent explosion. The author of this page neither takes any responsibility nor can be held liable for any damage caused to human beings and things due to the improper handling of Lithium-Ion batteries. Please be aware that the current design has not been certified for safety, consequently it is not suitable for commercial applications and must be implemented at your own risk. Last but not least, it is imperative to equip each Lithium-Ion battery pack with its dedicated battery protection board (or Battery Management System aka BMS).

Theory of Operation

The following sub-sections cover the theoretical and mathematical aspects of Lithium-Ion (Li-Ion) battery charging. The exact same principles apply to Lithium-Polymer (LiPo) batteries.

CC-CV Charging

Li-Ion batteries must be charged using the Constant Current Constant Voltage (CC-CV) charging method. This method consists of charging the battery at a constant current I_{chrg} until a certain voltage threshold V_{max} = 4.19 V/cell is reached, then gradually reducing the charging such that the constant cell voltage V_{max} is not exceeded. Charging is terminated once the current reaches a certain minimum threshold I_{full} of typically 50..150 mA.

Additional end-of-charge (EoC) criteria have been implemented for safety reasons. These include the time-based and capacity-based EoC detection. When a battery is connected, the charger measures the voltage at its terminals and roughly estimates its state of charge SoC in %. The SoC value is used for calculating the remaining capacity C_{max} and charge duration T_{max}. Charging is terminated if either of these values has been reached. The SoC calculation details are described in the following sections.

Control Loop

The battery “+” terminal is connected to the positive power supply through a power MOSFET (field-effect transistor). The battery “-” terminal is connected to the power supply ground through a low-value shunt resistor R_{shunt}.

The charging current is regulated by means of Pulse Width Modulation (PWM), where the MOSFET cyclically turned on and off by the Arduino at an approximate frequency of 1KHz. The charging current is controlled by gradually adjusting the PWM duty cycle which is the ratio between the MOSFET on and off duration.

V_1 is the voltage measured at the battery “+” terminal and V_2 is the voltage measured at the battery “-” terminal. Both voltages are measured relative to the power supply ground and are used for calculating the voltage V across the battery pack and the charging current I as follows:

V (V) = V_1 - V_2

I (A) = \frac{V_2}{R_{shunt}}

Two separate ADC channels on the Arduino are used for measuring the above voltages. The Arduino continuously monitors V and I and adjusts the PWM duty cycle in order to achieve the desired constant current or constant voltage regulation.

State-of-Charge Estimation

The state of charge SoC is estimated by reading the battery voltage V and comparing it to a series of values stored in a lookup table L = [l_1,l_2,l_3,l_4,l_5,l_6,l_7,l_8,l_9]. The threshold voltages are derived from the particular discharge curve shown below for the LG 18650 HE4 cells used in this project (source: https://lygte-info.dk/review/batteries2012/LG%2018650%20HE4%202500mAh%20%28Yellow%29%20UK.html).

The red discharge curve corresponding to 0.2A discharge current has been used, whereas the values of L were assigned such that:

  • l_1 = V@2.25Ah
  • l_2 = V@2.00Ah
  • l_3 = V@1.75Ah
  • l_9 = V@0.25Ah

SoC is calculated as follows:

  • V < l_1: SoC = 0\%
  • l_1 < V < l_2: SoC = 10 \%
  • l_2 < V < l_3: SoC = 20 \%
  • l_9 < V: SoC = 90 \%

The remaining capacity C_{max} and charge duration T_{max} are derived as follows:

C_{max}(mAh) = C_{full} \cdot (100 - SoC) \cdot 1.3

T_{max}(s) = 3600 \cdot \frac{C_{full}}{I_{chrg}} \cdot (90 - SoC) + 45 \cdot 60

Where C_{full} is the battery design capacity and I_{chrg} is the nominal charging current. Note that C_{max} is increased by 30% and T_{max} is increased by 45 minutes in order to to account for resistive losses and SoC estimation inaccuracy.

Safety

The charger implements several safety features. These include undervoltage, overvoltage, short circuit and open circuit detection.

The typical voltage range where a Li-Ion battery can safely operate is between V_{min} = 2.5 V/cell and V_{max} = 4.19 V/cell. Operating outside this range is likely to cause permanent damage to the Li-Ion cells and may even result in a catastrophic failure such as an explosion or fire.

The battery pack is additionally protected by a battery protection board (or Battery Management System aka BMS). The BMS measures the voltages of the individual battery cells as well as the charge/discharge current flowing through the battery. The BMS uses a solid-state switch to disconnect the battery as soon as the voltage or current values become outside of the specified limits.

For the most part, the BMS is completely transparent and does not interfere with the charging process, except for the case where the BMS disconnects the depleted battery in order to prevent over-discharge. In this case, the voltage of the depleted battery is still present across the BMS terminals through a high value resistor placed in series with the battery. This high value resistor causes a much lower voltage value to be measured at the charger terminals. Consequently, the charger must ignore the V_{min} lower limit and start charging at a much lower value of as low as V_{start} = 0.5 V/cell.

When presented with a depleted battery, the charger would start charging at a reduced safety current I_{safe} = I_{chrg} / 10 until the battery voltage reaches V_{safe} = 2.8 V/cell, afterwards it would apply the full charging current I_{chrg}. Once the voltage reaches this threshold, it is no longer allowed to drop below the V_{min}. A voltage below V_{min} would raise an “undervolt error” which is may caused by either a short circuit or a battery open circuit.

Open circuit is also detected if the charging current stays equal to zero while the PWM duty cycle increases beyond a specific threshold. This condition would raise an “open circuit error”.

Overvoltage is detected whenever the battery pack voltage momentarily exceeds V_{surge} = 2.25 V/cell. Exceeding this value would raise an “overvolt error”.

Trickle Charging

Once the end-of-charge (EoC) criteria has been met, the charger would cut-off the charging current and switch to an idle mode where it will continuously monitor the battery voltage. Once the voltage drops below a specific threshold of V_{trickle\_start} = 4.10 V/cell, a new charging cycle will be initiated using the following parameters:

V_{max} (V/cell) = V_{trickle\_max} = 4.15V/cell

C_{max} (mAh) = C_{full} \cdot 0.3 + C

T_{max} (s) = 20 \cdot 60 + T

Where C_{full} is the battery design capacity. C and T are the accumulated charge capacity and charge time since the battery has been connected, including the initial charge and all of the subsequent trickle charge cycles.

Given the above formulas, the trickle charge cycle uses a reduced V_{max} and allows for charging up to a maximum of 3% of the battery design capacity during a maximum duration of 20 minutes.

Hardware

The following sub-sections describe the hardware design aspects of the Li-Ion charger.

Mechanical Design

The following image gallery shows the mechanical design of both battery pack and charger.

The original 12 NiCd cells have been removed from the battery pack and replaced by 4 LG 18650 HE4 Li-Ion cells and a battery protection board (or Battery Management System aka BMS). Despite the increased capacity, the modern Lithium-Ion cells use significantly less space which leaves plenty of room for the BMS and and the required wiring.

The original battery charger has been retrofitted with the custom PCB containing the Arduino and required circuitry. A 19.5V / 3.33A notebook power supply has been used for powering the whole system.

Battery Protection Board

Despite the safety features described above, it is imperative to use a dedicated battery protection board for each of the battery packs. This provides an additional layer of protection to prevent an overcharge or over-discharge condition due to a software or hardware bug.

The following figures show the particular 4S / 30A (4S means 4 cells in series) battery protection board (or BMS) that has been used in this project. It has been acquired for less than 10€ on Ebay and serves its purpose very well (source: https://www.ebay.de/usr/rc-helicar).

In the above figure one can see the wiring diagram for connection the 4 Li-Ion cells with the BMS.

This particular BMS includes the cell balancer feature. If the voltage of one or more cells becomes higher than the rest of the pack, the BMS would actively discharge those cells to ensure that all the cells of the battery pack share the exact same voltage.

Circuit Diagram

The the following figure shows the Li-Ion charger circuit diagram.

Lithium-Ion battery charger circuit diagram

The above schematic, the 19.5V of the power supply are stepped-down to 5V by the 7805 voltage regulator U1. The 5V is used for powering the Arduino board.

The Arduino Pro Mini compatible board U2 hosts an ATmega 328P microcontroller running at 16MHz clock frequency and is used as the main processing unit for the device.

The Lithium-Ion battery is connected across the B+ and B- terminals. The battery charging current is regulated by switching P-Channel MOSFET (field-effect transistor) Q1 via pulse-width modulation (PWM).

The PWM-enabled digital output pin 9 on the Arduino generates a PWM signal which drives the gate of the MOSFET Q1 through the NPN transistor Q2. The voltage divider formed by R1 and R2 ensures that the gate-source voltage of the MOSFET stays within the specified limits.

A current-sensing shunt resistor connects the B- terminal with ground. It consists of two 1Ω/3W resistors R8 and R9 connected in parallel. This results in a total resistance of 0.5Ω. At a charging current of I = 2A, the voltage across the shunt will be exactly 1V; which is slightly below the 1.1V internal voltage reference of the Arduino thus corresponds to the full range of the Arduino’s analog-to-digital converter (ADC).

The analog pin A1 on the Arduino is used for measuring the voltage V_1 between B+ and 0V. Analog pin A0 is used for measuring V_2 between B- and 0V.

B+ is connected to pin A1 through a voltage divider consisting of R4 and R7, the ratio has been chosen such that the maximum battery pack voltage of 16.8V would result in slightly less than the Arduino’s internal reference voltage of 1.1V at A1. B- is connected to A0 through a current-limiting resistor R5; a voltage divider is not required for measuring V_2 as its value stays below the Arduino’s ADC internal reference voltage. Two 10µF Tantalum capacitors C4 and C5 are used for blocking the high-frequency noise caused by the PWM from reaching the analog inputs, an essential measure for smooth ADC readings.

The Diode D1 protects the 7805 regulator from a reverse power supply polarity. The diode D2 protects the battery from a reverse polarity; it also prevents the battery from feeding power back into the Arduino in case the main power supply has been disconnected.

A LED indicator D3 and its dropper resistor R6 are connected to Arduino’s digital pin 13.

PCB Layout

All of the components are of through-hole type and are mounted on a stripboard PCB. The following figures show the PCB layout of the Li-Ion charger. Please click on the respective image in order to see a larger version.

The MOSFET (TO-220 device in the top right corner) and large green-colored shunt resistors will get pretty hot so adequate ventilation needs to be assured. The following measures has been taken to avoid overheating:

  • The shunt resistors are raised by around 5mm from the PCB in order to assure adequate cooling.
  • A series of holes has been drilled in the bottom of the enclosure in order to allow for a better air flow.
  • The charging current I_{chrg} has been limited to 1.5A.

The electrolytic capacitor towards the top center of the board is in a sub-optimal position due to its location between two hot components – the 7805 regulator and the MOSFET. High temperatures reduce the lifespan of electrolytic capacitors thus the must be kept away from heat sources.

Note that the 3A BY255 diode D2 shown on the schematic has been added after these PCB pictures were taken, thus the front PCB view still shows shows 3 smaller 1A Schottky diodes soldered in parallel (top right corner). Connecting diodes in parallel is generally prone to failure due to the fact that their junction voltage might be slightly different which may lead to an unbalanced current distribution,whereas the diode with the lowest junction voltage would take most of the current.

The pin header located at the top right corner is used for connecting all the external wires. Following is the pinout assuming that pin 1 is at the top right corner and pin 10 is towards the middle of the board.

PinPurpose
1LED + (*)
2LED – (*)
3, 4Power supply +
5, 6Battery +
7, 8Power supply –
9, 10 Battery –

* The LED dropper resistor is located on a separate PCB together with the LED itself.

Downloads

Below you can find GitHub download links for the Arduino firmware source code, Eagle schematic source files and bill of material. All of the source code is distributed under the GNU General Public License v3.0.

Lithium-Ion Charger Firmware

Eagle Schematic Source Files

Bill of Material

Last updated on March 22nd, 2019

Leave a Reply

Your email address will not be published. Required fields are marked with an *.