# Tracker Solar

**URL:** <https://forum.arduino.cc/t/tracker-solar/240292>\
**Category:** General Guidance\
**Created:** [June 14, 2014, 10:21am UTC](https://forum.arduino.cc/t/tracker-solar/240292 "2014-06-14T10:21:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 14, 2014, 10:21am UTC](https://forum.arduino.cc/t/tracker-solar/240292/1 "2014-06-14T10:21:29Z")

</div>

Hello!

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

---

<div class="post-metadata">

**Author:** ![rogerClark](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@rogerClark](https://forum.arduino.cc/u/rogerClark)\
**Post date:** [June 14, 2014, 10:26am UTC](https://forum.arduino.cc/t/tracker-solar/240292/2 "2014-06-14T10:26:45Z")

</div>

Let me Google that for you.

"solar tracker arduino"

Oh yes. Here it is.

> **[Arduino Solar Tracker](https://www.instructables.com/Arduino-Solar-Tracker/)**
>
> 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/

Well, that wasn't so hard was it 😉

And here is the code

```plaintext
/* 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);
}

```

---

<div class="post-metadata">

**Author:** ![dave-in-nj](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dave-in-nj](https://forum.arduino.cc/u/dave-in-nj)\
**Post date:** [June 14, 2014, 11:55am UTC](https://forum.arduino.cc/t/tracker-solar/240292/3 "2014-06-14T11:55:52Z")

</div>

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/](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.

> **[Welcome cerebralmeltdown.com - BlueHost.com](http://www.cerebralmeltdown.com/)**
>
> Bluehost - Top rated web hosting provider - Free 1 click installs For blogs, shopping carts, and more. Get a free domain name, real NON-outsourced 24/7 support, and superior speed. web hosting provider php hosting cheap web hosting, Web hosting,...

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 !

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [June 14, 2014, 3:37pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/4 "2014-06-14T15:37:10Z")

</div>

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

...R

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 14, 2014, 3:46pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/5 "2014-06-14T15:46:29Z")

</div>

> dave-in-nj:  
> 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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 14, 2014, 4:44pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/6 "2014-06-14T16:44:03Z")

</div>

the code works correctly?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 14, 2014, 6:32pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/7 "2014-06-14T18:32:55Z")

</div>

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

[sketch\_jun14a.ino](https://forum.arduino.cc/uploads/short-url/3ILYjjzlrVv8bh2QKImsJkOhQWZ.ino) (1.68 KB)

---

<div class="post-metadata">

**Author:** ![ad2049q](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@ad2049q](https://forum.arduino.cc/u/ad2049q)\
**Post date:** [June 14, 2014, 6:38pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/8 "2014-06-14T18:38:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 14, 2014, 7:07pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/9 "2014-06-14T19:07:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [June 14, 2014, 7:36pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/10 "2014-06-14T19:36:42Z")

</div>

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

...R

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [June 14, 2014, 7:48pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/11 "2014-06-14T19:48:30Z")

</div>

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.

...R

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [June 15, 2014, 6:12am UTC](https://forum.arduino.cc/t/tracker-solar/240292/12 "2014-06-15T06:12:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dave-in-nj](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dave-in-nj](https://forum.arduino.cc/u/dave-in-nj)\
**Post date:** [June 15, 2014, 2:08pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/13 "2014-06-15T14:08:04Z")

</div>

> pc5\_costa:  
> 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.

---

<div class="post-metadata">

**Author:** ![wwbrown](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@wwbrown](https://forum.arduino.cc/u/wwbrown)\
**Post date:** [June 15, 2014, 3:57pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/14 "2014-06-15T15:57:21Z")

</div>

There are equations that very accurately estimate the position of the sun based upon the tear, month, day, time and your location, by accurate I think the max error is under 0.5° probably better than a tracker will do.

With these well known equations why not put in an RTC so you know the time, and use a handheld GPS to get the location of the collector (a one time measurement). Calculate the position of the sun and then just point to the sun, adjust every 5-10 minutes and sleep the rest of the time. The lag time could be calculated beforee it "went to sleep" by

This method will provide at least as much accuracy and since the system is not always searching for the best situation the driving motors will last longer.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [June 16, 2014, 3:32am UTC](https://forum.arduino.cc/t/tracker-solar/240292/15 "2014-06-16T03:32:30Z")

</div>

Regarding RTC and algorithm.

> This method will provide at least as much accuracy and since the system is not always searching for the best situation the driving motors will last longer.

It is because the light sensor system is always searching for the best situation, that makes it better in my opinion to relying on an RTC.

[soapbox] About light sensor better than RTC, no can't be bothered, It will be in another thread somewhere on the forum[/soapbox]

Tom....... 🙂

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [June 16, 2014, 6:42am UTC](https://forum.arduino.cc/t/tracker-solar/240292/16 "2014-06-16T06:42:41Z")

</div>

The sun is better at keeping time than any RTC - that's why we need leap-years.

If a position system using LDRs seems to be causing the motors to work too often the solution is very simple - just check the position every 15 or 30 minutes.

...R

---

<div class="post-metadata">

**Author:** ![dave-in-nj](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dave-in-nj](https://forum.arduino.cc/u/dave-in-nj)\
**Post date:** [June 16, 2014, 11:12am UTC](https://forum.arduino.cc/t/tracker-solar/240292/17 "2014-06-16T11:12:38Z")

</div>

Good Sirs,

A point of decorum.

if a poster says I have "X" and want to make it work. is it proper that we should offer that "Y" is better and not try to help the poster get his "X" to work ?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 16, 2014, 11:34am UTC](https://forum.arduino.cc/t/tracker-solar/240292/18 "2014-06-16T11:34:29Z")

</div>

> dave-in-nj:  
> Good Sirs,
> 
> A point of decorum.
> 
> if a poster says I have "X" and want to make it work. is it proper that we should offer that "Y" is better and not try to help the poster get his "X" to work ?

It's reasonable to discuss alternative approaches. There is a significant proportion of questions where people ask for help making a difficult solution work and ignoring easier solutions, usually IMO because they aren't aware of the easier solutions.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 16, 2014, 1:04pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/19 "2014-06-16T13:04:02Z")

</div>

> wwbrown:  
> There are equations that very accurately estimate the position of the sun based upon the tear, month, day, time and your location, by accurate I think the max error is under 0.5° probably better than a tracker will do.
> 
> With these well known equations why not put in an RTC so you know the time, and use a handheld GPS to get the location of the collector (a one time measurement). Calculate the position of the sun and then just point to the sun, adjust every 5-10 minutes and sleep the rest of the time. The lag time could be calculated beforee it "went to sleep" by
> 
> This method will provide at least as much accuracy and since the system is not always searching for the best situation the driving motors will last longer.

This is how the pros do it. BTW if you put your panel on a polar aligned axis, you only need one servo (and a seasonal tilt adjustment).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 16, 2014, 3:30pm UTC](https://forum.arduino.cc/t/tracker-solar/240292/20 "2014-06-16T15:30:56Z")

</div>

So if you have GPS, you have the time, right? The clock signal being broadcast by the satellite is atomic-based if I'm not mistaken, and will likely be way more accurate than your RTC. Each satellite has been calibrated to the same time, and all they do is transmit an ID and the time continuously... I think? Then the GPS receiver compares the time it took for each of the clock signals to come in and uses some trigonometry to determine your latitude and longitude. I'm probably oversimplifying, but that's at least how I thought I understood how they work.

[Next page](https://forum.arduino.cc/t/tracker-solar/240292.md?page=2)
