Introduction: Arduino Solar Tracker (arduino Ile Güneş Takip)
PARTS:
1) 1x box
2) 2x sg90 micro servo motor
3) 4x 10k resistor
4) 4x LDR
5) Jumper cable
6) 1x Arduino
7) 1x breadboard
8) 1x Powebank
Step 1: Under Part
*Short edge 4 inch Long edge 5 inch box
** 1 pieces sg90 servo motor
Step 2: Middle and Upper
* Square with sides 5 inches
*Short edge 2 inches long side 6 inches rectangle (3 pieces)
Step 3: Panel Part
* Short edge 6 inches long side 9 inches rectangle (3 pieces)
*Short edge 2 inches long side 7 inches rectangle (2 pieces)
Step 4: The Circuit
* Blue cables positive input of LDR
** Green cables output connected resistance
*** grey cables input (A0,A1,A2,A3)
**** Servo motors orange cables(9.pin,10.pin)
Step 5: THE CODE
#include<servo.h>
servo horizontal;
int servoh = 180;
int servohLimitHigh = 180;
int servohLimitLow = 15;
Servo vertical;
int servov = 45;
int servovLimitHigh = 80;
int servovLimitLow = 15;
// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top right
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down right
void setup()
{
Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
horizontal.write(180);
vertical.write(80);
delay(3000);
}
void loop()
{
int lt = analogRead(ldrlt); // top left
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left
int rd = analogRead(ldrrd); // down right
// int dtime = analogRead(4)/20;
// int tol = analogRead(5)/4;
int dtime = 10;
int tol = 50;
int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right
int dvert = avt - avd; // check the diffirence of up and down
int dhoriz = avl - avr;// check the diffirence og left and right
Serial.print(avt);
Serial.print(" ");
Serial.print(avd);
Serial.print(" ");
Serial.print(avl);
Serial.print(" ");
Serial.print(avr);
Serial.print(" ");
Serial.print(dtime);
Serial.print(" ");
Serial.print(tol);
Serial.println(" ");
if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance else change vertical angle
{
if (avt > avd)
{
servov = ++servov;
if (servov > 180)
{
servov = 180;
}
}
else if (avt < avd)
{
servov= --servov;
if (servov < 0)
{
servov = 0;
}
}
vertical.write(servov);
}
if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)
{
servoh = --servoh;
if (servoh < 0)
{
servoh = 0;
}
}
else if (avl < avr)
{
servoh = ++servoh;
if (servoh > 180)
{
servoh = 180;
}
}
else if (avl == avr)
{
// nothing}horizontal.write(servoh);
}
delay(dtime);
}
Comments
5 years ago
That's a good way to make one out of available materials :)