Welcome back to my blog today we will be making a single-axis solar tracking system using Arduino UNO
Required Components
- Arduino Uno rev3
- Servo motor SG90
- Breadboard small
- LDR 5mm (Light Dependent Resistor)
- Resistor 10k ohms (2x)
- Jumper Wires (10x)
- Solar Panel 5.5v
- 9v Battery
- Battery connector
Tools Required
- Glue Gun
- Soldering Iron
- Arduino IDE
- Laptop
Background
Solar panels generate the most electricity when the incoming light is perpendicular to the panel. A solar tracker rotates the panel along one or two axes (altitude and azimuth) so that it always faces the sun directly. This can add up to 25% more energy compared with a fixed panel.
Assembly
Connect LDR to 5 Volts and another Pin to A0 and then to a 10K resistor connected to the ground.
Connect the second LDR to 5 Volts and another pin to A1 and then to a 10K resistor connected to the ground.
This is a voltage splitter that will give a variable voltage to the analog inputs depending on the light hitting each LDR.
- Connect the servo brown wire to the ground of the battery, the red wire to the 9V, and the orange wire to digital pin 9.
Servo need's more power to function properly
Let's have a look at Circuit Diagram!!!
Code
//Code Written by TECH_TELE
#include <Servo.h>
Servo sg90;
int ldr_1 = A0; // lrd pin connected to A0
int ldr_2 = A1; // LDR pin connected to A1
int servo_pin = 9;
int pos = 90;// initial position
int servo_max=178; // maximum position for servo
int servo_min=2; // minimum position for servo
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ldr_1, INPUT);
pinMode(ldr_2, INPUT);
sg90.attach(servo_pin);// servo pin declared 9 Line no 5
sg90.write(pos);
}
void loop() {
double ldrStatus1 = analogRead(ldr_1);
double ldrStatus2 = analogRead(ldr_2);
Serial.print("LDR1 Status:");
Serial.print(ldrStatus1);
Serial.println("");
Serial.print("LDR2 Status:");
Serial.print(ldrStatus2);
Serial.println("");
if(ldrStatus1>ldrStatus2){
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
sg90.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
if(ldrStatus1<ldrStatus2){
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
sg90.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
}
Top comments (2)
SG90 servo operating voltage is 4.8 - 6.0 volts and you have it connected to a 9 volt battery. It is likely that the servo will get damaged with such a high voltage and cease to function in a very short time.
What does the tracker do when it gets dark? Does it return to the east and wait for sunrise as I don't see anything in the code that would make it do that.
Thanks