|
» About me » Bristol VA/TN » E-Mail » Hobby Electronics » Arduino Microcontroller
Solar Panel Charge Controller Using Arduino Microcontrollerby Lewis Loflin To see the Picaxe version of this page see Solar Panel Charge Controller Using PICAXE Microcontroller
Purpose: to cycle to charge voltage on/off and to check other aspects such as solar panel input voltage when charging lead-acid batteries. The LED1 indicator 'bad' meaning the input voltage below the charging voltage when on. DP11 turns on charge switch transistor. Can use PWM or a simple timing routine. Will blink on/off with charge cycle. (Charge enable) LED2 indicator fully charged battery. (DP10) A 10-bit analog-to-digital converter (ADC) has a step voltage of about 4.9 mV over a 5-volt range. This relates to the charge point (CP) variable. To measure input voltage from the solar panel and the voltage on the battery we use a voltage divider to drop the voltage below 5-volts. This uses two resistor voltage dividers (15k and 2.2k) which produces a voltage of about 1.7 - 1.9 volts when fully charged. This equates to about decimal 346 - 400 from the ADC and is compared to the charge point variable CP. Note line "chon = CP - y * 1000" when uncommented the charge 'on' time will decrease gradually as battery is more charged. When fully charged the charge voltage is disabled. The variables chon (charge on time) and choff (charge off time) can be preset to any value. One can experiment with this CP value. Too small, battery won't fully charge. Too large, battery will over charge. The voltage input is connected to AD0 while the voltage on the battery is monitored at AD1. This same circuit can be used with a 24-volt system by changing the 15K to 27K, and using a 24-volt relay. The power for the Arduino itself can be obtained from the battery bank under charge through a 5-volt regulator or separate supply. Note if the battery bank is completely dead the circuit won't function with no power to the Microcontroller. A separate source for the controller is recommended. This circuit will also work using a power supply instead of a solar panel as a simple battery charger. The Code/* Solar cell battery charger/regulator Dp12 LED1 indicator 'bad' meaning the input voltage below charging voltage. Dp11 turns on charge switch transistor. Can use PWM or a simple timing routine. Will blink on/off with charge cycle. Dp10 LED2 indicator fully charged battery This uses two resistor voltage dividers (15k and 2.2k) which produces a voltage of about 1.7-1.9 volts when fully charged. This equates to about decimal 346-410 from the ADC. The voltage input is connected to AD0 while the voltage on the battery is monitored at AD1 */ #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 = 389; // 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 }
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.
If using this material on another site, please provide a link back to my site. |