Advertisement
arduino solar tracker circuit

Arduino Solar Tracker with ServoMotor

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 http://www.electroschematics.com/8019/diy-solar-tracker-system/ you can find the version with DC motors, but without Arduino.

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:

#include <Servo.h> 
 
Servo myservo; 
int pos = 90;   // initial position
int sens1 = A0; // LRD 1 pin
int sens2 = A1; //LDR 2 pin
int tolerance = 2;
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pinMode(sens1, INPUT);
  pinMode(sens2, INPUT);
  myservo.write(pos);
  delay(2000); // a 2 seconds delay while we position the solar panel
}  
 
void loop() 
{ 
  int val1 = analogRead(sens1); // read the value of sensor 1
  int val2 = analogRead(sens2); // read the value of sensor 2

  if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
    //do nothing if the difference between values is within the tolerance limit
  } else {    
    if(val1 > val2)
    {
      pos = --pos;
    }
    if(val1 < val2) 
    {
      pos = ++pos;
    }
  }

  if(pos > 180) { pos = 180; } // reset to 180 if it goes higher
  if(pos < 0) { pos = 0; } // reset to 0 if it goes lower
  
  myservo.write(pos); // write the position to servo
  delay(50);
}

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.

26 Comments

Join the conversation!

Error! Please fill all fields.
  • stephen-maughansky-com

    My 9 year old son loved this simple solar tracker, he now wants to build one to rotate a 100w solar panel….I think the servo may need upgrading 😉

  • hardikgjr

    I tried the above, its not working well. My motor rotates full 180 degree & doesn’t stops at the location of light..
    plz help me out

  • Bobette

    Hey! I think this is a great project. I am doing something very similar and was wondering whether it is possible to replace the servo motors with the stepper motors. I understand that stepper motors are less efficient, however, they are all I have.

  • Surya

    HI…
    a small doubt!!
    At 12:00 PM the sun will be at the center and values of LDR1 and LDR2 are same.. at that time the panel have to place in horizontal position exactly..
    but
    here it is not possible!!
    can i have a solution?

  • Fabiano

    Incredible.

    You save my life (and my work too) with this project.

    Sorry my bad English

    Thanks.

  • Madhav

    Good, clean and neat project. I would like to see a PWM driving the MOSFET based H bridge. The PWM should be as per the error in the east and west sensors. In other words, if the error is large, the PWM should try to reach the desired position faster with larger T(on) time and as the position is being reached, the T(on) should decrease.

    The reset facility is also a very good feature to add along with the control for the second axis – the north to south, so that the solstice can be taken care of, improving the performance and efficiency.

    Again, a great project and keep it up….Cheers.

  • H De

    can you please specify the ratings of LDR, and the servo motor?
    Thank you

  • abhi mike

    can i use stepper motor instead of servo motor?

  • Muhammad Zuhaib

    What about LDR ratings? plz tell us

  • zaibkamboh

    Plz inform me about CLDR ratings?

Looking for the latest from TI?