Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

Salutations and thank you for visiting The IoT Projects. This guide is intended to show the ways of building the Dual Axis Solar Tracker Arduino Project using LDRs and Servo Motors. The publication can be divided into seven parts, which can determine an extensive guide on how to build the project. Thus using light sensing devices like LDRs it is possible to observe the sunlight and in turn realign the position of this solar panel to help increase its efficiency. Now let’s examine each of the mentioned parts as well as the careful and thoughtful approach to the project.

Working Principle of LDR Sensor

In this assignment, the LDRs act as light-sensing tools, also called photoresistors, that react to light. The graph indicates that as the intensity of light increases, the resistance of an LDR decreases. In our setup, we employ four LDRs for detecting the sun. By transmitting a signal to the Arduino, two servo motors will be activated to adjust the solar panel’s orientation, optimizing its performance by aligning it with the sun’s rays.

Project Simulation: Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

Before delving into the wiring system, we will provide a comprehensive overview of the project. However, for now, let’s proceed with a simulation of the project.

Upon powering up the Arduino, the sensors and servo motors are activated, as illustrated in the provided image. When the LDR sensor detects an increase in brightness, it sends a signal to the Arduino. Thus, the Arduino controls both servo motors to adjust the position of the solar panel for better performance. The servo motors respond correctly to variations in light brightness.

Additionally, the two potentiometers can be used to vary the speed of the servo motors. We will delve deeper into this aspect within the programming section.

Tinkercad Dual Axis Solar Tracker Arduino Simulation file

Interfacing Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

To establish the necessary connections, follow these steps:

1. Connect the 5V pin from the Arduino to the lower horizontal row of the breadboard.
2. Similarly, connect the GND pin from the Arduino to a second lower horizontal row of the breadboard.
3. Extend the 5V and GND rows to the upper horizontal rows of the breadboard.
4. Connect the power pins of both the vertical and horizontal servo motors to the 5V row.
5. Connect the GND pin of both the horizontal and vertical servo motors to the GND row.
6. Connect the signal pin of the vertical servo motor to digital pin 10 of the Arduino.
7. Connect the signal pin of the horizontal servo motor to digital pin 9 of the Arduino.
8. Connect one terminal of both potentiometers to the GND row, and the other end terminals of both potentiometers to the 5V row.
9. Connect each LDR from one terminal to the 5V row and the other terminal to the GND row through 10k-ohm resistors.
10. Connect the wiper pin of potentiometer 1 to analog pin A4, and the wiper pin of potentiometer 2 to analog pin A5.
11. Connect the bottom-left LDR voltage divider point to analog pin A1 of the Arduino.
12. Connect the top-left LDR voltage divider point to analog pin A0 of the Arduino.
13. Similarly, connect the top-right LDR voltage divider point to analog pin A2.
14. Finally, connect the bottom-right voltage divider point of the LDR to analog pin A3 of the Arduino.

By following these steps, you will successfully establish the necessary connections between the components and the Arduino.

Programming Arduino for Dual Axis Solar Tracker Project

#Include is used to include a servo header library file.

#include <Servo.h> 

For the configuration of the horizontal servo, follow these settings:

1. Set the horizontal servo to a position of 180 degrees.
2. Set the servo’s limit to 175 degrees when the signal is high.
3. Set the servo’s limit to 5 degrees when the signal value is low.

By adjusting these configurations, you can control the range of motion for the horizontal servo.

Servo horizontal; // horizontal servo
int servoh = 180;
int servohLimitHigh = 175;
int servohLimitLow = 5;
// 65 degrees MAX

To configure the vertical servo, follow these steps:

1. Set the vertical servo to a position of 45 degrees.
2. Set the servo’s limit to 60 degrees when the signal is high.
3. Set the servo’s limit to 1 degree when the signal value is low.

By adjusting these settings, you can control the range of motion for the vertical servo, allowing it to move within the specified limits.

Servo vertical; // vertical servo
int servov = 45;
int servovLimitHigh = 60;
int servovLimitLow = 1;

Here are the pin connections for the LDRs:

– ldrlt: Pin for the top-left LDR.
– ldrrt: Pin for the top-right LDR.
– ldrld: Pin for the bottom-left LDR.
– ldrrd: Pin for the bottom-right LDR.

By correctly connecting these pins, you can ensure that the LDRs function properly and provide the necessary input for the solar tracking mechanism.
// LDR pin connections
// name = analogpin;
int ldrlt = A0; //LDR top left – BOTTOM LEFT <— BDG
int ldrrt = A3; //LDR top rigt – BOTTOM RIGHT
int ldrld = A1; //LDR down left – TOP LEFT
int ldrrd = A3; //ldr down rigt – TOP RIGHT

In the `void setup()` function, we perform the following actions:

1. We attach the signal pins for the vertical and horizontal servos.
2. The rotation of the horizontal servo is set to 180 degrees.
3. Similarly, the vertical servo is set to 45 degrees.
4. A delay of 2.5 seconds is implemented.

By carrying out these setup steps, we ensure that the servos are initialized correctly and positioned as desired before the main program execution begins.

void setup(){
horizontal.attach(9);
vertical.attach(10);
horizontal.write(180);
vertical.write(45);
delay(2500);
}

In the `void loop()` function, the following actions take place:

1. We read the analog pin values of the Arduino connected to the LDRs.
2. The average values of the vertical and horizontal LDR readings are calculated.

By obtaining the LDR readings and calculating their averages, we can determine the position of the sunlight and make the necessary adjustments to the servo motors for optimal solar panel orientation.

void loop() {
int lt = analogRead(ldrlt); // top left
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left
int rd = analogRead(ldrrd); // down right
int dtime = 10; int tol = 90; // dtime=diffirence time, tol=toleransi
int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right
int dvert = avt – avd; // check the diffirence of up and down
int dhoriz = avl – avr;// check the diffirence og left and rigt

The program utilizes IF and IF-ELSE statements within a loop to continuously calculate the average values of the LDRs. Based on these values, the code adjusts the degrees of the servo motors to optimize their effectiveness in tracking the sunlight.

By incorporating these conditional statements, the program ensures that the servo motors respond accordingly to changes in light intensity and accurately position the solar panel for maximum efficiency.

if (-1*tol > dvert || dvert > tol)
{
if (avt > avd)
{
servov = ++servov;
if (servov > servovLimitHigh)
{servov = servovLimitHigh;}
}
else if (avt < avd)
{servov= –servov;
if (servov < servovLimitLow) { servov = servovLimitLow;} } vertical.write(servov); } if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)
{
servoh = –servoh;
if (servoh < servohLimitLow)
{
servoh = servohLimitLow;
}
}
else if (avl < avr) { servoh = ++servoh; if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
}
else if (avl = avr)
{
delay(5000);
}
horizontal.write(servoh);
}
At last, we have added the delay of (dtime).

delay(dtime);

}
Now, compile the program and upload it to your Arduino board.

Our IoT Based Projects Resources:

This Coronavirus Tracker uses the ESP8266 development board for your nation.

Real-time Monitoring the Temperature and Humidity of DHT11 or DHT22 withe NodeMCU ESP8266 & Local Webserver

Home Automation with ESP8266 Web Server & Relay Module Control Appliances from Local Network

Firstly, having an Arduino and an LCD, we have to connect the DHT11 Humidity and Temperature Sensor with Arduino & LCD.

Real time monitoring and detection of floods using IoT, Node MCU & Thing speak

Final Program code/sketch
#include

Servo horizontal; // horizontal servo
int servoh = 180;
int servohLimitHigh = 175;
int servohLimitLow = 5;
// 65 degrees MAX

Servo vertical; // vertical servo
int servov = 45;
int servovLimitHigh = 60;
int servovLimitLow = 1;

// LDR pin connections
// name = analogpin;
int ldrlt = A0; //LDR top left – BOTTOM LEFT <— BDG int ldrrt = A3; //LDR top rigt – BOTTOM RIGHT int ldrld = A1; //LDR down left – TOP LEFT int ldrrd = A3; //ldr down rigt – TOP RIGHT void setup(){ horizontal.attach(9); vertical.attach(10); horizontal.write(180); vertical.write(45); delay(2500); } void loop() { int lt = analogRead(ldrlt); // top left int rt = analogRead(ldrrt); // top right int ld = analogRead(ldrld); // down left int rd = analogRead(ldrrd); // down right int dtime = 10; int tol = 90; // dtime=diffirence time, tol=toleransi int avt = (lt + rt) / 2; // average value top int avd = (ld + rd) / 2; // average value down int avl = (lt + ld) / 2; // average value left int avr = (rt + rd) / 2; // average value right int dvert = avt – avd; // check the diffirence of up and down int dhoriz = avl – avr;// check the diffirence og left and rigt if (-1*tol > dvert || dvert > tol)
{
if (avt > avd)
{
servov = ++servov;
if (servov > servovLimitHigh)
{servov = servovLimitHigh;}
}
else if (avt < avd)
{servov= –servov;
if (servov < servovLimitLow) { servov = servovLimitLow;} } vertical.write(servov); } if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)
{
servoh = –servoh;
if (servoh < servohLimitLow)
{
servoh = servohLimitLow;
}
}
else if (avl < avr) { servoh = ++servoh; if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
}
else if (avl = avr)
{
delay(5000);
}
horizontal.write(servoh);
}

delay(dtime);

}

Video Tutorials

Conclusion

Well done on finishing the build of the Dual Axis Solar Tracker with Arduino, LDRs, and servos! By tracking the sun’s movement, this project allows solar panels to maximize energy collection throughout the day, improving efficiency by up to 40%.

We hope you found the process of interfacing the LDR light sensors and servo motors to be an informative learning experience. This project demonstrates how combining hardware and code can create solutions to real-world problems. Please feel free to provide any feedback or ask additional questions – we’re happy to help clarify or expand on any parts of the project. Thank you for taking the time to complete this solar tracking build; we’re glad you could participate in exploring ways to boost renewable energy generation.


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top