Arduino battery charge controller.

Arduino Battery Charge Controller

by Lewis Loflin

This is a simplified version of my Solar Panel Battery Charge Controller Using Arduino. One can easily add the ideas from that project to this one.

Above is a generic Arduino Nano, but the code will work on any Arduino style microcontroller. The 5V regulator is build into the unit I used and if not use a separate 5V supply.

The battery voltage is measured from the TP1. The 10V zener diode drops 10V leaving a voltage value of 0v-5V at TP1. Normally the battery/charge voltages range from 12V-14V. The Arduino ADC returns a 10-bit value from 0-1023 based on an input voltage of 0V-5V. A value of Vin should return an ADC number of about 600 based on a 12.7 volt input. The idea is if the battery voltage drops below 12.6V turn on the charge current from the solar panel, turn off the current then wait, then measure again.

A HIGH from DP2 switches on Q1/Q2. Q1 is a PNP bipolar transistor. In addition by adjusting the value of 1K resistor on Q1's base we can introduce current limiting in addition to acting as a power switch. See Introduction to Constant Current Circuits. Note in the video I was charging a 12-volt lead-acid sealed gel-cell type battery.

This is for small applications and if trying to charge a 1000-watt battery bank buy a commercial unit. Add a heat sink to Q1 if needed - other PNPs will work if they have sufficient collector current. See the following on various types of switching transistor circuits:

Zener diode switch circuit.

The above uses a transistor switching circuit to turn on the zener diode circuit to do a voltage measurement. This prevents the small, but steady discharge of the battery. You will have to add that to the following code.

Solar cell battery charger/regulator

#define Vin 0
#define CE 2 // charge enable
#define chon   4000 // charge on time
#define choff  4000 // charge off time
#define CP  600 // charge point variable

int val;

void setup()   {
  pinMode(CE, OUTPUT);
  digitalWrite(CE, LOW);

void loop()   {

  val = analogRead(Vin);
  while (val > CP) {
    val = analogRead(Vin);
    Serial.print("Charge off val = ");
    Serial.print("Vbat = ");
    Serial.println(val * .0048 + 10.0);
  digitalWrite(CE, HIGH);
  digitalWrite(CE, LOW);
Serial monitor Arduino

The above program will produce this out on the Arduino serial monitor.

LM317 current limiter used with solar panel.

I used this circuit to protect my solar panel charging system. The solar panel can produce a maximum current of 500mA. A really drained lead-acid battery can look like a dead short so this safely limits the current to protect the panel from possible damage.

The formula is Iout = 1.25V / RE. For 500mA RE = 2.5 Ohms.