Solar Tracker

Hi everyone , I have come up with a project called solar tracker 2.0 . It is a single axis vertical sun tracker . I have used two ldrs to find the difference with two values. But due to some reasons ,I got some bugs.Here is the code I used:

#include <Servo.h>

Servo myservo;
int pos = 90;
int sens1 = A0;
int sens2 = A2;
int tolerance = 2;

void setup()
{
myservo.attach(9);
pinMode(sens1, INPUT);
pinMode(sens2, INPUT);
myservo.write(pos);
delay(2000);
}

void loop()
{
int val1 = analogRead(sens1);
int val2 = analogRead(sens2);

if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {

} else {
if(val1 < val2)
{
pos = --pos;
}
if(val1 > val2)
{
pos = ++pos;
}
}

if(pos > 180) { pos = 180; }
if(pos < 0) { pos = 0; }

myservo.write(pos);
delay(75);
}

Can you please suggest me a better code for this.

sun_tracker.ino (634 Bytes)

  if ((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance))
  {

  }
/code]
What should happen if this test returns true ?

Hi,

Here is the code I used:

Did you write the code?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

hi bob, I have done this part so that I can tolerate levels of interference with the ldr

hi arduino-x ,I want the sun tracker to track the sun so I made the servo to turn to the side that has more light intensity. the bugs I got were like the servo started vibrating and started making some noise and it ignored the light sometimes

shashidharybhat:
hi bob, I have done this part so that I can tolerate levels of interference with the ldr

Do you intend to put some code in the code block for that test ?

Hi,
Please a circuit diagram, have you got your LDR wired as a potential divider.

What analog readings do you get in normal sunlight?

You may have your tolerance way too low, 2 out of 1023 is a very low tolerance.
10 or 20, would probably be better.

Your drive system, may not be able to settle the PV angle to give a difference <2.

Thanks.. Tom... :slight_smile:

UKHeliBob:

  if ((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance))

{

}



What should happen if this test returns true ?

If the error is within tolerance, then nothing should happen.

Dude, you are only allowing 75 milliseconds for the servo to react to a change. And each time you discover that the sun is still off-target, you increase the target position by one. So if your sketch starts way off target, that target vlaue will get jammed all the way over to 180 or 0 before the servo catches up.

The sun moves pretty slowly. Try increasing that delay to something bigger - say, 500ms, and see if that gets rid of the vibration.

If the error is within tolerance, then nothing should happen.

So the test is not necessary and the else could be replaced by a test to see if the range is outside of the tolerance which would make the code more logical.

And

  if ((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance))
  {
  }

Is doing twice the work as the absolute value of the difference of two variables does not depends on the way you do the difference so

  if (abs(val1 - val2) <= tolerance) {
  }

is totally enough

But he is doing nothing if the test returns true so the test is not necessary anyway.

Yes it's totally enough to do nothing, no need to add insult to injury :slight_smile:

UKHeliBob:
But he is doing nothing if the test returns true so the test is not necessary anyway.

There's an else clause.

PaulMurrayCbr:
There's an else clause.

If there is no code required in the if clause then you don't need the else clause. You could simply invert the logic and use an if clause.

Your alignment can be off center by 10° in either direction and lose only 1.5% of the energy. The deadband can be increased greatly. You can slew past center then let the sun catch up.

What is the physical arrangement of the sensors? There is a very simple way of doing this, even with CdS cells.

This could be done with 1 servo and 2 LDRs if the axis of rotation were pointed due North (or South) and tilted up to match your latitude, also, the Sun moves across the sky at only 1/4 degree per minute so high speed, high precision positioning is not needed.

I'm working on a drawing for the sensor where the panel only needs to be moved every 45 minutes and will have 99.5% collection efficiency or greater(+/- 5.7° error). A gearbox motor driven by an H-bridge will be sufficient. The panel will stop at the west end when the light level falls below the DUSK_DAWN definition and automatically return to the east when the level increases above the threshold the next morning. Any pair of reasonable matched sensors can be used.

@Arctic_Eddie:
Yep that would work, what I was thinking about is is a contraption with the rotation axis pointed at the celestial pole, (35 degrees above the due North horizon here), and another platform with a East / West (horizontal) axis on top of that for seasonal declination adjustment, it would only complete a cycle once a year.

You probably don't need the seasonal tracker as it can be hand cranked once a month. If you set the declination to NCP-90 and leave it there then your lowest capture efficiency at the solstices is still 89% when the error is 23°. Look for one of the old C-band satellite dish mounts. They can be hand cranked for declination and motor driven for hour angle.

I will post my sensor drawing shortly.

Here's a drawing of a simple tracker sensor setup. The device consists of two sensors, reasonably balanced, and mounted above the top edge of the panel. There is a third fixed sensor aimed at the eastern horizon to detect sunrise. The drawing view is from above the panel looking down it's face toward the ground.

The ratio of H/D determines the deadband angle. With a ratio of 10, both sensors will be illuminated in the angular range +/- 5.7°. The panel would be moved about every 45 minutes. It would be moved when the sun moves to the west so that the east sensor becomes shadowed by the partition. The panel is moved west until the west sensor is shadowed. At that point, it will be 45 minutes until the east sensor is shadowed. During this time, the panel collection efficiency is 99.5% or greater.

The drive mechanism can be a 24VDC gearmotor driven by an H-bridge. There are numerous sources on eBay.