Arduino battery charger with opto-isolated CCS and 2 TL431 voltage comparators.
Fig. 1 Arduino battery charger with opto-isolated
CCS and 2 TL431 voltage comparators.
Click for larger image.

Solar Panel Battery Charge Controller Switching Circuit

by Lewis Loflin


Note: Indicator LEDs DP9, DP10, and DP11 not shown in schematic.

Related circuits and theory see the following:

TL431 shunt regulator circuit configured as a voltage comparator.
Fig. 2 A TL431 shunt regulator circuit configured
as a voltage comparator.

Optocoupler controlled constant current source with  LM317 and +5V regulator.
Fig. 3 Optocoupler controlled constant current source
with LM317 and +5V regulator.
Click for larger image.

Optocoupler controlled constant current source with  LM317 and +5V regulator for solar panel Charging.
Fig. 4 Optocoupler controlled constant current source with
LM317 and +5V regulator for solar panel Charging.
Click for larger image.

Arduino Code for Above Circuits



/*
	Arduino TL431 CCS Battery Charger
	Use pwm to control output current 
	for constant current source. Use 
	TL431 voltage detector.
	Connect both TL431 circuits to battery.
	PWM duty cycle is based on the TL431 comparators.
	by Lewis Loflin www.bristolwatch.com
*/

#define POT 0
#define PB1 2
#define PB2 3
#define TL431A 4
#define TL431B 5
#define pwmOut 6

// values measured on resistive load
// CCS set for 1.14A max.
#define ccsHigh 255
#define ccsMed 144
#define ccsLow 45
#define ccsOff 0

int temp = 0;

void setup() {
  // PB1, PB2 LOW if pushed, otherwise HIGH
  // yes I know about INPUT_PULLUP
  pinMode(PB1, INPUT);
  digitalWrite(PB1, HIGH);  // pullup
  pinMode(PB2, INPUT);
  digitalWrite(PB2, HIGH);  // pullup

  // High from TL431 Vin > Rset
  pinMode(TL431A, INPUT);  // Vin battery LOW
  pinMode(TL431B, INPUT);  // Vin battery HIGH

  pinMode(pwmOut, OUTPUT);  // To CCS optocoupler
  Serial.begin(9600);
  Serial.println("Serial OK");
}

void loop() {

void loop() {

  if (digitalRead(PB1) == 1 && digitalRead(PB2) == 1) {
    temp = analogRead(POT) / 4;
    delay(1000); // wait for release
  }  // variable 0-1 Amps

  if (digitalRead(PB1) == 0 && digitalRead(PB2) == 1) {
    temp = ccsHigh;
    delay(1000); // wait for release
  }  // 1 Amp

  if (digitalRead(PB1) == 1 && digitalRead(PB2) == 0) {
    temp = ccsMed;
    delay(1000); // wait for release
  }  // 0.5 Amps

  if (digitalRead(PB1) == 0 && digitalRead(PB2) == 0) {
    temp = ccsLow;
    delay(1000); // wait for release
  }  // 0.25 Amps

  analogWrite(pwmOut, temp);
  Serial.println("PWM value = ");
  Serial.println(temp);

  delay(5000);  // wait 5 Sec.
  
} // end loop


TL431 based sink-current regulator driving high current constant current source with optocoupler ON-OFF control.
Fig. 5 TL431 based sink-current regulator driving high current constant current
source with optocoupler ON-OFF control.
Click for larger image.


Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.