Automatic PWM Battery Charger

Today we are going to make an automatic battery charger, an automatic battery charger is a charger which stops charging the battery when battery is fully charger. the automatic battery charger we are going to make uses PWM (Pulse Width Modulation) technique to charge the battery. this charger can be used with both 12V or 24V batteries, the charger has an auto battery detect feature. The supply voltage for this charger can be 30V to 40V, if we only want to charge 12V batteries we can use minimum 15V supply. first we connect the input supply to the charger the we connect the battery the charger automatically detects battery voltage and start charging the battery. We have used an Arduino to give the intelligence to the charger, the Arduino generates the PWM signal to its pin D9, the duty cycle of PWM signal varies according to battery voltage, the PWM duty cycle is inversely proportional to battery voltage, meaning if battery voltage goes above to the reference the PWM duty cycle decreases, and if battery voltage goes below to the reference the PWM duty cycle increases.  The steps to build this charger.

Step 1 :

An Arduino is used to control the duty cycle of PWM signal and to read the battery voltage, five IRFZ44 MOSFETS are used and connected parallel to each other means connect their pin number 1 of all the MOSFETS to each other, their pin number 2 to each other, and their pin number 3 to each other , a PC817optocoupler is used to isolate the Arduino and MOSFETS the optocoupler is connected to the pin d9 of Arduino which generates thePWM signal, a schottky diode is used to isolate the battery positive from the input positive, a buck regulator is used to convert the battery voltage to 5V to supply the Arduino MC34063 IC and a few more component are used to make the buck converter all the connections and components are given is the circuit diagram, a 2 pin terminal block is used as input terminal, we can give 15V to 40V at the input, another 2 pin terminal block is used for the output terminal, 6 LEDs are used to indicate the battery level, 74HC595 is is used to control the LEDs. A voltage divider is made with a 47K resistor and a 5K trimpot resistor to reduce the battery voltage to give the ADC of Arduino. I have made PCBs for the project you can find circuit diagram, Gerber files, component list and Arduino code below.

Step 2:

Now connect the Arduino to you PC and upload the code to Arduino

Arduino code

int i,data,pwm,bat,b,tmp;

float vo,cutoff,on;

void setup() {
  
  pinMode(2,OUTPUT);
  
  pinMode(3,OUTPUT);
  
  pinMode(4,OUTPUT);

 TCCR1B = TCCR1B & B11111000 | B00000001; // Set PWM frequency for D9 & D10:
  
 Serial.begin(9600);
   
}

void loop(){ 
  
  for(int j=0;j<3;j++){
    
      vo=analogRead(A0);
      
      vo=vo*.1;
      
      bat=bat+vo;
      
    for(int i=0;i<7;i++){
      
      if(i>7)i=0; 
      
      led(i,1);
      
      if(i>0)led(i-1,0);
      
      delay(100);
      
      }
      
     }
     
  bat=bat/3;
  
  if(bat<16){
    
  cutoff=14.4;
  
  on=13.8;
  
  b=12;
  
  }else {
    
  cutoff=28.8;
  
  on=27.6;
  
  b=24;
  
  }
  Serial.println(bat);
  
  delay(2000);
  
  while(1){  
    
    led(0,0);
    
    led(1,0);
    
    led(2,0);
    
    led(3,0);
    
    led(4,0);
    
    led(5,0);
      
    
    i++;
    
    if(i>7)i=0; 
    
    led(i,1);
    
    if(i>0)led(i-1,0);
    
    vo=analogRead(A0);
    
    vo=vo*.1;
    
    if(vo>cutoff)pwm--;
    
    if(vo<on)pwm++;
    
    if(pwm<0)pwm=0;
    
    
    if(pwm>100)pwm=100;
    
    if(b==12)tmp=1;
    
    if(b==24)tmp=2;
    
    if(vo>b)led(0,1);
    
    if(vo>b+(.4*tmp))led(1,1);
    
    if(vo>b+(.8*tmp))led(2,1);
    
    if(vo>b+(1.2*tmp))led(3,1);
    
    if(vo>b+(1.6*tmp))led(4,1);
    
    if(vo>b+(2.2*tmp))led(5,1);

  Serial.print(b);  
  
  Serial.print("V Battery ");

  Serial.print("output volt ");
  
  Serial.print(vo);
  
  Serial.println("V");
  
  analogWrite(9,pwm);

  delay(500);
  
 }
}
void led(uint8_t pin,bool val){

 bitWrite(data,pin,val);
  
 digitalWrite(2,LOW); //latch pin low

shiftOut(3,4,MSBFIRST,data); //shiftOut(datapin,clockpin,LSBFIRST/MSBFIRST,data);
 
 digitalWrite(2,HIGH);
  
  }

Components:
Circuit Diagram:
Icon

Circuit Diagram 0.00 KB 390 downloads

...
Gerber Files
Icon

Arduino pwm auto chr - CADCAM 110.80 KB 206 downloads

...
Arduino Code

Icon

Pwm_bat_chr 1.86 KB 232 downloads

...
Icon

Pwm_bat_chr 1.37 KB 200 downloads

...
Icon

Pwm_bat_chr 0.73 KB 234 downloads

...

1 thought on “Automatic PWM Battery Charger”

  1. your board you used and the gerber file board are not the same in addition it was easy to write the name of the component or the value instead of R1…R2….BVS….and so on…the rest i will try this board redesign and try.

    Reply

Leave a Comment