Circuit Solar Tracker with Servo Motor Proposal

This solar tracker system uses the Arduino UNO board, a servomotor, 2 LDRs and 2 resistors to rotate the solar panel towards the Sun or a source of light. Here
I have a standard servo that can rotate approximately 180 degrees (90° in each direction) and is controlled using the included Arduino’s Servo Library. The code is simple too and I’ll try to explain it after this video where I made a short presentation of the project in action. Unfortunately I had no solar panel at that moment.
Here is the Sketch Code:
  1. #include <Servo.h>
  2. Servo myservo;
  3. int pos = 90; // initial position
  4. int sens1 = A0; // LRD 1 pin
  5. int sens2 = A1; //LDR 2 pin
  6. int tolerance = 2;
  7. void setup()
  8. {
  9. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  10. pinMode(sens1, INPUT);
  11. pinMode(sens2, INPUT);
  12. myservo.write(pos);
  13. delay(2000); // a 2 seconds delay while we position the solar panel
  14. }
  15. void loop()
  16. {
  17. int val1 = analogRead(sens1); // read the value of sensor 1
  18. int val2 = analogRead(sens2); // read the value of sensor 2
  19.  
  20. if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
  21. //do nothing if the difference between values is within the tolerance limit
  22. } else {
  23. if(val1 > val2)
  24. {
  25. pos = --pos;
  26. }
  27. if(val1 < val2)
  28. {
  29. pos = ++pos;
  30. }
  31. }
  32.  
  33. if(pos > 180) { pos = 180; } // reset to 180 if it goes higher
  34. if(pos < 0) { pos = 0; } // reset to 0 if it goes lower
  35. myservo.write(pos); // write the position to servo
  36. delay(50);
  37. }
Inside the code we use the “pos” variable to set the initial position of the servo to 90, the mid position. The 2 LDRs are connected to pin A0 and A1 on the board. The “tolerance” variable is used for allowing a small tolerance otherwise the solar panel would be continously adjusting its position.
In the setup() function we set the pins were the LDR are connected as INPUTs and position the servo motor at 90° then wait for a 2 seconds before the code execution inside the loop(). In the loop() we read the values received from our 2 sensors and adjust the solar panel based on these values.

Schematic of the Arduino Solar Tracker Circuit

arduino solar tracker circuit
As you can see in the schematic all that you need to make the electrical part is the board, one servo, 2 LDRs and 2 x 10K resistors. Usually the servo has a yellow wire that is used to control the rotation and it must be connected on pin 9 on the board.
The 2 LDRs (light dependent resistors) must be positioned the same way as the ones showned here at a slightly different angle. If your servo acts weird try to connect a 470µF/10V capacitor between the +5V and GND.

No comments:

Post a Comment

its cool