How to Make Universal Battery Charger

10,513

100

45

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

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

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!

Share

    Recommendations

    • Tape Contest

      Tape Contest
    • Arduino Contest 2019

      Arduino Contest 2019
    • Trash to Treasure

      Trash to Treasure

    45 Discussions

    0
    None
    ARD_MAN_328P

    27 days ago

    Hi, excellent project. Is it possible to upscale the input / output? I am trying to make a battery to battery charger (both 12v) for a campervan / motor home. When the engine is running (measured with input of >13.6v) I woild like an output of (whatever it can produce - adjustable by software / hardware in the project) from the alternator to charge the leisure battery. However, I don’t want any back-feed from the leisure battery, or taking more than the current specified. I can program the Arduino / Atmel328 software - and obviously happy to share - but I don’t want to risk my limited hardware knowledge from causing problems - primarily fire - from melting cables! Any help would be gratefully received.

    F39028B7-41FA-407E-8AE3-AAEA8BAA7D1F.jpeg
    1 reply
    0
    None
    MartinD_CZARD_MAN_328P

    Reply 27 days ago

    Hi,
    if I understand you correctly, you want to charge a lead-acid battery from a lead acid battery. Honestly lead batteries are not exactly my field of work (i work mostly with lithium or nickel based batteries), but from my knowledge this circuit might not be exactly what are you looking for, because there will be some voltage drop on the output. However, lead batteries are relatively durable charging-wise, so I would say that a purely hardware solution would work (see https://batteryuniversity.com/learn/article/charging_with_a_power_supply). Backfeed could be prevented with a Schottky diode. But as I said, I do not have much experience with these so I really do not want to give you wrong or misleading information, better check with somebody who has more expertise in this exact field.

    0
    None
    fly71

    2 months ago on Introduction

    Hi Martin
    I want to ask you, with which program I can open the project and upload it to the MCU
    With the Arduino 1.8.3 program I can not open it and even with AVr studio 5.1 I have problems opening the files

    1 reply
    0
    None
    MartinD_CZfly71

    Reply 8 weeks ago

    Hi, if you mean the hex files, then just upload them using AVRdude. If you mean the .c and .h files, then you should be able to open them in AVRstudio...

    0
    None
    fly71

    2 months ago on Step 4

    Hi Martin
    I congratulate you for your project, very nice is interesting.
    I was looking for a similar project, basically a project to test the batteries and their charging capacity, often checking batteries for small tools.
    You can charge LiFe batteries, just select the cell voltage?
    I have read the description of this project and I assume that the discharge can also be done on batteries made up of several cells.
    Regarding the download I wanted to ask if you can increase the power of discharge, a possible solution is to insert 2 FET in the discharge section and put a large heatsink with a fan, or is it necessary to change the block of the discharge in the MCU?
    To program the MCU, just use this programmer?
    https://blackstufflabs.com/2013/10/24/aggiornare-firmware-usbasp-con-arduino/
    I built some projects and loaded the program in the PICs, but with ATMEGA never programmed, I only programmed the Arduino board for my 3D printer.
    I leave you an e-mail in case you want to give suggestions on this project.
    cellui@yahoo.it
    Greetings Luigi

    2 replies
    0
    None
    MartinD_CZfly71

    Reply 2 months ago

    Hi,

    I am not sure about LiFePO4 batteries, you would need to look up the internet to find out their charging profile. And yes, you can discharge a few cells in series, as long as you can keep the FET cool enough. So a big heatsink with a fan would definitely help with that. Putting two FETs in parallel is not that hard, but it would require some changes (you can simply tie gate pins together and the same with drains; but put 0.1 ohm resistors on each source before connecting them together).
    The site you have linked is in Italian, which I do not speak, unfortunately. According to Google translate, it speaks about USBasp, which you can use to program the ATmega.

    0
    None
    fly71MartinD_CZ

    Reply 2 months ago

    ......Putting two FETs in parallel is not that hard, but it would require some change......
    So if I want to put 2 FET, it is not necessary any modification on the source code to the MCU, but just make the hardware modification on the electronic circuit

    0
    None
    gettingthere

    2 months ago

    Hi trying to get in touch with you again

    0
    None
    MartinD_CZ

    1 year ago

    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.

    3 replies
    0
    None
    Nitrus015MartinD_CZ

    Reply 1 year ago

    Hi Martin,
    This is an excellent project, I must commend you for it.

    My current interest is with charging those 18V NiCd drill batteries, and I'd like to build this. I'll probably need to modify it to take higher voltage I guess, as you mention 12V - 20V power source.
    I noticed this comment however, and I'd like to ask whether you're still working on v2?
    Is it worth building this for my purposes or should I wait for v2?
    Cheers.

    0
    None
    MartinD_CZNitrus015

    Reply 1 year ago

    Hi,

    well, modifying it for 18V NiCd batteries won't be complicated. Regarding the V2 - well, I had to pause it because of other projects I had been working on, so now it is on hold. But since many people are asking me about it, I will try to finish it sometime. The problem is that I cannot (and don't want to) promise any finish dates, as I really do not know when I will get back to it...

    0
    None
    Nitrus015MartinD_CZ

    Reply 1 year ago

    Yes, I suspected as much for the modification - I have not looked at the schematic in depth yet but I don't think it will be too much of an issue. If you have any suggestions to begin with, I'd be happy to hear them :)

    As for V2, no worries. It is better to take your time and put out something complete, rather than push out something half-baked for the sake of an update.

    0
    None
    tonzerotnk

    1 year ago

    source code Open with what program ?

    0
    None
    CraigG41

    1 year ago

    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?

    1 reply
    0
    None
    MartinD_CZCraigG41

    Reply 1 year ago

    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.

    0
    None
    Srajmund

    1 year ago

    Hello,

    Could you write the Fuse bits of AVR?

    0
    None
    Srajmund

    1 year ago

    Hello,

    Nice project.

    Could you write the fuse bits?

    srajmund0968@gmail.com

    0
    None
    mrimgr

    1 year ago

    Welcome.

    Project AVR fuse bit?

    0
    None
    mrimgr

    1 year ago

    Welcome.

    Project AVR fuse bit?