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:
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.
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.
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:
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.
- #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);
- }
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
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