Anda di halaman 1dari 4

/*

muhammad alfiyan nafis


subdiv.of power system engineering
div.of electrical engineering
engineering faculty
university of august 17th 1945
*/
#include <LiquidCrystal.h>
float solar_volt =0; // tegangan solar sel
float bat_volt=0;
// tegangan baterai
float sample1=0;
// pembacaan pin A0
float sample2=0;
// [embacaan pin A1
int pwm=6;
// keluaran sinyal PWM pada gate mosfet
int load=9;
//load is connected to pin-9
int charged_percent =0;
LiquidCrystal lcd(12,11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 sebagai Kontrol backlight
int RED=7;
// indikator penggunaan baterai
int GREEN=8;
// indikator pengisian dan penuhnya baterai
void setup()
{
TCCR0B = TCCR0B & 0b11111000 | 0x05; // setting prescalar untuk frekuensi 61.0
3Hz pwm
Serial.begin(9600);
pinMode(pwm,OUTPUT);
pinMode(load,OUTPUT);
pinMode(RED,OUTPUT);
pinMode(GREEN,OUTPUT);
digitalWrite(pwm,LOW);
digitalWrite(load,LOW);
digitalWrite(RED,LOW);
digitalWrite(RED,LOW);
pinMode(backLight, OUTPUT);
//set pin 13 sebagai output
analogWrite(backLight, 150);
//kontrol intensitas backlight 0-255
lcd.begin(16,2);
// kolom, baris, ukuran display
lcd.clear();
// display kosong
}
void loop()
{
lcd.setCursor(16,1); // set kursor
lcd.print(" ");
// tampilkan karakter kosong
/////////////////////////// VOLTAGE SENSING /////////////////////////////////
///////////
for(int i=0;i<150;i++)
{
sample1+=analogRead(A0); //baca tegangan output solar panel
sample2+=analogRead(A1); //baca tegangan baterai
delay(2);
}
sample1=sample1/150;
sample2=sample2/150;
// actual volt/divider output=3.127
//2.43 is eqv to 520 ADC

// 1 is eqv to .004673
solar_volt=(sample1*4.673* 3.127)/1000;
bat_volt=(sample2*4.673* 3.127)/1000;
Serial.print("solar input voltage :");
Serial.println(solar_volt);
Serial.print("battery voltage :");
Serial.println(bat_volt);
// ///////////////////////////PWM BASED CHARGING ///////////////////////////////
/////////////////
// As battery is gradually charged the charge rate (pwm duty) is decreased
// 14.4v = fully charged(100%)
// 12v =fully discharged(0%)
// when battery voltage is less than 12v, give you alart by glowing RED LED and
displaying "DISCHARGED..."
if((solar_volt > bat_volt)&& ( bat_volt <= 12.96 ))
{
analogWrite(pwm,242.25); // @ 95% duty // boost charging// most of the charging
done here
Serial.print("pwm duty cycle is :");
Serial.println("95%");
}
else if((solar_volt > bat_volt)&&(bat_volt > 12.96)&& (bat_volt <= 14.4 ))
{
analogWrite(pwm,25.5); // 10% duty // float charging
Serial.print("pwm duty cycle is :");
Serial.println("10%");
}
// // shut down when battery is fully charged or when sunlight is not enough
else if ((bat_volt > 14.4) or (solar_volt < bat_volt))
{
analogWrite(pwm,0);
Serial.print("pwm duty cycle is :");
Serial.println("0%");
digitalWrite(GREEN,LOW); // green LED will off as no charging is done during thi
s time
}
///////////////////////////////////////// BATTERY STATUS INDICATOR ////////////
////////////////////////////////////
//The map() function uses integer math so will not generate fractions
// so I multiply battery voltage with 10 to convert float into a intiger value
// when battery voltage is 6.0volt it is totally discharged ( 12.96*6.94 =89.942
4)
// when battery voltage is 7.2volt it is fully charged (14.4*6.94=99.936)
// 12.96v =0% and 14.4v =100%
charged_percent=bat_volt*6.94;
charged_percent=map(bat_volt*6.94, 89.9424 , 99.936 , 0 , 100);
/*
if (solar_volt > bat_volt)&&( bat_volt <=14.4))
{
Serial.print (charged_percent);
Serial.println("% charged");
Serial.println("");
Serial.println("***************************************************************
*******************");
}
else if (bat_volt < 12.96)
{

Serial.println("BATTERY IS DEAD !!!!! ");


}
*/
////////////////////////////////////LCD DISPLAY ////////////////////////////////
/////////////////////
lcd.setCursor(0,0); // set the cursor at 1st col and 1st row
lcd.print("SOL:");
lcd.print(solar_volt);
lcd.print(" BAT:");
lcd.print(bat_volt);
lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
// LCD will show the %charged during charging period only
if ((bat_volt > 12.96) && (bat_volt <=14.4))
{
lcd.print(charged_percent);
lcd.print("% Charged ");
}
// LCD will alart when battery is dead by displaying the message "BATTERY IS DE
AD!!"
else if (bat_volt < 12.96)
{
lcd.print("BATTERY IS DEAD!!");
}
/////////////////////////////LOAD ////LED INDICATION ///////////////////////////
////////////////////////////
if ((solar_volt < 3 ) && (bat_volt > 6.2))
// when there is no sunlight(night) and battery is charged,
//load will switched on automatically
{
digitalWrite(load,LOW); // for relay digitalWrite(load,HIGH);
}
///load will be disconnected during day time(solar_volt > 12) or when battery is
discharged condition
if ((bat_volt < 12.96 )or (solar_volt > 12 ))
{
digitalWrite(load,HIGH); // for relay digitalWrite(load,LOW);
// prevent battery from complete discharging
}
//////////////////////////////LED INDICATION DURING CHARGING////////////////////
////////////////////
if ( solar_volt > bat_volt && bat_volt <14.4)
{
///Green LED will blink continiously indicating charging is going on
digitalWrite(GREEN,HIGH);
delay(5);
digitalWrite(GREEN,LOW);
delay(5);
}
// Red LED will glow when battery is discharged
// also display in LCD
if (bat_volt < 12.96 && bat_volt > 12)
// seecond restriction is given for indicating battery is dead
// if you omit the (bat_volt > 12) when ever battery is dead also display bat di
scharged
{
digitalWrite(RED,HIGH); // indicating battery is discharged
lcd.setCursor(1,1);

lcd.print("BAT DISCHARGED..");
}
// Red LED will OFF when battery is not discharged
if (bat_volt > 12.96)
{
digitalWrite(RED,LOW);
}
//Green LED will glow when battery is fully charged
if(bat_volt >=14.4)
{
digitalWrite(GREEN,HIGH);
}
}

Anda mungkin juga menyukai