DEV Community

Sameer Aftab
Sameer Aftab

Posted on

 

Single Axis Solar Tracking System using Arduino

Welcome back to my blog today we will be making a single-axis solar tracking system using Arduino UNO

Required Components

  1. Arduino Uno rev3
  2. Servo motor SG90
  3. Breadboard small
  4. LDR 5mm (Light Dependent Resistor)
  5. Resistor 10k ohms (2x)
  6. Jumper Wires (10x)
  7. Solar Panel 5.5v
  8. 9v Battery
  9. Battery connector

Tools Required

  1. Glue Gun
  2. Soldering Iron
  3. Arduino IDE
  4. 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

  1. Connect LDR to 5 Volts and another Pin to A0 and then to a 10K resistor connected to the ground.

  2. 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.

  1. 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!!!

Block Diagram for Single Axis Solar tracking Using Arduino

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);
  }
}
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)