This DIY Sun Tracker will dynamically adjusts the position of the solar panel to face the sun directly, maximizing the amount of sunlight captured. Here we will dive deep into how to create a dual-axis sun tracking solar panel project using Arduino, its components, working principles, and more.

Components Required

For this project, you will need:

  • Arduino Uno: The brain of the project, responsible for processing data and controlling the motors.
  • 4 Light Dependent Resistors (LDRs): Detect light intensity from different directions.
  • 4 Resistors (10k ohm): Form a voltage divider circuit with the LDRs.
  • 2 SG90 Servo Motors: One controls the horizontal axis (azimuth), and the other controls the vertical axis (elevation).
  • Solar Panel: Demonstrates how the tracker aligns the panel with sunlight.
  • Breadboard and Jumper Wires: For making temporary connections.
  • Epoxy Sheets: For making frames and brackets to mount the solar panel, sensors, and servos.
  • Heat Gun: For securing the components and ensuring stability in the assembly.
  • Glue Stick: Used with the heat gun for fixing LDRs, solar panel mounts, and other elements on the frame.

Working Principle

The arduino based sun tracking solar panel project works on the principle of comparing light intensities to determine the sun’s position. Here’s how it operates:

  1. Light Detection:

    • Four LDRs are placed in a cross pattern around the solar panel, dividing it into four quadrants: top-left, top-right, bottom-left, and bottom-right.
    • Each LDR senses the intensity of sunlight in its respective quadrant and sends the analog data to the Arduino.
  2. Data Processing:

    • The Arduino reads the LDR values and calculates the differences between opposing quadrants:
      • Horizontal difference = (Top-Left + Bottom-Left) - (Top-Right + Bottom-Right)
      • Vertical difference = (Top-Left + Top-Right) - (Bottom-Left + Bottom-Right)
    • These differences indicate the direction in which the solar panel needs to move to align with the sun.
  3. Servo Adjustment:

    • Based on the calculated differences, the Arduino adjusts the angles of the horizontal and vertical servos.
    • The servos move incrementally until the light intensity is balanced across all LDRs, indicating that the panel is aligned with the sun.
  4. Dynamic Tracking:

    • As the sun moves throughout the day, the system continuously adjusts the panel’s position to ensure it remains perpendicular to the sun’s rays.

Sun Tracking Solar Panel Circuit Diagram

Sun Tracking Solar Panel Project Circuit Diagram
Arduino Sun Tracking Solar Panel Project Circuit Diagram

The circuit connections are as follows:

  1. LDRs: Connect the LDRs to analog pins A0, A1, A2, and A3 on the Arduino. Pair each LDR with a 10k ohm resistor in a voltage divider configuration.
  2. Servos: Connect the signal pins of the servos to digital pins 2 and 13 of the Arduino. The power and ground pins are connected to a 5V source and GND, respectively.
  3. Power Supply: Use a 5V power supply for the Arduino and servos.

Code Explanation

#include <Servo.h>
Servo horizontalServo;
Servo verticalServo;

  • The Servo library is included to control the servo motors.
  • Two Servo objects are declared: horizontalServo for horizontal movement and verticalServo for vertical movement.

int ldrTopLeft = A2;
int ldrTopRight = A1;
int ldrBottomLeft = A3;
int ldrBottomRight = A0;

  • These pins are connected to the LDRs to read analog light intensity values.

int horizontalPos = 90;
int verticalPos = 90;

  • Initial angles for both servos are set to 90 degrees, which is the neutral position.

void setup() {
  horizontalServo.attach(2); 
  verticalServo.attach(13);  

  • The servos are attached to pins 2 and 13.

  horizontalServo.write(horizontalPos);
  verticalServo.write(verticalPos);

  • The servos are set to their initial positions (90 degrees).

  pinMode(ldrTopLeft, INPUT);
  pinMode(ldrTopRight, INPUT);
  pinMode(ldrBottomLeft, INPUT);
  pinMode(ldrBottomRight, INPUT);

  • The LDR pins are configured as input to read analog values.

  Serial.begin(9600);

  • Initializes serial communication for debugging.

void loop() {
  int topLeft = analogRead(ldrTopLeft);
  int topRight = analogRead(ldrTopRight);
  int bottomLeft = analogRead(ldrBottomLeft);
  int bottomRight = analogRead(ldrBottomRight);

  • Reads analog values from the four LDRs.

int horizontalDifference = (topLeft + bottomLeft) - (topRight + bottomRight);
int verticalDifference = (topLeft + topRight) - (bottomLeft + bottomRight);

  • horizontalDifference: Compares light intensity on the left vs. right.
  • verticalDifference: Compares light intensity on the top vs. bottom.

  if (horizontalDifference > 50) horizontalPos += 1;
  else if (horizontalDifference < -50) horizontalPos -= 1;

  if (verticalDifference > 50) verticalPos += 1;
  else if (verticalDifference < -50) verticalPos -= 1;

  • If the light difference exceeds 50 units, the servo is moved by 1 degree in the appropriate direction.

  horizontalPos = constrain(horizontalPos, 0, 180);
  verticalPos = constrain(verticalPos, 0, 180);

  • Limits the servo angles between 0 and 180 degrees to prevent out-of-range errors.

  horizontalServo.write(horizontalPos);
  verticalServo.write(verticalPos);

  • Moves the servos to the updated angles.

  delay(50);

  • A small delay of 50ms ensures smoother servo movement and prevents rapid oscillations.

Code for Sun Tracking Solar Panel Project

#include <Servo.h>

// Declare servo objects
Servo horizontalServo;
Servo verticalServo;

// LDR pins
int ldrTopLeft = A2; 
int ldrTopRight = A1; 
int ldrBottomLeft = A3; 
int ldrBottomRight = A0; 

// Servo positions
int horizontalPos = 90; // Initial horizontal angle
int verticalPos = 90;   // Initial vertical angle

void setup() {
  horizontalServo.attach(2); // Connect horizontal servo to pin 2
  verticalServo.attach(13);  // Connect vertical servo to pin 13

  // Set initial servo positions
  horizontalServo.write(horizontalPos);
  verticalServo.write(verticalPos);

  pinMode(ldrTopLeft, INPUT);
  pinMode(ldrTopRight, INPUT);
  pinMode(ldrBottomLeft, INPUT);
  pinMode(ldrBottomRight, INPUT);

  Serial.begin(9600); // For debugging
}

void loop() {
  // Read LDR values
  int topLeft = analogRead(ldrTopLeft);
  int topRight = analogRead(ldrTopRight);
  int bottomLeft = analogRead(ldrBottomLeft);
  int bottomRight = analogRead(ldrBottomRight);

  // Calculate differences
  int horizontalDifference = (topLeft + bottomLeft) - (topRight + bottomRight);
  int verticalDifference = (topLeft + topRight) - (bottomLeft + bottomRight);

  // Adjust horizontal servo
  if (horizontalDifference > 50) horizontalPos += 1;
  else if (horizontalDifference < -50) horizontalPos -= 1;

  // Adjust vertical servo
  if (verticalDifference > 50) verticalPos += 1;
  else if (verticalDifference < -50) verticalPos -= 1;

  // Constrain servo angles to valid range
  horizontalPos = constrain(horizontalPos, 0, 180);
  verticalPos = constrain(verticalPos, 0, 180);

  // Move servos to new positions
  horizontalServo.write(horizontalPos);
  verticalServo.write(verticalPos);

  delay(50); // Small delay for smooth movement
}

Leave a comment

Please note, comments must be approved before they are published

Your cart

×