In Part 1 of this project, we covered the general design of the battery charger.  Part 2 described the physical construction of the charger.  In Part 3, we will cover the calibration and operation of the charger, and present the Arduino Nano source code for the project.

Once the board was populated, I isolated the output from the voltage sense resistors by removing the Jumper J3.  Then I fed a voltage into the sensors which was adjustable, and substituted for a real battery.  I set it up so that 30 volts resulted in 5 volts at the sense point, with 0 volts being zero at the sense point.  This gave me a linear range to work with. Jumper J3 is shown below in the operating position.

DSCN0308

And here is J3 in the calibrating position…

DSCN0309

 

In my first live testing with the mower, I found that the charger was not turning off when it should, which could result in overcharging the batteries and warping the plates, thus ruining them.  I first thought it might have been because of our Phoenix heat.  Troubleshooting showed that the 2N7000 FET was not turning the LM-317 off.  When I started to unsolder the bad 2N7000 from the board, I heard a click, and found that one of the leads had snapped off.  I remembered when installing it that I had bent the leads in an awkward fashion, and hoping that it didn’t break.  Well, it did.  For the replacement, I was more careful.  After replacing the transistor, all worked fine.

DSCN0310

Here is the Arduino Code:

charger.ino

Note** If you cut and paste the following code into your Arduino IDE, you may get some errors refering to “stray XXX”, with some numbers where the XXX is.

This is because of the way browsers save some characters as non-ascii characters.  I found that in particular, the quote marks in the various Serial.print and Serial.println statements are misinterpreted.  To fix this, you can erase the quote marks, and retype them in your Arduino IDE.  Then save and recompile the sketch.  That fixed it for me.

Alternatively, you may try downloading the code form the “arduino.ino” link just above this note.  Good luck, and have fun… Randy WB0SMX

 

/*
SLA Battery Charger
Control charging of sealed lead acid battery based on voltage.
the circuit reads a voltage sensor on battery. If voltage is less
than lower limit, charging current is turned on and remains on
until sensor voltage exceeds upper limit. At that point, the
logic turns charging current off and implements a delay before
taking next sensor read.
In this manner, the charging current works to gently keep the
battery voltage within the limits, while allowing it to be
exercised within those limits.

This circuit can be adjusted for any voltage of battery, by
changing the source voltage and adjusting the sensor to match
the measured battery voltage.

*/
#define OFF HIGH
#define ON LOW
#define LOWOFF LOW
#define HIGHON HIGH
int sensorPin = A0; // analog input pin for the sensor
int ledPin = 13; // Internal Arduino led pin
int chargePin = 6; // Drive pin for the pass device
int restLed = 7; // LED pin to indicate Resting condition
int chargeLed = 12; // LED pin to indicate Charging condition
int sensorValue = 0; // Value coming from the sensor
float voltsPerCount = 0.0; // Calculated value per count
float analogValue = 0.0; // Averaged Voltage Sensor read
float sensorAvg = 0.0; // Averaged Raw Count Sensor read
float sensorSum = 0.0; // Temporary storage for Averaging
int count = 0; // Counter for Averaging
float batteryMult = 6.0; // Multiplier from sensor to battery volts
// 5 volts full scale on sensor = 30 volts on battery
float analogRef = 5.00; // Voltage on external ARef pin
boolean charging = 0; // To keep track of state

void setup() {
analogReference(EXTERNAL); // set to use ARef pin
pinMode(ledPin, OUTPUT); // Onboard charge indicator
pinMode(restLed, OUTPUT); // External Rest indicator
pinMode (chargeLed, OUTPUT); // External Charge indicator
pinMode(chargePin, OUTPUT); // Set up Charge driver pin
Serial.begin (9600); // Set up Serial Communication
// Give a startup indication on LEDs

for(count = 1;count <=5;count++)
{
digitalWrite(chargeLed, OFF);
digitalWrite(restLed, OFF);
digitalWrite(ledPin, LOWOFF);
delay(250);
digitalWrite(chargeLed, ON);
digitalWrite(restLed, ON);
digitalWrite(ledPin, HIGHON);
delay(250);
}

// turn off charging to start;
digitalWrite(chargePin,OFF);
digitalWrite(chargeLed, OFF);
digitalWrite(restLed, ON);
digitalWrite(ledPin, LOWOFF);
// calculate volts per count;
voltsPerCount = analogRef/1024;
}

void loop() {
// read the value from the sensor:
for(count = 1;count <=5;count++)
{
sensorValue = analogRead(sensorPin);
sensorSum += sensorValue;
}
sensorAvg = sensorSum / (count-1);
sensorSum = 0.0;
analogValue = sensorAvg * voltsPerCount * batteryMult;
if (analogValue <= 27.6)
{
// turn on charging;
digitalWrite(ledPin,HIGHON);
digitalWrite(chargePin,ON);
digitalWrite(chargeLed, ON);
digitalWrite(restLed, OFF);
charging = 1;
}
else if (analogValue >= 29.0)
{
// turn off charging;
digitalWrite(ledPin,LOWOFF);
digitalWrite(chargePin,OFF);
digitalWrite(chargeLed, OFF);
digitalWrite(restLed, ON);
charging = 0;
//delay(4000);
}
Serial.println(“”);
Serial.print(analogValue);
Serial.print(” volts “);
Serial.println(“”);

if (charging == 0)
{
Serial.println(“RESTING”);
delay(4000);
}
else
{
Serial.println(“CHARGING”);
delay(250);
}
}