Go Down

Topic: Tracker Solar (Read 752 times) previous topic - next topic



Does anyone have code for the solar tracker project (consisting of 4 SWDS, which will rotate the servo motor in order to capture more light)??


Let me Google that for you.

"solar tracker arduino"

Oh yes. Here it is.


Well, that wasn't so hard was it ;-)

And here is the code

Code: [Select]
/* 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()
// 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


well, since you asked for 4 swds and I have no idea what that means, I can offer you a couple places.

I checked out SWDS  http://swds.org/  but could not find any information about solar tracking.
" unique habitat for birds, bugs and other little creature...."

for what I know about solar tracking...first Dwyane over at Redrok invented the application of using 4 LED's as the sensors.  it has been copied many times, so I would start there.

that site offers a non-arduino solution as it uses  the sensors to move the motor.
the problem is that without the smarts, it has a few areas that it cannot handle. such as it will not follow with clouds and does not have either a night return or a flat setting to eliminate the effects of wind.

the guy is brilliant, but not great on web page design.

the other place is the guy who is brilliant with arduino code for the same application.  not sure if he uses 4swds though.


this is a calculated postioner that uses your location on the planet, the alignment of the sun along with the rotation of the earth and will point the array at the sun.  it does not use feedback so if your alignment is off, your tracking is off.

both are very viable technologies and the blending of the two would make a great final project.  heck, you might be able to install one at SWDS !


... and there have been several Threads on the same subject in the last few months. Some even have a similar title.



both are very viable technologies and the blending of the two would make a great final project.  heck, you might be able to install one at SWDS !

Having a tracker based purely on realtime brightness feedback strikes me as a very crude approach, but using it to refine a cumulative estimate of lat/long and season to configure a polar aligned tracker seems very elegant.
I only provide help via the forum - please do not contact me for private consultancy.


the code works correctly?


sent me this code for a solar tracker, but it does to me, does not work!
someone could help me


That 1.68k file is small.
If it does not work then you are better off starting from a clean page.
Write down your specification of what yours must do, should do, may do, could do, and then write small programs at first to test each part of that.

By the way, in your writeup you might get nil marks if you don't spell it as the Oxford Dictionary does.


If you want help from this forum, read this and follow directions before posting: http://forum.arduino.cc/index.php/topic,148850.0.html


Their have been several Threads about solar trackers in recent months. Google will help you find them.



If you take the trouble to search for previous Threads about solar tracking you should quickly find that all you need is 4 Light Dependent Resistors and 20 or 30 lines of code.

if you are prepared to adjust the tilt manually once a month you only need 2 LDRs.



Hi,  at the top of this page is a window that says "search the Arduino Forum", I suggest you use it by inputting

solar tracker

The forum is littered with this subject, it has been done so many times before.

Tom........ :)
Everything runs on smoke, let the smoke out, it stops running......VK3DMK


Have you build your hardware?
With the following features that are required by the sketch:

   4 light dependent resistors resistors, connected to analogue inputs 0, 1, 2, 3
   2 potentiometers, connected to analogue inputs 4 & 5
   2 servos connected to digital pins 9 & 10


You say that the sketch doesn't work, but you don't say in what way.

Does the servo move in the wrong direction?
Does the servo move too far?
Do the servos go backwards and forwards trying to find the best position?

Just saying it doesn't work isn't very helpful to anyone prepared to give you assistance.


sent me this code for a solar tracker, but it does to me, does not work!
someone could help me

you need to get the schematic for that sketch and also make sure the servo's you are using are working with the signals being sent.

Go Up