Introduction: Arduino Solar Tracker

Picture of Arduino Solar Tracker

Step 1: How It Works

Picture of 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

Picture of The Set-up

Just hot glue it together!!! 

Step 4: The Circuitry

Picture of 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
#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()
// servo connections
// name.attacht(pin);

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;

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


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!

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

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


// servo connections

// name.attach(pin);




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 );



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.setCursor(0,1); //set lcd cursor to bottom left

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



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




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





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




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


if (avl > avr)









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






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.

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...

rdraycott (author)rdraycott2015-02-11

this is all I get :-(

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 ??

kumar_ashish (author)rdraycott2016-03-31

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

Akin Yildiz (author)Spellmal2016-03-30

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

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?

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?

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

JunaidC (author)Spellmal2016-09-11

Can u me code?

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

mayureshdugade (author)Spellmal2015-10-29

Hello ,which IC have u used ???

mayureshdugade (author)Spellmal2015-10-29

Hellowhich IC have u used ???

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

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

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

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

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. ;-)

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,

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

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. ;-)

geo bruce (author)TomDunlap2013-06-03

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


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.

geo bruce (author)TomDunlap2013-07-20

nice upload your design to

geo bruce (author)TomDunlap2013-07-20


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

What are the results and conclusions

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

What are the results and conclusions

MC James (author)geo bruce2014-11-03

*videos *thanks

TomDunlap (author)geo bruce2013-06-03
Sure, here is the link to the YouTube clip I made:
geo bruce (author)TomDunlap2013-06-03


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

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.

mongause (author)2017-11-26

Since achieving maximum output is the desired goal, why not simply measure the panel's maximum output voltage to achieve alignment. Since a bird flying by or a motor kicking on, could drop the voltage, you'd need to save the location of max voltage and make multiple passes for comparison. I'd think that 3 max volt measurements in the same location should be sufficient. As to the extra energy used in multiple motor moves, how does that compare to unnecessary auxiliary sensors that are powered all day.

Rene046 (author)2017-11-14

Why use LDR ?

The solar panel is one big LDR, let it sweep to find the highest voltage...

sweep one horizontal and once vertical to find highest voltage true a divider.

Some day i'll will try it, when working with a solar panel.

ChongH (author)2017-10-06

Hi could i know what the potentiometers are used for? I'm planning to make it for my project but i can't seem to understand what it is for. Thanks in advance.

JoseH98 (author)2017-08-23

Una idea tan genial como sencilla! Fantastico montaje y programación. Felicidades

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.

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

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.

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

Here is the second picture.

Sorry .

Ameya kunte (author)2017-07-12

Can u send me the circuit with petentiometers

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

amazing robot i like it

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!

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:

DivasG (author)2017-05-01

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

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.

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

Finished! Quite fun project.

About This Instructable




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: