Charging Lithium Ion Batteries with the Arduino

Many of our projects are running off the common 18650 Lithium Ion battery, so today we wanted to talk about the math of charging, and of course we want to use an Arduino to manage that charge.

Lithium Ion batteries need a Constant Current (CC) / Constant Voltage (CV) charge. It starts out in CC, then switches to CV to finish once the battery comes up to a specified voltage.

If you have a 2000mah battery, you typically want a charge current of half that, so multiply .5 * 2000mah = 1000 ma charge current (check your battery datasheet for recommended charge current).

We are charging 4 batteries in series, so 4 * 4.2v = 16.8v is our maximum charge voltage.

We will be using two LM317 regulators, one in CC mode, and one in CV mode. The LM317 has a 1.5A maximum with a heat sink. If you need more current, use the LM338 (5A).

To determine the correct resistor for the CC regulator, we divide 1.25v by the desired current (1A), and get 1.25 ohms. We also need to determine the resistor wattage, so multiply 1.25v * 1A and we get 1.25W (use a 2W resistor).

R1 (Ohms) = 1.25v / 1A
R1 (Watts) = 1.25v * 1A

To determine the correct resistors for the CV regulator, we need our desired output voltage (I will use 16.4v to give more life to the batteries, and less stress on an optional inverter) . We will use 220 Ohms for R1 and 2700 Ohms for R2.

R2 = R1 * ((Vout – 1.25)/1.25)

The Arduino is used to monitor voltage and current, and toggle two relays, disabling the CC regulator and enabling the CV regulator when the voltage hits 80% of target, then shutting down the CV regulator when current drops below 50ma. Active mode as well as voltage and current can be displayed on a LCD. See the tutorial.

A future upgrade will be a temperature sensor that stops charging (and discharging) when the battery temperature exceeds a predetermined value. We can also drop the load when the battery discharges to a predetermined value.


LM317 Datasheet
Samsung 18650 Datasheet

4 thoughts on “Charging Lithium Ion Batteries with the Arduino”

  1. Something that's never been clear to me is how one protects against *over-discharge* when using simple 18650s to power Arduino or ESP8266 circuits.

    I know we aren't supposed to let them run below 3.0V (or some say 3.2V) but how does one implement this type of protection? I see a lot of pre-baked Li-ion charging boards available for cheap from the usual suspects, but nothing that has a primary job of protecting against over-discharge.

  2. LVD's are commonly found on Inverters and BMS boards, you can make a simple one with a Arduino, voltage divider to monitor battery voltage and a relay to disconnect the load.

Leave a Comment

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