Arduino solar PWM charge controller

Suitable for any current rating using 12V lead-acid batteries

This document gives a vormgeving for a PWM solar charge controller suitable for use with 12V lead-acid batteries. It is able to monitor battery voltage, charge current and explosion current, and manage the charge process appropriately. The current capacity of the charger depends upon the choice of MOSFETs and cooling arrangements, but even without heatsinks it can treat ten amps. The controller uses only low-cost components, including either an ATMega328 or Arduino spil a microcontroller, and is suitable for either hobbyist building or mass-production. A controller of this type is suitable for a puny solar power installation of three hundred watts or less spil might be found on an outbuilding, boat, RV, or a very petite off-grid huis.

This project is based te part on one I designed and built previously, a PWM charge controller utilising an arduino and an INA219 voltage-current sensor. The of this vormgeving wasgoed comparable to any commercial PWM controller of similar price, but had some drawback I determined needed addressing. The INA219 chip made it unlikely to monitor geyser or charging currents separately without a 2nd chip, preventing the inclusion of an over-current flow disconnect capability, and the opto-isolator MOSFET drive used more current than ideal and ran the MOSFET unsafely close to maximum Vgs. The prototype also failed during a thunderstorm, with the INA219 kicking off to read only spil zero or full-scale voltage, which raised concerns about susceptibility to atmospheric electric current. This vormgeving is an attempt to juist thesis flaws

However low cost to construct, this vormgeving is a capable charge controller for small-scale, 12V installations up to 200W spil may be often seen on outbuildings and mobile homes. It supports all of the essential features, except for the blocking diode – for reasons explained below, I choose to keep this spil a separate unit installed inline to the panels.

  • Effective regulation of battery charging, including decent use of saturation charge and come back to float when charge is accomplish.
  • Prevent battery over-discharge by disconnecting power to the fountain should the battery voltage fall below a level healthy for the battery.
  • Monitoring of charge state, output to a multiplicity of instruments or transmitters – it’s lightly adaptable.
  • Measurement of supply, battery and fountain current, again output to a diversity of instruments or transmitters spil required.
  • Automatic disconnect of the fountain on over-current condition.
  • Maximum open-circuit panel voltage of 20V.

Fundamentals of vormgeving.

For ease of understanding and manufacture, this vormgeving can be split into a number of sections which can each be assembled and tested independently before being connected fully. Spil it is designed to be hobbyist-friendly, it can be assembled entirely using through-hole components on stripboard – there is no need for PCB fabrication or high-skill SMD soldering. All power MOSFETs are N-channel type, which permits for lower Ron and so diminished energy loss and enhanced current treating capability.


The control section is designed to use either an arduino professional mini (8 or 16MHz), or a nude ATMega328 with the internal RC oscillator – the latter is more suited if you intend to mass-produce thesis, the former for development and hobbyists. It includes not just the processor, but also the Trio.3V regulator and the voltage divider used for measuring battery voltage. This regulator vereiste be capable of a high level of precision ter order to accurately monitor battery voltage. Not all regulators can do this. The ‘official’ Arduino Voor Mini Trio.3V uses a MIC5205 regulator, which is capable of sufficient accuracy at a maximum current of 100mA, but is still unsuitable spil it has a maximum input voltage of only 16V: No good. A suitable regulator is the LP2950 – Three.3V, high-precision, 30V max input. The current consumed by this charge controller is very puny, so there would be no significant advantage ter a switching supply.

The 1000?F capacitor on the regulator input is not just for smoothing out noise: It stores enough power to run the electronics for 300ms at 40mA draw, which is enough for a display. This is part of the over-current cutoff feature, preventing the microcontroller from resetting during a epistel loss of power. 300ms is more than long enough to detect the over-current condition and shut off the blast.

The control houtvezelplaat has three analog inputs (input current, output current and compensation) and two digital outputs (Input switch and output switch) that are core to the function of the charge controller, plus whatever inputs and outputs are required for the controls (A ondergrens of one button, but you are free to add whatever interface component you wish, subject to power constraints). The input and output switching boards are all designed to accept ordinary Trio.3V logic, so the control houtvezelplaat is truly nothing more than a microcontroller and the most basic power supply.

At a ondergrens, this controller needs a single button spil a user interface (To reset power after over-current shutdown). The addition of an OLED or LCD display is strongly advised to display battery voltage and currents, but not rigorously required. If you want you can go over-the-top and do something with analog meters and an elaborate steampunk-styled carved wooden case – but don’t go overheen 100mA on the regulated Three.3V rail, or the LM2950 will not assure decently regulated output. The firmware I have written assumes an I2C-interfaced 128×64 OLED display.

The divider should be a ratio of at least a ratio of 1/8. This corresponds to a maximum measurable voltage of 26V – the voltage which may be encountered during fault condition, if the battery is disconnected while the panels are under optimal lighting condition. The ratio does not need to be precies – there is no need for 0.1% resistors, because the precies ratio can be measured spil part of the initial calibration process and configured into the firmware. I used a Two.2K? and 22K? resistor.

If you are using an arduino, there is very little to this houtvezelplaat: Regulator, divider, capacitors, diode, that’s it. Connect to the following pins:

If you are using a nude ATMega328, same thing but with an extra reset button and speld headers for programming.

During development I used an Arduino uno for testing purposes. If you want to do that, no problem – just connect the Three.3V line from the regulator to Vref on the Uno and adjust the firmware for outer reference.

Current measurement.

Te order to decently charge a lead-acid battery, both battery voltage and current vereiste be measured – the voltage to within a high degree of accuracy, the current less so. While my previous vormgeving used an INA219 chip, this component is not available ter through-hole form and can be difficult to obtain, and did not provide the capability to also monitor current from the input or to the flow. The failure of this component ter a previous prototype also raises concerns.

Bidirectional current shunt measuring is difficult – it requires a more expensive op-amp specialised to the purpose or a differential ADC such spil the ADS1115, which is not available ter through-hole form. With some creative shunt placement, calibration and software compensation it is flawlessly posible to gather all the required measurements instead using two unidirectional shunts – this needs nothing more than a very common LM358 dual op-amp and a few resistors.

My solution uses two shunts, producing output voltages Vi (input) and Vo (Output). The LM358 amplifies thesis into the range required for the ADC, 0-1.8V. Note not Trio.3V: While the LM358 can accept an input at ground and sway the output to within 20mV, it can’t go all the way to supply rail. The firmware interprets anything overheen 1.9V from the output current amplifier spil an over-current condition and instantaneously disconnects output power.

Two potentiometers are used to adjust the amplifier build up so that the output is 1.8V under the designed maximum current. More precise calibration can performed by coming in precies I/V ratios ter firmware for enlargened accuracy. This treatment means there is no need for precision shunts or concerns about parasitic resistance: Simply waterput ter a length of wire or more-or-less suitable value, then adjust the potentiometers and firmware constants to accommodate it. I used aluminium wire, it makes a workable shunt.

There are two other factors which voorwaarde be calibrated and compensated for.

  • The LM358 does have a DC bias, but spil this is onveranderlijk the controller can partially compensate for by taking a zero-reading at power on.
  • The orkestratie of the shunts and amplifiers means that the amplified output Voi also includes the non-amplified output of Vi. This is a very petite figure te comparison, but requires one extra ADC reading of Vi to subtract from the Voa reading. This could be avoided with a few more resistors of greater precision, but the method used here reduces part count.

Te total, the calibration process to ensure accurate measurements requires taking three measurements after the charge controller is assembled:

  1. Supply a known voltage on the battery connector and note the ADC reading from the voltage divider to determine divider ratio. Adjust firmware appropriately. This can be avoided by using 1% precision resistors.
  2. Run a known current through Ri, adjust build up pot so that max-current would give an output of 1.8V. Adjust firmware spil adequate for fine-tuning.
  3. Run a known current through Ro, adjust build up pot so that max-current would give an output of 1.8V. Adjust firmware spil adequate for fine-tuning.

DC offset compensation te the positive direction is fully automatic, and does not need to be by hand set. Thesis measurements complicate initial setup, but eliminate the need for high-precision shunts and resistors and most of the constraints on op-amp selection, reducing the cost and making it lighter to obtain suitable components.

An significant consideration is stability of the reference voltage. See the ‘control’ section for more on this. It is essential that the Trio.3V rail is exactly Three.3V, with high precision, spil it serves spil the ADC reference.

All of this vormgeving is intended to be cheap. Very cheap. Aluminium wire or long PCB tracks rather than mangalin alloy shunts, calibration proces te place of precision components, and a low-cost op-amp rather than decent instrumentation amplifier or shunt amplifier. Accuracy is compromised to achieve this aim: Perhaps +-10% accuracy may be expected. It’s poor, but it’s good enough to make the key measurements needed to determine when to switch charge mode and when to trigger over-voltage disconnect, and that’s the significant part.

A potential refinement would be to run the LM358 off of the common positive supply, rather than the Three.3V rail, with resistors inserted before the ADC inputs. This would permit the total ADC input range to be used, enlargening precision.

Input power switching.

The decision to use N-channel MOSFET for charge control can require some unusual layouts. I have seen three solutions to this problem: A charge pump (Spil seen ter the PWM5), an opto-isolator drive (Spil seen ter my previous vormgeving) and this vormgeving using an intermediate transistor. I used a P-channel MOSFET spil an intermediate, but a PNP bipolar or JFET could also be used. This vormgeving also permits the use of a zener pin to limit Vgs and prevent MOSFET harm. To achieve a reasonably prompt fall time on the gate requires a resistor of at most 47K? connected from source to gate. This gives a fall time of 0.2ms – slagroom for improvement, but good enough for the 245Hz PWM frequency used here. I originally attempted a 100K? resistor, but this lead to excessive switching losses and an overheated MOSFET.

One major advantage of the N-channel MOSFET spil a switching factor is that, with careful choice of a MOSFET with very low Ron, power dissipation is very low. The IRF3205 is readily available and has an Ron of only 8m? – even at 20A, it will dissipate only Trio.2W. At 10A, it doesn’t even need a heatsink.

A notable omission te my vormgeving is the blocking diode. I have left this out to permit some plasticity te use – spil hobbyist solar setups are not standardised, not every user needs the diode te the charge controller. I use an outward MPPT optimiser which includes this diode, others may wish to use an ideal diode module, or numerous blocking diodes for combining power from many panels. An earlier revision included an ideal diode incorporated into the input switching, but I determined this over-complicated the vormgeving.

I have previously designed an ideal diode diode circuit which will vleierij this charge controller flawlessly. Most of the components are collective.

Spil this is a PWM controller, not an MPPT, no high-frequency MOSFET drive is needed.

Using PWM to control charging does have a notable drawback: It creates a loterijlot of noise. This noise can be radiated from the panel, battery or blast cables. Without filtering this could result ter severe noise on the fountain output. Worse, it also presents on the battery – peak voltages above fifteen volts could have electrochemical effects that will severely shorten battery life. A few well-placed 1000?F capacitors take care of the worst of it.

This vormgeving could be adapted for MPPT, but that would require the use of a MOSFET driver chip, a physical layout more suited to high-frequency operation, careful consideration of gate ringing, a large high-current inductor and more sophisticated software. This is why MPPT charge controllers are more expensive. Even so, this charge controller is half-way to being MPPT capable and such extension may be a project for future consideration.

Output power switching.

Switching of the fountain is required primarily to prevent over-discharge of the battery, but is also used to disconnect the fountain under over-current or by hand by pressing the control button. This is also via an N-channel MOSFET, but this time is simpler to drive spil it shares the ground potential of the ATmega. A BS170 is again used, but this time just to shift the Trio.3V output of the ATmega up to a level that can operate the power MOSFET. While the gate voltage cannot exceed the safe range under normal operation, it may toebijten if the battery is disconnected or fails, so again a zener pin is required. Most N-channel MOSFETs will work, but I suggest the use of the IRF3205 again spil it has a very low Ron and so minimal fever dissipation – which means little heatsink. You might also want to waterput the MOSFET off-board ter order to make it lighter to connect thicker wires.

Another capacitor here is used to help sleek the outgoing current, permitting for lighter measurement.

One punt to be aware of is the variation ter output voltage according to battery voltage – if you power lights off of this directly, their brightness will vary fairly noticeably with battery charge. If you want to fix this, you can just waterput a DC-DC converter module on the output.

Construction considerations.

Parts of this circuit involve high currents – even a 100W installation for use with a lead-acid battery may go spil high spil 10A from the panels when charging, and fountain current could exceed this. Such high currents are difficult to treat on stripboard or PCB without resistive losses. To help overcome this, the fountain, battery and panel terminals all share a common positive rail. A glad consequence of the decision to use N-channel MOSFETs for power switching, this also makes construction lighter spil they can all be brought to a common terminal block.

I have used three types of transistor ter this vormgeving: BS170 N-channel small-signal MOSFET, VP0106 P-channel MOSFET, and IRF3205 power MOSFET. Thesis are all very common, lightly available parts – but, should you want to substitute them, this is not difficult. You can substitute them with just about any MOSFET of matching channel and, for the power MOSFET, current capacity. The only constraint is that the BS170 is switched by Trio.3V logic, and so any substitute vereiste have a suitably low threshold voltage. Alternatively, they could be substituted with a 2N2222 bipolar transistor with suitable base resistor.

The display I used is the 128×64 monochrome I2C OLED. There are a loterijlot of thesis little OLED displays available, so if you cannot get the precies one you may need to slightly alter the firmware. You could also substitute it with another display device entirely, but this will obviously require substantially more alterations.

Software and charging argorithm.

The firmware is arduino-based, and can run on an 8MHz Three.3V arduino professional mini. Operating on a 16MHz arduino may require some adjustment due to the higher default PWM frequency.

Lead-acid batteries are a moderately difficult battery to charge decently. Doing so requires precise measurement of the battery voltage, and measurement of current with less precision. This firmware uses a two-state specimen: A saturation charge that maintains a battery voltage of Vcharge until the current required to do so (subject to a peak follower to discount the effect of passing clouds) falls below a set theshhold Icharged, at which point it transitions to a float charge that maintains a 2nd, lower voltage of Vfloat. Transition to saturation charge comes when the voltage falls below a set voltage (11.0 to 12.0V typical) or after 240 hours, whichever comes very first. This charge process is based upon that described on pagina 73 of the GNB Industrial Power Handbook for Stationary Lead-Acid Batteries, Part 1.

The precies values of thesis depend upon the battery. However all lead-acids use the same electrochemistry, variations te such factors spil electrolyte concentration and plate alloy material can affect the optimal voltages. If possible, thesis should all be set ter accordance with the datasheet provided by the battery manufacturer te order to maximise battery life – but, if this information is not available, the source code includes ‘preset’ suggestions that will be approximately onberispelijk for flooded batteries, AGM batteries and gelled batteries, based on figures from a BBL guide to battery charging.


Leave a Reply

Your email address will not be published. Required fields are marked *