How to Make Universal Battery Charger

17,880

113

54

Introduction: 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

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!

Be the First to Share

    Recommendations

    • Halloween Contest

      Halloween Contest
    • Retro Tech Challenge

      Retro Tech Challenge
    • Micro:bit Contest

      Micro:bit Contest

    54 Comments

    0
    swalehi
    swalehi

    4 years ago

    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.

    0
    AkramM18
    AkramM18

    Reply 1 year ago

    Hi swalehi ! I need,Send my please.
    And If you have FUSE bit?

    0
    marboddm
    marboddm

    Reply 7 months ago

    Please send me the files. Thank You, Dan

    0
    MojtabaJ5
    MojtabaJ5

    Reply 4 years ago

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

    mojtabajahangard90@gmail.com

    0
    AkramM18
    AkramM18

    1 year ago

    That is PCB no testing, Chek it plaese.

    0
    AkramM18
    AkramM18

    1 year ago

    BTN block.

    BTN_.JPG
    0
    AkramM18
    AkramM18

    1 year ago

    PCB, No testing!!!

    Cgarger5110_Martin.JPG
    0
    AkramM18
    AkramM18

    1 year ago

    How it is fuse bit?

    0
    Willythered
    Willythered

    Question 1 year ago

    Hello, I'm very excited to source the parts and attempt this build. Before I do is there any new progress on version 2 with the balancing? If not this is what I will build. Thanks for the great design.

    0
    MartinD_CZ
    MartinD_CZ

    Answer 1 year ago

    Hi,

    I eventually abandoned it, mostly because of lack of time. But it is certainly possible. I released what I had on GitHub, so maybe you can get inspired from that...

    0
    ARD_MAN_328P
    ARD_MAN_328P

    2 years 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
    0
    MartinD_CZ
    MartinD_CZ

    Reply 2 years 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
    fly71
    fly71

    2 years 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

    0
    MartinD_CZ
    MartinD_CZ

    Reply 2 years 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
    fly71
    fly71

    2 years 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

    0
    MartinD_CZ
    MartinD_CZ

    Reply 2 years 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
    fly71
    fly71

    Reply 2 years 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
    gettingthere
    gettingthere

    2 years ago

    Hi trying to get in touch with you again