Notifications
Clear all

Solar tracker with to LDR

10 Posts
3 Users
0 Likes
391 Views
henrik_t7
(@henrik_t7)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

I have made a solar tracker with two LDRs and a servo motor, see drawing of the conversion.

 

ezgif.com webp to jpg

found this code on the net, but it doesn't work, servo motor runs around and not right and left.

 

#include <Servo.h>  //includeing the library of servo motor
Servo sg90;
int initial_position = 90;
int LDR1 = A0; // connect LDR1 on pin A0
int LDR2 = A1; // connect lDR2 on pin A1
int error = 5;
int servopin = 9; // servo on pin 9

void setup() {
  sg90.attach(servopin);
  pinMode(LDR1, INPUT);
  pinMode(LDR2, INPUT);
  sg90.write(initial_position); //move servo at 90 degree
  delay(2000);

}

void loop() {
  int R1 = analogRead(LDR1);  // raed LDR1
  int R2 = analogRead(LDR2);  // read LDR2
  int diff1 = abs(R1 - R2);
  int diff2 = abs(R2 - R1);

  if ((diff1 <= error) || (diff2 <= error)) {

  } else {
    if (R1 > R2)
  {
  initial_position = - initial_position;
  }
    if(R1 < R2)
  {
   initial_position = ++ initial_position;
  }
  }
  sg90.write(initial_position);
  delay(100);

}

 


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6907
 

@henrik_t7 I would be highly skeptical about any code that was driving a servo in this application. I have a 1.2kWh battery bank, and 1.08kW of solar. I would be using a stepper if I was to do this but I don't need to. I know there are others here who have done something like this so a search here on the forum might bear fruit.

I will tell you that tracking is more complicated than a simple 1 axis movement. If you live very close to the equator then that is fine but if you live further north you will get the biggest bang for your buck with a 2-axis, or if only 1-axis use it to track North-South, not East-West. The most frequent advice today is rather than spending a lot of time and money on tracking, lay them flat and buy 1 more panel than you planned, which generally gives better absolute performance and for sure better price performance.

Use this website to calculate the effect of different angles, I think you will be surprised by some of the answers LINK

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2508
 

Posted by: @henrik_t7

I have made a solar tracker with two LDRs and a servo motor, see drawing of the conversion.

 

-- attachment is not available --

found this code on the net, but it doesn't work, servo motor runs around and not right and left.

 

The code you found on the 'net cost nothing and is worth every penny of it.

Since abs(R1-R2) = abs(R2-R1) (since only sign and not magnitude changes) calculating and using BOTH diff1 and diff2 is meaningless, only one is required.

Second, setting initial_position = -initial_position will tend to change from 90 to -90 which is NOT a valid servo position (they usually range from 0-180) so your servo may not be able to move to the new value supplied.

Third, the prefix operator ++ increments the value of the variable so setting initial_position to ++initial_position is a very sketchy way of incrementing the variable's value by 1.

Fourth, if you consider what's happening here

   If R1 is bigger than R2 then reverse the sign of servo argument.       BUT

   If R1 is smaller than R2 then add 1 to it

Which seems odd, doesn't it ? Depending on which way your servo is oriented (i.e. 0=EAST and 180=WEST or vice versa) you'd want to adjust the orientation as the sun moves westward and then when BOTH register no light, then move fully to the EAST end to prepare for tomorrow's dawn.

I presume that your LDRs are pointed at 45 degree angles towards  the EAST and WEST. so that only one shows full strength at midmorning and one at mid afternoon 

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6907
 

@will @henrik_t7 One thing that may not be obvious is what happens to a servo when even a small 2' x 5' solar panel is hit with 30 mph winds.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2508
 

@zander 

That's what the windmill is for 🙂

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6907
 

@will They even work in the dark.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
henrik_t7
(@henrik_t7)
Member
Joined: 3 years ago
Posts: 21
Topic starter  

Thanks for the answers Since the code isn't worth anything, what do you have to do to make it work??

Have started again with Arduino, after a few years break and programming is not my strong point.

If there are some like here an idea for it, rest I will be very happy.

Here in Denmark, where I live, the sun goes from east to west. I have a small solar charger for some electronics, but it sits still somewhere and the solar cells only get power when the sun gets there. therefore it could be smart for solar cells to follow the sun.

Thanks


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6907
 

@henrik_t7 Making the code work isn't really the issue. Being so far north means the sun actually rises in the NE in the summer with the most extreme northing on the solstice, and likewise in the winter months, it rises extremely far SE. That means you need to tilt the panels north and south to match the seasonal changes and east and west to match the daily changes. I gave you a link to a website where you can see the effect of various tilting (NS) angles on seasonal yields.

You are at 55 degrees, I am at 49 degrees. The two screenshots show you the effect of no tilt vs matching the tilt to your latitude, which means the sun's rays are striking your panels at 90 degrees BUT only on one day a year. This is where one motor/sensor array operates. It makes the panels face the sun at 90 degrees every day. Then you need a second set of motors/sensors to tilt along the EW axis to follow the daily travel of the sun.

Look closely at the two included charts, I think you will see something unusual. Yes, the winter months production goes up when tilted to match the latitude, but it goes down for the summer months as the sun is literally behind the panels. I first noticed this when I lived in a house oriented along compass lines with the north wall almost all glass. At 11 pm I would watch the sun set in the NORTH.

What  I am trying to do is show you that to do this project, you need first to construct a mechanical system to mount the panel to and equip it with 2 motors and 2 sensors. I know a place with a large tracking panel and I can try to get information from them if you are interested. There is actually 2 panels, each panel is probably 2M x 2M. I am sure the cost is several thousand.

I am including a link to a sun tracker and a picture showing your track on June 20 near Copenhagen. Notice that the sun is in the north from about 4 AM to 8 AM and again from about 1800 to 2200. If you change the location to somewhere further south, you will see the early morning and late evening sections are much smaller to the north, and the noon azimuth is higher.

I live full-time in an RV, and the RF community are big users of solar. We discovered some time ago (by using the PVWatts app) that it is more cost-effective to just add an extra panel and leave them all flat. In fact, because our roof is curved, about 1/2 will be tilted very slightly to the south and 1/2 to the north. 

In summary, IF you are interested in the intellectual exercise of having your panels always perpendicular to the sun's rays in order to get the maximum power from your panels, you need a substantial mounting mechanism with 2 motors and 2 sensor arrays. You also need to spend electricity to move the motors. In these cases, I recommend only changing the NS tit once per week and the EW tilt every 15 minutes. Keep good records and let us know the annual NET numbers.

SunCalc link HERE

Screenshot 2023 03 26 at 06.18.58
Screenshot 2023 03 26 at 06.19.38

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2508
 

Posted by: @henrik_t7

Thanks for the answers Since the code isn't worth anything, what do you have to do to make it work??

Have started again with Arduino, after a few years break and programming is not my strong point.

It's hard to say how to fix the code because you haven't said anything about the configuration of the LDRs. There are a couple of different strategies I can imagine.

Perhaps having two hand selected balanced LDRs sloped away from each other at a small angle. I say balanced because you'll need to buy a pack and then test each one to find the pair that comes closest to an exact match of each other's readings.

You would then write your sketch to turn the servo in such a way as to make the two LDR readings equal. That is, the LDRs are both pointing the same angle AWAY from the sun. When neither registers any light, return to wherever EAST is and wait for the next day,

If you use 4 LDRs with the second (balanced) pair oriented perpendicular to the first set, you could then implement bidirectional tracking.

Ron has already made some suggestions for your continuing research.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6907
 

@will @henrik_t7 Here is a pic of what the full NS and EW trackers look like. Obviously, if you only want EW or NS then just do 2 walls.

Screenshot 2023 03 26 at 09.30.02

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote