Introduction: How to Make Universal Battery Charger

Picture of How to Make Universal Battery Charger

In this Instructable I would like to share with you my most recent project, an AVR-based universal battery charger. What does it mean universal battery charger? Well, it can charge batteries. And it can charge all four basic types of rechargeable batteries - that is, NiCd, NiMH (usually in AA or AAA form), lithium cells (usually in the form of 18650 cells) and lead-based batteries (those 12V blocks). On each battery type, you can set multiple charging parameters.

Can it do more? Of course it can. Except for charging, it can also discharge your battery to measure its real capacity or to reduce memory effect on Ni-based cells. It also comes with voltage or current limited power supply and temperature probe.

It is Arduino-compatible, even though it is not written in Arduino language. Also, you can build it in blocks - there is charging block, discharging block, control block (display and buttons) and auxiliary block (fan and temperature probe). Those blocks work independently, so you can build your device only with block of your choice.

The build is not complicated and requires nothing special (you can get everything at radioshack or ebay). It will cost you about 10 - 15 USD, it depends on how cheap you get the parts. Build time depends on your skill, you must know how to work with soldering iron and schematics. However, this is not a project for beginners, so I will not describe every step here. I am posting the schematics and firmware, so you should be able to work with that.

You can also watch this video to see it in action:

Step 1: Control & Power

Picture of Control & Power

Power

The whole thing is powered from 12 - 20 V power source, I recommend either a desktop computer PSU or better an old laptop power brick. The maximal charging current is 3 A and charging voltage depends on the input voltage. Maximal discharging power depends on your heatsink, if you use a fan and a medium-sized heatsink you can achieve max discharging power of more than 20 W.

Accuracy

The biggest challenge in the whole build. For charging lithium batteries, you need to achieve more than 3% accuracy. So, a few rules:

  1. Use 1% or less tolerance resistors! (keep away from those 5% ones)
  2. Make all switching lines from thick copper cable and make them as short as possible.
  3. Put the opamp far from all switching parts.
  4. Respect analog ground, digital ground and power ground! (see the schematic)

The brain

The brain of the whole project is an ATmega 328P - the same as in your Arduino. Clocked at 20 MHz, it provides all the necessary controls. You can get this MCU for less than 2 USD from Ebay.

Controls

For user to control the device, a display and 5 buttons are used. The display is Nokia 5110s 96x48 monochromatic display, again from Ebay (2 USD). Five buttons (left, right, up, down, OK) are used to move in the menus. Also, three LEDs are used - one for power and two MCU-controllable (one is used as "charging" and the second one as "end-of-charge").

Step 2: Charging Part

Picture of Charging Part

The "hardest" part to build is this one. It consists of a PWM-controlled buck converter which steps down the input voltage. The output voltage and current are measured and evaluated by the MCU and eventually the duty cycle of the PWM is adjusted. The code contains algorithms for NiMH, NiCd, Li-Ion/Pol and SLA batteries.

Note: yes, I know that this is not the best and/or accurate method for regulating V/C. But it is accurate enough and is much simpler to build then the other options. Trust me, I have been using this charger for a few moths now and I never had a problem with it overcharging (or anyhow damaging) the battery.

Li-Ion/SLA charging

Lithium and lead batteries are charged with the same algorithm - the charger starts in constant current mode, waits for the voltage to rise and then switches to constant voltage. You can set the current and voltage limit. This algorithm has overvoltage and overtemperature protection. Also, the user can abrupt the charging at any given time. See the pictures for an example of lithium battery charge.

Ni-Cd/Ni-MH charging

Nickel-based batteries are charged in constant current mode for a given period of time or until one if the abruption methods kicks in. You can set the charging current, charging time and number of cells in series. This algorithm has overvoltage, overtemperature, -dV/dt and time-out protection.

Power supply

The charger can also serve as a simple constant voltage/constant current source. However, note that because of the slow MCU, the power supply has long transient response time. So use only loads which do not mind that.

Step 3: Discharging Part

A simple discharging part is also integrated in the project. It consists of a N-channel MOSFET and current sensing resistor. PWM from the MCU is converted to true analog voltage using a low pass filter and then fed into the gate of the MOSFET, which in turn serves as a variable resistor. The MCU regulates PWM duty cycle based on the measurement from current sense resistor. You MUST mount the discharging MOSFET onto a heatsink, because it is dissipating all of its energy into heat! IF you don not have a big enough heatsink, you must include a fan.

When you choose "discharge" from the main menu, you can set the discharging current and the minimal voltage ("undervoltage protection"). The software automatically measures battery capacity in mAh and mWh.

Step 4: Conclusion

Source

You can download the source code from my GitHub.

Please let me know if you like this project. I am thinking about building V2 with integrated battery balancer, so if there will be enough people interested, I will post the schematic for it. Also, if you have any questions or comments, feel free to post them!

Comments

tonzerotnk (author)2017-10-25

source code Open with what program ?

MartinD_CZ (author)2017-09-25

UPDATE: I am currently working on version 2 of this thing, with cell balancing, better UI and lots of other stuff. Also it will be in a form of an Arduino shield. V2 should be out in October, so insted of building this, I recommend waiting for V2.

CraigG41 (author)2017-09-24

Curious about this statement: "I know that this is not the best and/or accurate method for regulating V/C." - the way you have done it seems to be pretty standard for all the reference designs I have seen?

