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


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.


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.


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


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!

<p>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?</p>
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.
<p>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.</p>
<p>hi swalehi<br>can you send me your pcb and other files?</p><p>mojtabajahangard90@gmail.com</p>
<p>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.</p>
<p>Sorry, but how to write 38k hex file in 32k controller</p>
<p>hi<br>i need pcb or layout file and partlist of this charger! please help me! send this files to my my email:</p><p>mojtabajahangard90@gmail.com</p>
<p>Hi,</p><p>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 &amp; partlist</p>
<p>thank you martin</p><p>but i have no expert khowledge about drawing of schematic to draw pcb! can you send me a pictur of pcb?</p><p>when finish you version2,2?</p>
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.
<p>Hi,</p><p>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 &amp; delivery times from Ebay</p>
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?
<p>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.</p>
My id is torrelcorp@gmail.com
Hi again<br><br>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. <br>Regards
2N3904 ?
<p>yeah, I used those</p>
Another quick one. In the schematic shouldn't the lcd backlight be connected to vcc thru a current limiting resistor instead of gnd?
<p>Q1 is a general NPN tranzistor. Q2 is a P-channel MOSFET. IRF9540 should work fine.</p>
Oops forgot to add . I dont have the mosfet you mentioned. Can i use IRF9540 or IRFP9140.
What's the component marked Q1
Hi Martin <br>This looks really interesting. Am attempting to build this. I'm sure i will have questions. Hope you dont mind helping me out?!
<p>sure I will help, just drop me a message or write in the comments :)</p>
looks very nice.somehow I missed seeing the part where you gave a complete list of materials and instructions for putting this together.<br>

About This Instructable




More by MartinD_CZ:Arduino-controlled True Switching Regulators How to Make Universal Battery Charger Simple AVR Laser Game Gun 
Add instructable to: