A Charger Lightly – How to Build a Battery Charger Part 1

A Charger Lightly – How to Build a Battery Charger Part 1

By: Lasse Jaspersen

In this 2-part series on how to build a battery charger for a solar tracker (instructions to follow), you will learn how to:

  • Build a 12V lead-acid battery charger
  • Use an Arduino Nano to control the charging circuit
  • Use perfboard for plated-through-hole (PTH) soldering of a circuit.
  • Mount a circuit on “something”, just until you find the right box
  • to put it in.

There is a lot to cover, so we have split it up into Part 1 and Part 2.



How to Build a Battery Charger

How to Build a Battery ChargerComponents You’ll Need:

  • 2 x throw switches; one for the power input, and one for switching the battery.
  • 1 x LM317T
  • 2 x 2 port screw terminals
  • 2 x 220 ohm resistors
  • 3 x 1k ohm resistors
  • 1 x 4.7K ohm resistor (for IRF9630 pull-up)
  • 1 x 51K ohm resistor (for zener pull-down)
  • 1 x 10V zener diode
  • 1 x 5V relay (one channel is needed, more can be used)
  • 1 x generic tiny diode (for relay flyback protection)
  • 1 x IRF9630 P-channel power MOSFET
  • 2 x BC239 NPN transistors (or equivalent NPN type transistors)
  • 1 x 4.7uF ceramic capacity (~20V)

How to Build a Battery Charger Overview

For our upcoming Arduino-based solar tracker instructions, one thing is just as important as the solar panel and the Morai micro linear actuators that will keep the panel perpendicular to the sun. It is all well and good to be able to convert the divine sunshine at any given moment into a usable current for the same moment, but to preserve it takes a little effort.

In this piece, we’ll be going over how to build a nice little charger module that won’t break your budget. It can charge a 12V lead-acid battery (car, motorcycle, scooter, any kind, as long as it’s lead-acid; a proven technology), to 12.7V.

A quick overview is in order. From the panel (ours uses bypass diodes and a blocking diode for maximum efficiency) we get an output of X watts. The voltage – my test panel is 36V/0.3A = 11.88W – must be dropped to 14.67V using a step-down converter. The current limiter drops 1.17V, so at the MOSFET we output 13.5V. There’s a small blue potentiometer (known as a trimpot) on that IC . The flat little screw should be turned until you get 14.67V on output.

From this output, we pass our power into an LM317T current limiter. A current limiter has one purpose, so it is a simple little circuit. There’s a voltage drop, and a loss of effect (watts), but it doesn’t matter when we get up to using 80-100W solar panels. The LM317T current limiter does need a heatsink, so we attach a small heatsink, good up to 2-3W.

The formula to calculate the output current is:

I_OUT = VREF / R1 = 1.25V / 1.25R = 1A

The formula to calculate loss to heat, which must be dissipated, is:

P = (I**2) x R1 = (1**2) x 1.25R = 1.25W

In practice, the heatsink attached to the LM317T tab goes up only 4-5 degrees celsius, so there’s no need to worry.

Here  (lm317_calc.py) is a convenient calculator written in python3 for both voltage regulation and current regulation using an LM317. It can be run cmd.exe on Windows or gnome-terminal on Ubuntu, here’s example output for the R1 value used in our current regulator:

$ lm317_calc current 1
R1 = 1.25V / 1.00A = 1.25R
P = ( 1.00A ** 2 ) * 1.25R = 1.25W
The LM317 will require heatsinking to dissipate this effect.

( You can download python3 from http://www.python.org )

We only wish to charge our lead-acid battery at a maximum of ~13.5W, so we pass this 1A from the current limiter into an IRF9630 P-channel power MOSFET. I go into more detail about this later, but suffice to say that the MOSFET is a good way to control the flow to the battery.

There’s a very small loss of effect here, since the IRF9630 has a R_DS of 0.8 ohms; P = (I**2) x R = (I**2) x 0.8R = 0.8W

Regardless of this low value, we heatsink the MOSFET so it should be good up to 2-3W. For heavier loads, a small 5V relay should be used – a greater loss of effect is not acceptable. A single 5V relay uses ~0.33W with the Normal-Open path closed, so there is that to consider before using one.

The IRF9630 handles the charging into the battery. Be mindful that we only wish to pass 13.5V from DRAIN to the battery’s positive terminal, while wiring the negative terminal back to GND. Charging at a voltage greater than 13.8V has a negative effect on lead-acid batteries. In the last few weeks I’ve discussed this with an auto-mechanic and an electrician, and while both would use 14.7V at C/1 to quick-charge a 12V battery, they conceded that anything above 13.8V leads to dissipation of water in the battery, and thus a decline in its expected lifetime. I will interject here that there are many different ways to charge a 12V battery, but the best practice I’ve been advised to follow by an engineer is to charge at a constant current (CC) of C/1, where C denotes the Ampere hours (hereafter ‘Ah’), or charge of the battery. C/1 in this case  is 9Ah, so it would be good to charge at a constant current (CC) of 9A – 13.5V x 9A = 121.5W, for at least one hour, until reaching a stable battery  voltage of 12.7V read with vSense().

Using a CC of C/5 (4.5A) is also acceptable, but we settle on a max CC of ~C/10. At the end of charging period it is prudent to level out the cells with a trickled charge of C/20 (450mA). The end of the charging period has in this project been defined as the point in time where the battery (with the charge OFF for at 10 seconds before sensing the voltage) reads 12.7V. Then we charge for a while longer, continually poll the  battery’s voltage, until it needs to be charged again. This is just not  realistic with my puny test panel, especially not in darkest February – so  in the images the step-down converter is fed from a 90W laptop charger. The final fact worth noting is that 12V lead-acid batteries do not start charging until they receive a voltage of 12.8V or above.

It all sounds very complex, but in practice you can take any 13.5V charger, from C/1 to C/10 and charge until the battery reads 12.7V. Remember to wait 10-20 seconds after disconnecting the charger before reading its voltage. We can, for simplicity’s sake, call 12.7V ‘100%’, fully charged, and 11.5V ‘0%’, empty.

There’s a caveat to this charge-baboonery, which must be mentioned.

When you charge a 12V lead-acid battery, hydrogen gas is released from its cells. How much depends on the voltage and current. It is always a bad idea to go above 13.8, but if you charge with a CC of e.g. C/1, in this case 9A, you should be sure that there’s some ventilation in the locale where you charge. Old discarded 12V batteries are not just ‘left in a big room somewhere’, there are ventilation systems in place to prevent a build-up of hydrogen gas. Hydrogen gas is explosive (above a certain concentration  threshold) – but this is not Mythbusters, so we’ll have no explosions just  to prove a point. Consider yourself warned, but don’t get nervous. The  charger is for mounting on a solar tracker after all, charges at a maximum  of ~C/10, and will mostly do its charging outdoors.

To sense the battery voltage, and the charge voltage, a zener diode with a 51K pull-down is used. The reading is smoothed out, with 10 reads over a period of 2 seconds. The zener diode drops 9.29V, allowing our Arduino Nano to read it with analogRead(). The default voltage reference for the Nano is 5V, so it would act a bit surprised if it saw a 12.7V signal on an analog input. Across the zener diode, instead the Arduino sees a 4.21V signal when the chargeVoltage is 13.5V, and 3.41V when the batteryVoltage is 12.7. By using the zener drop as an offset, we get a good way of sensing voltage. We use this bit in vSense() to read the voltage:

// reading is smoothed across 10 readings, which are averaged out
voltage = reading * ( vRef / 1023 ) ;
voltage = reading * ( 5.0 / 1023 ) ;
// No voltage reaching vRefPin, do not include zenerdrop in return value
// Most likely charger and battery are disconnected
if( voltage == 0.0 )
return 0 ;
// Include the zenerdrop in return value
return voltage + zenerDrop ;

The zener diode is wired parallel to the output (DRAIN) of the IRF9630, so it can read both charge voltage and battery voltage, depending on whether the MOSFET is passing a charge or not. As mentioned above, it is necessary to wait a moment until the battery voltage settles before reading it.

The positive wire from the MOSFET (which has its SOURCE connected to the positive output of the LM317T current limiter) goes to the positive terminal of the battery – but what about using the power we are storing? Simply splice an extra wire capable of carrying ~20W of effect into the COM terminal of a relay.

From there, when the relay is driven HIGH by our BC239 NPN transistor, the Normal-Open (‘NO’) path is opened, and from the ‘NO’ terminal continue the positive connection into your loads. I needed a small charger for phone and miscellaneous, so I put one of our step-down converters inline, and it now happily delivers ~2.5W to an off-the-shelf ‘On the Go’ USB hub that can provide a set of USB type A, female ports to e.g. an Android phone, or, if a switch is flipped, let you charge devices connected to it. That gave me 3 USB ports that can pull their charges from the battery. Had to heatsink it a bit for 2.5W.

That’s done for Part 1 on How to Build a Battery Charger. Next we will cover the wiring for the perfboard and pth-soldering.

Click here to continue to Part 2 (coming March 20)

Leave a Comment