I've made a circuit for solar charge controller. The problem with this circuit is that when the Induino board is power through USB port from laptop, the code works fine. But when I use the same battery which is being sensed as supply to run the board, the Led's all are ON, indicating malfunction.
Here's the code.
#define voltage_in 0
#define voltage_out 1
#define LED1 12
#define LED2 10
#define charge_enable 11
int x;
int y;
int chon = 5000; // charge on time
int choff = 2000; // charge off time
int CP = 368; // charge point variable
// CP sets the battery charge voltage level. Can vary from 346 - 410.
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(charge_enable, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(charge_enable, LOW);
}
void loop() {
x = analogRead(voltage_in); // voltage from solar panel
//under CP on ADC indicates not enough voltage to charge battery
y = analogRead(voltage_out); // voltage on battery to be charged
// over or equal to CP on ADC indicates fully charged battery
if (x < CP) digitalWrite(LED1, HIGH);
else digitalWrite(LED1, LOW);
// LED off indicates good input voltage
if (y > CP) digitalWrite(LED2, HIGH);
else if (y <= CP) digitalWrite(LED2, LOW);
// LED on means battery is charged
if ((x > y) & (y < CP) & (x > CP)) { // check input voltage and voltage on battery
// turn on charge cycle if voltage input good AND battery voltage low.
digitalWrite(charge_enable, HIGH); // turn on voltage to battery
chon = (CP - y) * 1000;
delay(chon); // ON wait
digitalWrite(charge_enable, LOW); // turn off charge enable
delay(choff); // OFF wait
} // end if
}
Arduino board.docx (1.15 MB)