#include //Integrating library for dealing Stepper.h stepper motors #include //Integrating design math.h library for basic mathematical operations //Declaring Constants #define motorStephor 200 //steps for horizontal motor #define motorStepver 200 //steps for vertical motor //Digital pins #define motor1hor 6 #define motor2hor 7 //Variables int prom; //Average of four LDR int pyr; //BPW34 photodiode int h=60; //Steps executed by the horizontal motor int v=5; //Steps executed by the vertical motor int ltsensor; //Value of the top left LDR int rtsensor; //Value of the top right LDR int rdsensor; //Value of the bottom right LDR int ldsensor; //Value of the bottom left LDR int sen=50; //Sensibility int dil; //Average set of LDR left int dit; //Average set of LDR top int dir; //Average set of LDR right int did; //Average set of LDR bottom int diff; //Difference between LDR above the bottom int diff2; //Difference between LDR left to right int pup; //upper switch int pdown; //lower switch Stepper horStep (motorStephor, motor1hor, motor2hor); Stepper Stepper verStep (motorStepver, motor1ver, motor2ver); //Program initialization void setup () { horStep.setSpeed (30); //RPM horizontal motor verStep.setSpeed (10); //RPM vertical motor //Serial Port Serial.begin(9600); //Pins configuration pinMode (pyr, INPUT); pinMode(ltsensor, INPUT); pinMode(rtsensor, INPUT); pinMode(ldsensor, INPUT); pinMode(rdsensor, INPUT); pinMode(pup, INPUT); pinMode(pdown, INPUT); } void loop () { do { pyr = analogRead(0); //Reading analog inputs ltsensor = analogRead(1)*1.022; //(constant is to calibrate the LDR) rtsensor = analogRead(2)*1.007; dit = (ltsensor + rtsensor)/2; //Average sensors up did = (ldsensor + rdsensor)/2; //Average sensors down diff =(dit - did); //Difference between the level of radiation delay (50); if ((pyr==0)&&(pup==HIGH)&&(prom<=8)|| (pyr==0)&&(pdown==HIGH)&&(prom<=8)) //If the value of pyr is zero and the average of the sensors is equal or less than 8 and the switches have the range mov(); //mov function } while ( (pyr==0)&&(pup==HIGH)&&(prom<=8)|| (pyr==0)&&(pdown==HIGH)&&(prom<=8)); if (-1*sen > diff || diff > sen) //If the measured difference between the set of sensors is greater or less than the sensitivity value { if(dit < did) //If the mean value of the above sensors is smaller than the bottom sensors { if (pdown==HIGH) { verStep.step (0); //Stop vertical motor delay (10); } else if (pdown==LOW) { verStep.step (v); //Turn motor up delay (50); } } else if(dit > did) //If the average value of bottom sensors is smaller than the above sensors { if (pup==HIGH) { verStep.step (0); //Stop vertical motor delay (10); } else if (pup==LOW) { verStep.step (-v); //Turn motor down delay (50); } } else //any other case { verStep.step (0); //Stop vertical motor delay (10); } } delay (10); pyr = analogRead (0); //Sensor readings again for possible change ltsensor = analogRead(1)*1.022; rtsensor = analogRead(2)*1.007; ldsensor = analogRead(3); rdsensor= analogRead(4)*1.013; dil = (ltsensor + ldsensor)/2; //Average sensors left dir = (rtsensor + rdsensor)/2; //Average sensors right diff2 = (dil - dir); //Difference between the level of radiation delay (50); if (-1*sen > diff2 || diff2 > sen) //If the measured difference between the set of sensors is greater or less than the sensitivity value { if(dil < dir) //If the average of the left sensor is smaller than the right sensor { horStep.step (h); //Turn motor right delay (10); } else if(dil > dir) //If the average of the left sensor is larger than the right sensor { horStep.step (-h); //Turn motor left delay (10); } else //any other case { horStep.step (0); //Stop horizontal motor delay (10); } } delay(10); } // “mov function” void mov () { if (pup==HIGH) { verStep.step (72); //Turn 72 steps up (are the steps to change position once hide the sun) delay (50); } else if (pdown==HIGH) { verStep.step (-72); //Turn 72 steps down delay (50); } delay (10); }