MartinD_CZ (author)CraigG412017-09-25

Hi,

yes, it indeed is, but most reference designs do not have a display and controls, they regulate based on some predefined values. In those applications you need the processor to react to a sudden change in the output ASAP, which is hard, when it is busy drawing the display or checking controls and doing a lot of other stuff. So yes, the method itself is okay. And the processor is still fast enough, I just wanted to point out that this is fine for battery charging, where the load changes slowly, but not for a lab bench power supply or something similar.

Srajmund (author)2017-09-17

Hello,

Could you write the Fuse bits of AVR?

Srajmund (author)2017-09-17

Hello,

Nice project.

Could you write the fuse bits?

srajmund0968@gmail.com

mrimgr (author)2017-09-13

Welcome.

Project AVR fuse bit?

mrimgr (author)2017-09-13

Welcome.

Project AVR fuse bit?

72ebola72 (author)2017-09-01

Welcome.

I want to change a pinouts LCD from CE=PD0, RST=PD1, DC=PB3, DATA=PB4, CLK=PB5 to PD3, PD4, PD2, PD1, PD0.

When I change pins PB4 and PB5 to different, LCD does not show.

Why?

How to change the connection LCD?

clairvoux (author)2017-04-04

What are the differences between the different grounds? I've been looking at the schematic for a while now, and they all seem to have the same characteristics, so why do you recommend separating into 3 planes?

MartinD_CZ (author)clairvoux2017-04-04

They do have the same potential indeed, but separating grounds is very common. There are two basic reasons - ground loops and noise. I am not honestly going to explain them, you can search for that very easily.

swalehi (author)2017-01-09

I built the PCB with little changes that is no uart and no isp connection and for the sake of simplicity in pcb i change the pin layout of lcd and switches if any one in need i can send.

MojtabaJ5 (author)swalehi2017-01-12

hi swalehi
can you send me your pcb and other files?

mojtabajahangard90@gmail.com

swalehi (author)2017-01-09

I made the project but not working menu are working but pwm is not generating. I reviewed the circuit with my built no difference found. I rebuild the project and programmed the micro controller but no luck. Do not know whats wrong if any help i will appreciate. The problem is the output voltage is same as input voltage what ever you set in menu.

BobanM2 (author)2016-12-30

Sorry, but how to write 38k hex file in 32k controller

MojtabaJ5 (author)2016-12-05

hi
i need pcb or layout file and partlist of this charger! please help me! send this files to my my email:

mojtabajahangard90@gmail.com

MartinD_CZ (author)MojtabaJ52016-12-06

Hi,

unfortunately, I do not have any layout files, as I have build this on a piece of perfboard... And you can work out the partlist from the schematics. I am planning version 2.0 with cell balancing, so maybe there I will provide layout & partlist

MojtabaJ5 (author)MartinD_CZ2016-12-06

thank you martin

but i have no expert khowledge about drawing of schematic to draw pcb! can you send me a pictur of pcb?

when finish you version2,2?

daragon50 (author)2016-11-21

This looks to be an interesting and useful project that I'd like to try and build. Do you have a parts list and where to get them that you can share or post.

MartinD_CZ (author)daragon502016-11-29

Hi,

Unfortunately, I do not have a partlist, since anybody can customize their project. But I provided schematics, so I hope you can write down the parts really easily. Getting the parts - either Ebay or your local RadioShack, depends on your local prices & delivery times from Ebay

daragon50 (author)MartinD_CZ2016-11-29

Understood. Can you identify what you used for your UART and the p-fet in the discharge module? Is the ISP where you are plugging in the UART?

MartinD_CZ (author)daragon502016-11-30

Well, to receive data from UART, you need an UART to USB converter (2 USD on Ebay). Discharging FET is any generic FET in TO-220 mounted onto a heatsink. The ISP is something different from UART.

gettingthere (author)2016-11-21

My id is torrelcorp@gmail.com

gettingthere (author)2016-11-19

Hi again

I was wondering if you would be interested in working with me on a battery charging related controller. This is a commercial requirement. Please email me if you can.
Regards

gettingthere (author)2016-11-14

2N3904 ?

MartinD_CZ (author)gettingthere2016-11-14

yeah, I used those

gettingthere (author)2016-11-12

Another quick one. In the schematic shouldn't the lcd backlight be connected to vcc thru a current limiting resistor instead of gnd?

MartinD_CZ (author)gettingthere2016-11-13

Q1 is a general NPN tranzistor. Q2 is a P-channel MOSFET. IRF9540 should work fine.

gettingthere (author)2016-11-10

Oops forgot to add . I dont have the mosfet you mentioned. Can i use IRF9540 or IRFP9140.

gettingthere (author)2016-11-10

What's the component marked Q1

gettingthere (author)2016-11-08

Hi Martin
This looks really interesting. Am attempting to build this. I'm sure i will have questions. Hope you dont mind helping me out?!

MartinD_CZ (author)gettingthere2016-11-09

sure I will help, just drop me a message or write in the comments :)

petersoldan (author)2016-09-28

looks very nice.somehow I missed seeing the part where you gave a complete list of materials and instructions for putting this together.

About This Instructable

5,990views

93favorites

License:

More by MartinD_CZ:Arduino-controlled True Switching RegulatorsHow to Make Universal Battery ChargerSimple AVR Laser Game Gun
Add instructable to: