# 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).

### Become the Maker you were born to be. Try Arduino Academy for FREE!

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.

References:

## Become the Maker you were born to be. Try Arduino Academy for FREE!

Subscribe
Notify of
Inline Feedbacks
2 months ago

I was trying to follow along here and you lost me at where “To determine the correct resistor for the CC regulator”. You say “to divide 1.25v by the desired current of one amp“. Where do you get the 1.25v?

Bryan
1 year ago

Another good article. Lithium batteries give of an increase in heat when they are charging. During the recharging of the batteries the battery temperature could increase enough to cause a fire, You didn’t cover that. Why?

Mabbo Segatta
3 years ago

The idea given here that 18650 batteries are to be Charged with a Constant Current && Constant Voltage source is a thought process from some â€˜Very-Old-Schoolâ€™. The fact is that these batteries can be comfortably charged with varying current ‘pulses’ BUT the top limit shouldn’t exceed the manufactureâ€™s stated limits. Also (Very IMPORTANT) â€¦ each cell has to be individually monitored so as not to exceed 4.2V before sending the Charge pulse. (The methodology given in this post here doesn’t do that.) In the absence of such a check there is a danger that a cell can experience a higher voltage when in series connection. Now there are many brilliant designs available for charging up to 4 cells in series with a 5V USB charger without any step-up Booster.

Brian Jenkins
3 years ago
Reply to  Mabbo Segatta

Thanks for the helpful insight Mabbo!

5 years ago

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.

5 years ago

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.

5 years ago

Thank you.Never thought of using a LVD to charge a 18650 earlier.

5 years ago

You don't use a LVD to charge. You can use a LVD to prevent over discharge.