Created
June 11, 2020 08:45
-
-
Save dsijanov/87ab2f365b89d3dddae558a3eb524f6e to your computer and use it in GitHub Desktop.
Solar Sun tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo tragac; //It creates a servo object that manages the servo. | |
int istokPin = 1; //It adds analog pins connected to the light sensor | |
int zapadPin = 2; | |
int istokVal = 0; //It creates variables that store sensor values. | |
int zapadVal = 0; | |
int greska = 0; | |
int kalibracija = 204; //Calibration shift that sets the error to zero when both sensors receive the same amount of light. | |
int tragacPoz = 90; //It creates a variable that stores the positioning of the servo. | |
void setup() | |
{ | |
tragac.attach(11); //It adds an object to the servo connected to pin 11. | |
} | |
void loop() | |
{ | |
istokVal = kalibracija + analogRead(istokPin); //It reads the values of the east and west sensors. | |
zapadVal = analogRead(zapadPin); | |
if(istokVal<350 && zapadVal<350) //It checks if both sensors receive a little light, it's dark! | |
{ | |
while(tragacPoz<=160) //It moves the tracker to the far Eastern position to greet the dawn. | |
{ | |
tragacPoz++; | |
tragac.write(tragacPoz); | |
delay(100); | |
} | |
} | |
greska = istokVal - zapadVal; //It determines the difference between two sensors. | |
if(greska>15) //If the error is positive and bigger than 15, it moves the tracker to the East. | |
{ | |
if(tragacPoz<=160) //It confirms that the tracker is not in the far East position. | |
{ | |
tragacPoz++; | |
tragac.write(tragacPoz); //It moves the tracker to the East. | |
} | |
} | |
else if(greska<-15) //If the error is negative and lower than -15, it moves the tracker to the West. | |
{ | |
if(tragacPoz>20) //It confirms that the tracker is not in the far West position. | |
{ | |
tragacPoz--; | |
tragac.write(tragacPoz); //It moves the tracker to the West. | |
} | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment