Arduino Solar Tracker
What is does:
It searches for the brightest light source like the sun.
There is a newer and better version of this project: https://www.instructables.com/id/Dual-Axis-300W-IOT-Solar-Tracker/
How It Works
How it works:
I'd made a sensor of 4 LDRs with sheets between them
I'd made a sensor of 4 LDRs with sheets between them
The white dots are the LDRs
When the stick on top is righted to the sun or the brightest point
the four LDRs get the same amount of light on them.
the four LDRs get the same amount of light on them.
Example1 when the light is left on top:
right-top, right-down, left-down are in the shadow
and left-top get the most light
Example2 when the light is on top
left and right down are in the shadow and top is in the light
Parts List
- 2 x servo's Ebay link 1.5$ / piece
- 4 x lightdepending resistors (ldr) Cheap LDR's on Ebay 0.78$ for 20 pcs
- 4 x resistors 10K Resistors on Ebay 0.78$ for 50pcs free shipping
- 1 x Arduino Arduino UNO Ebay link 3.5$ free shipping
- 2 x potentiometers 10k (value doesn't matter) Ebay link
The Set-up
Just hot glue it together!!!
The Circuitry
The Code
you can download the code down this page
/* this code is written by geobruce
for more info check my site http://xprobe.net
*/
#include <Servo.h> // include Servo library
Servo horizontal; // horizontal servo
int servoh = 90; // stand horizontal servo
Servo vertical; // vertical servo
int servov = 90; // stand vertical servo
// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top rigt
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down rigt
void setup()
{
Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
}
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 rigt
int dtime = analogRead(4)/20; // read potentiometers
int tol = analogRead(5)/4;
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 rigt
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);
}
/* this code is written by geobruce
for more info check my site http://xprobe.net
*/
#include <Servo.h> // include Servo library
Servo horizontal; // horizontal servo
int servoh = 90; // stand horizontal servo
Servo vertical; // vertical servo
int servov = 90; // stand vertical servo
// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top rigt
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down rigt
void setup()
{
Serial.begin(9600);
// servo connections
// name.attacht(pin);
horizontal.attach(9);
vertical.attach(10);
}
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 rigt
int dtime = analogRead(4)/20; // read potentiometers
int tol = analogRead(5)/4;
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 rigt
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);
}