Introduction: Arduino Solar Tracker

Step 1: How It Works

How it works:
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.


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


Step 2: Parts List

Step 3: The Set-up

Just hot glue it together!!! 

Step 4: The Circuitry

Step 5: 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);




Comments

author
Spellmal made it! (author)2014-12-05

Just finished up my take on this tracker. I used continuous rotation servos, so i had to modify the code a bit. Super fun project, thanks geo Bruce!

IMG_0525.JPG
author
AlberA (author)Spellmal2015-01-22

Hi could you send me the schematic for the build and the codes... because i think im going to go with the continuous rotation servos too.... ty

author
Spellmal (author)AlberA2015-01-22

My wiring and build was pretty much the same as GeoBruces, except for an LCD I added.

For your individual motors, the servohstop and servovstop values might need adjusting. If it doesnt work as is, try setting both of these values to 90 and go from there.

#include <LiquidCrystal.h> //include LCD Library

#include <Servo.h> // include Servo library

LiquidCrystal lcd (2, 3, 4, 5, 6, 7); //

Servo horizontal;

int servohStop = 95;

int servohLeft = 105; //move horizontal

int servohRight = 85;

Servo vertical; // vertical servo

int servovStop = 95;

int servovUp = 105 ;

int servovDown =87;// move vertical servo

// LDR pin connections

// name = analogpin;

int ldrLeftTop = 1; //LDR top left

int ldrRightTop = 0; //LDR top right

int ldrLeftBottom = 2; //LDR down left

int ldrRightBottom = 3; //ldr down right

int dtime = 25; //delay time in milliseconds

int tolerance = 100; //difference tolerance between ldr readings

int count = 0; //millis(); //start millisecond count

void setup()

{

lcd.begin(16, 2); //begin 16x2 LCD

Serial.begin(9600);

// servo connections

// name.attach(pin);

horizontal.attach(9);

vertical.attach(10);

}

void loop()

{

//int count = millis(); //start millisecond count

int leftTop = analogRead(ldrLeftTop); // top left

int rightTop = analogRead(ldrRightTop); // top right

int leftBottom = analogRead(ldrLeftBottom); // down left

int rightBottom = analogRead(ldrRightBottom); // down right

//print resistance values to serial monitor for debugging

Serial.println(leftTop );

Serial.println(rightTop );

Serial.println(leftBottom );

Serial.println(rightBottom );

Serial.println();

count++;

int avt = (leftTop + rightTop) / 2; // average value top

int avd = (leftBottom + rightBottom) / 2; // average value down

int avl = (leftTop + leftBottom) / 2; // average value left

int avr = (rightTop + rightBottom) / 2; // average value right

int avgTot = (rightTop+rightBottom+leftTop+leftBottom) / 4;

int dvert = avt - avd; // check the diffirence of up and down

int dhoriz = avl - avr;// check the diffirence og left and right

if (count%10 == 1) //mod the millis count so the lcd screen updates every 10 millis

{

lcd.clear(); //clear the screen and position cursor at top left

lcd.print("dvert: "); //difference in vertical resistances read from the LDRs

lcd.print(dvert);

lcd.setCursor(0,1); //set lcd cursor to bottom left

lcd.print("dhoriz: "); //difference in horizontal resistance read from the LDRs

lcd.print(dhoriz);

}

if (-1*tolerance > dvert || dvert > tolerance) // check if the difference is in the tolerance else change vertical angle

{

if (avt > avd) //if average resistance on top is greater than on bottom

{

vertical.write(servovUp);

}

else //avg resistance on bottom is greater than on top

{

vertical.write(servovDown);

}

}

else if (-1*tolerance < dvert || dvert < tolerance) //if difference is smaller than tolerance, stop vertical servo

{

vertical.write(servovStop);

}

if (-1*tolerance > dhoriz || dhoriz > tolerance) // check if the difference is in the tolerance else change horizontal angle

{

if (avl > avr)

{

horizontal.write(servohLeft);

}

else

{

horizontal.write(servohRight);

}

}

else if (-1*tolerance < dhoriz || dhoriz < tolerance) //if difference in horizontal

{

horizontal.write(servohStop);

}

delay(dtime);

}

WiringDiagramUPDATED_bb.jpg
author
zawminmin (author)Spellmal2016-09-20

I would like to get this code.Now I research about dual axis solar tracker.So I need your help.I would like to know why you assign tolerance is 100.I must show the comparison of tracking and fixed system.I must prove that tracking get power more than fixed system.So how do measure power in this system?please give me advise.

author
rdraycott (author)Spellmal2015-02-11

I followed your schematic and used your code but I can't get info to display on LCD.. lcd back light lights up and white squares are there when I turn potentiometer... do the 4 resistors have to be a certain ohm to work correctly...

author
rdraycott (author)rdraycott2015-02-11

this is all I get :-(

temp_1521861806.jpgtemp_-2061293483.jpg
author
OPELFRIK (author)rdraycott2016-05-21

hello, can you please help me. I have made project by Spellmal and get the some problems as you with the LCD screen. how u solved thoose problems ??

author
kumar_ashish (author)rdraycott2016-03-31

Try adjusting the LCD contrast by varying the voltage input to pin 3 (V0) of LCD using potentiometer.

author
Akin Yildiz (author)Spellmal2016-03-30

got a screen myself, working on replicating this project.. thanks for the comment

author
hendrif (author)Spellmal2015-04-04

can i know what is the function of the LCD?and can i get the full image of your model solat tracker?

author
AlberA (author)Spellmal2015-01-23

Thank you for the answers... so i wounder if your servos are modifyed to make a full spinn... if i do that to my servos would the code you sent me work?

author
VedantU (author)Spellmal2016-09-15

Hi, I was planning to make this for my recent college project but for some reason it doesnt work well. I followed the circuit and the code as well (changed it since at first it was moving away from the light) but then at times the servo dont work at all or sometimes only one works. I can't seem to figure out what the problem is. At first i thought its loose connection but even after changing the wires and checking everything it doesnt seem to work properly

author
JunaidC (author)Spellmal2016-09-11

Can u me code?

author
SwarnadeepP (author)Spellmal2016-03-30

Hi I am Swarnadeep from India. I am using same as yours for my college project. Can you pls give me your code ??? I am using 360 servo for horizontal axis

author
mayureshdugade (author)Spellmal2015-10-29

Hello ,which IC have u used ???

author
mayureshdugade (author)Spellmal2015-10-29

Hellowhich IC have u used ???

author
gjscott1991 (author)Spellmal2015-03-23

Hi could you send me the schematic for the build and the codes... because i think im going to go with the continuous rotation servos toceers

author
AlberA (author)Spellmal2015-01-22

Hi could you send me the schematic for the build and the codes... because i think im going to go with the continuous rotation servos too.... ty

author
gjscott1991 (author)AlberA2015-03-23

Hello is there any chance you could send me the schematic for the build and the codes... because i think im going to go with the continuous rotation servos too.... thank you

author
sali58 (author)AlberA2015-02-21

hi can you please send me same stuff (he schematic for the build and the codes for display ..)to build a solar tracker

Thank you

author
TomDunlap (author)2013-06-02

Just finished it and got it debugged. Really cool. Now I'm going to try to use it to build a Solar Forge and or a Solar Sand Sinter 3D Printer. Should be a snap. ;-)

author
ShreyasP4 (author)TomDunlap2016-03-12

Hey Tom, We are right now making a Solar sand sinter 3D printer. We have finished making the coordinate plate and are working on the tracking system now. Would like to get your inputs. Best,

author
BalaJ11 (author)ShreyasP42016-03-26

hi dude ,

what is the rate and power of servo motor which u have used.. can u give me some details.. i have to do this as mini project

author
TomDunlap (author)ShreyasP42016-03-12

Good luck with your project. I have not been able to pursue this one so not much more to add. Everything you need should be available online now. Except time and money. You'll have to come up with those. ;-)

author
geo bruce (author)TomDunlap2013-06-03

cool! :p
can you show us some video's or pictures?

thnx

author
TomDunlap (author)geo bruce2013-07-13

Another development, I used a Makerbot Replicator to print a replacement for the foam core sensor holder. Here is the Sketchup pic of it. The two pieces glue together. The center top hole is for a fifth sensor to shut the system down if clouds block the sun so it doesn't try to point at the brightest cloud.

Pyramid 3.png
author
geo bruce (author)TomDunlap2013-07-20

nice upload your design to http://www.thingiverse.com/

author
geo bruce (author)TomDunlap2013-07-20

thnx!!

author
بارقا (author)geo bruce2016-03-06

What are the results and conclusions

author
بارقا (author)geo bruce2016-03-06

What are the results and conclusions

author
MC James (author)geo bruce2014-11-03

*videos *thanks

author
TomDunlap (author)geo bruce2013-06-03
Sure, here is the link to the YouTube clip I made: http://youtu.be/6GTVWdeKvzY
author
geo bruce (author)TomDunlap2013-06-03

Nice!!!

It's cool to see your instructable finished by someone else :D
it means i've helped someone ^^ or someone liked my project! :D

author
TomDunlap (author)geo bruce2013-06-03

It's really helpful to get me started toward my other goals.
Next I want to modify the code to operate some 12V drill motors with a MotorShield or the like if I can find one that will handle the 3-4A current.

author
YeganeA made it! (author)2017-08-09

Thank you geo for this perfect tutorial and also the program. It was a great experience for me! as
but unfortunately, one of my servo's has broken up!
I should try stronger servos.


photo_2017-08-09_21-55-40.jpg
author
tatoo23 made it! (author)2017-07-17

Hello everyone
First, A big thanks for this UTOT, the idea and Great.
I managed to climb.
But strangely when I telescope a lamp of photoresistors, the photoresistance goes against the senses. They leak the lamp !!!
Could you help me?
Has anyone ever encountered problems?

I noticed that the PLA parts do not hold in the sun (I live in france Provence13), the pieces soften.
I made ABS parts, now I have to test them. But its should be more solid
.
thank you in advance

Ps: I posted two photos

IMG_20170717_133309.jpg
author
geo bruce (author)tatoo232017-07-17

It can be that you mixed up left and right and up and down. then it wil try to avoid the light
or maybe the resistors and photo resistors are mixed up.

author
tatoo23 made it! (author)tatoo232017-07-17

Here is the second picture.

Sorry .

DOS 2.jpg
author
Ameya kunte (author)2017-07-12

Can u send me the circuit with petentiometers

author
yacinehooo made it! (author)2017-06-14

amazing robot i like it

2017-04-21 20.37.11.jpg
author
El Zotz (author)2017-05-12

I'm starting my solar tracker. Today i welded some stainless steel sheets and put most of the bread board together. Wish me luck!

image.jpgimage.jpg
author
geo bruce (author)El Zotz2017-05-12

Best luck!
have fun with your build!

And If you'd like to put your welding skills to good use you might be interested in my other instructable: https://www.instructables.com/id/Dual-Axis-300W-IOT-Solar-Tracker/

author
DivasG (author)2017-05-01

How did you aligned the servo with sun/lightsource at first?

author
dgunner240 (author)2017-03-22

Hey. Love the idea. Some cool things here. I'm a student studying energy and specifically doing some projects with solar. I was wondering what happened when it was a cloudy day? Did it still track the sun accurately? Also did you buy to potentiometers for 10000 dollars ea.? My goal is to make a cheaper potentiometer.

author
AlexeyB19 made it! (author)2017-03-14

Finished! Quite fun project.

solarTracker - 1.png
author
jusio made it! (author)2017-03-14

Quite a fun project. Word of advice for those doing it, test your LDRs you have before starting this project, might save you some trouble. Some of the LDRs I had were producing enormously high voltage, way above data sheet values (like 10 times higher, it was impossible to overcome with tolerance calibration).

solarTracker - 1.png
author
monusuthar2016 (author)2017-01-27

Hello

can i copy this instructables in my site, i will mention your name

author
geo bruce (author)monusuthar20162017-01-28

Yes If you mention my name and a link to my instructable it's perfect for me!

Good luck with your projects!

and thanks for asking ;)

author
ShiroK1 (author)2017-01-12

hi do you have a schematic diagram and code if stepper motor is used instead of servo? ty

About This Instructable

379,238views

673favorites

License:

Bio: Hello, I'm Bruce. I'm a student in Belgium. I have a wide variety of interests: electronics, computers, technology, ... In my spare time I ... More »
More by geo bruce:Musical Tesla Coil Kit (instructions)Design a Parametric Pulley (DXF / STL)High Voltage Pulse Generator for $8 (stungun)
Add instructable to: