Enhanced Dual Axis Program
Enhanced Dual Axis Program
Enhanced Dual Axis Program
#defineVOLTA1
#define LUX A3
LiquidCrystallcd(2,3,4,5,6,7);
floatTemperature,temp,volt,volts,lux,Temp; int
temp1, value,analog_value;
bytedegree[8] =
{
0b00011,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
Servomyservo;
intpos=90;//settheinitialpositionoftheHorizontalmovement,controllingfirstservo motor
intldr1=A0;//setldr1topinA0asaninteger
intldr2=A1;//setldr2topinA1asaninteger
int tolerance = 2; // allowable tolerance setting - so as to prevent servo motor constantly
in motion
intx;//setxasabsoluteofldr2-ldr1
inty;//setyasabsoluteofldr1-ldr2
Servo myservo2;
constintDAWN=600;
constintDUSK=1800;
void setup()
{
lcd.begin(16,2);
lcd.createChar(1,degree);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("SunTracking");
lcd.setCursor(0,1);
lcd.print("System");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ByAminu,BelloBodinga");
lcd.setCursor(0,1);
lcd.print("12210310012");
delay(2000);
lcd.clear();
myservo.attach(9); // attaches the servo on digital pin 9 to the horizontal movement servo
motor
pinMode(ldr1,INPUT);//setldr1pinasaninput
pinMode(ldr2,INPUT);//setldr2pinasaninput
myservo.write(pos);// writethestartingpositionofthehorizontalmovementservomotor
delay(2000);//2seconddelaytoallowthesolarpaneltomovetoitsstaringposition before
comencing solar tracking
myservo2.attach(10);//attachestheservoondigitalpin10totheverticalmovement servo motor
pinMode(ldr3,INPUT);//setldr3pinasaninput
pinMode(ldr4,INPUT);//setldr4pinasaninput
myservo2.write(pos2);//writethestartingpositionoftheverticalmovementservomotor
delay(2000);//2seconddelaytoallowthesolarpaneltomovetoitsstaringposition before
comencing solar tracking
}
void loop()
{
/*---------Temperature--------*/
float reading=analogRead(sensor);
Temperature=reading*(5.0/1023.0)*100;
delay(10);
/* Voltage */
temp1=analogRead(VOLT);
volts= (temp1/511.5)*5;
delay(10);
/*-----LightIntensity--------*/
value=analogRead(LUX);
volt=(value/1023.0)*5;
lux=((2500/volt)-500)/3.3;
delay(10);
/*------DisplayResult--------*/
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T:");
lcd.print((int)analog_value);
lcd.write(1);
lcd.print("C");
lcd.setCursor(8,0);
lcd.print("V:");
lcd.print(volts);
lcd.setCursor(0,1);
lcd.print("LDR1: ");
lcd.print((int)lux);
lcd.print(" Lux");
Serial.println((int)Temp);
Serial.println(volts);
Serial.println((int)lux);
delay(500);
//Tocheckday/nightsituations
/*
if(light)
{
if(analogRead(ldr5)<DUSK)
{
dark=true;
//stufftodowhenitchangesfromlighttodark
}
}
else
{
if(analogRead(ldr5)>DAWN)
{
dark=false;
//stufftodowhenitchangesfromdarktolight
}
}
*/
{
pos=180;//resetthehorizontalpostionofthe motorto180ifittriestomovepastthis point
}
if(pos<0)
{
pos=0;//resetthehorizontalpositionofthemotorto0ifittriestomovepastthispoint
}
myservo.write(pos);//writethestartingpositiontothehorizontalmotor
delay(50);
//noservomotorverticalmovementwilltakeplaceiftheldrvalueiswithinthe allowable
tolerance
}else{
if(val3>val4)//ifldr3sensesmorelightthanldr4
{
pos2 = pos+1; // decrement the 90 degree poistion of the vertical servo
motor - this will move the panel position Northward
}
if(val4>val3)//ifldr4sensesmorelightthanldr3
{
pos2 = pos-1; // increment the 90 degree position of the vertical motor -
this will movethe panel position Southward
}
delay(900);
}
//
resettheverticalpostionofthemotorto180ifittriestomovepastthispo
int if(pos2 > 180)
{
pos2=180;
}
//
resettheverticalpositionofthemotorto0ifittriestomovepastthispoin
t if(pos2 < 0)
pos2=0;
}
myservo2.write(pos2);//
writethestartingpositiontotheverticalmovementmotor delay(50);