Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Solar Tracking System with Light-Dependent Resistors and Servos

View and Edit Project In Cirkit DesignerImage of Arduino UNO Solar Tracking System with Light-Dependent Resistors and Servos

Solar Tracking Energy System Documentation

Summary

This document provides a detailed overview of a solar tracking energy system designed using an Arduino UNO, servos, light-dependent resistors (LDRs), resistors, and Qwiic cables. The system adjusts the position of a solar panel to align with the direction of maximum sunlight using two servos controlled by the Arduino UNO. The LDRs provide feedback on the light intensity from different directions, allowing the system to determine the optimal position for the solar panel.

Component List

Arduino UNO

Resistor

Servo

Photocell (LDR)

Qwiic Cable - Breadboard Jumper (4-pin)

Wiring Details

Arduino UNO

Resistor

Servo

Photocell (LDR)

Qwiic Cable - Breadboard Jumper (4-pin)

Code Documentation

/*
 * Solar Tracking Energy System
 * This Arduino sketch controls a solar tracking system using two servos and four
 * light-dependent resistors (LDRs). The servos adjust the position of the solar
 * panel to align with the direction of maximum sunlight.
 */

#include <Servo.h>

// Define pins for servos
const int servoPin1 = 10;
const int servoPin2 = 9;

// Define pins for LDRs
const int ldrPin1 = A0;
const int ldrPin2 = A1;
const int ldrPin3 = A2;
const int ldrPin4 = A3;

// Create servo objects
Servo servo1;
Servo servo2;

void setup() {
  // Attach servos to their respective pins
  servo1.attach(servoPin1);
  servo2.attach(servoPin2);

  // Initialize serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Read LDR values
  int ldrValue1 = analogRead(ldrPin1);
  int ldrValue2 = analogRead(ldrPin2);
  int ldrValue3 = analogRead(ldrPin3);
  int ldrValue4 = analogRead(ldrPin4);

  // Print LDR values for debugging
  Serial.print("LDR1: ");
  Serial.print(ldrValue1);
  Serial.print(" LDR2: ");
  Serial.print(ldrValue2);
  Serial.print(" LDR3: ");
  Serial.print(ldrValue3);
  Serial.print(" LDR4: ");
  Serial.println(ldrValue4);

  // Calculate average LDR values for horizontal and vertical axes
  int avgHorizontal = (ldrValue1 + ldrValue2) / 2;
  int avgVertical = (ldrValue3 + ldrValue4) / 2;

  // Map LDR values to servo positions
  int servoPos1 = map(avgHorizontal, 0, 1023, 0, 180);
  int servoPos2 = map(avgVertical, 0, 1023, 0, 180);

  // Move servos to calculated positions
  servo1.write(servoPos1);
  servo2.write(servoPos2);

  // Delay for stability
  delay(1000);
}

This code controls the solar tracking system by reading the values from the LDRs, calculating the average light intensity for the horizontal and vertical axes, and adjusting the positions of the servos accordingly. The servos are moved to the positions that align the solar panel with the direction of maximum sunlight.