Greetings and welcome to The IoT Projects. In this tutorial, we will guide you through the process of creating a Dual Axis Solar Tracker Arduino Project using LDR (Light Dependent Resistor) and Servo Motors. We have organized the article into seven segments, providing a step-by-step approach to building this project. By utilizing light-sensitive sensors such as LDRs, we can track the sunlight and adjust the position of the solar panels accordingly, enhancing their efficiency. Let’s dive into each segment and explore the project in detail.
Working Principle of LDR Sensor
In this project, the LDRs function as light detectors, or photoresistors, which are sensitive to light. As illustrated in the graph, the resistance of an LDR decreases as light intensity increases. In our setup, we employ four LDRs to detect sunlight. Once they send a signal to the Arduino, it will instruct two servo motors to adjust the position of the solar panel, optimizing its efficiency by directing it towards the maximum sunlight exposure.
Project Simulation: Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors
In this section, we will provide a comprehensive overview of the project before delving into the wiring system. However, for now, let’s proceed with a simulation of the project.
Upon powering on the Arduino, all the sensors and servo motors come into action, as depicted in the image above. When the light intensity on the LDR sensor increases, it sends a signal to the Arduino. As a result, the Arduino guides the two servo motors to adjust the position of the solar panel, aiming to maximize its efficiency. The servo motors respond accordingly as the light intensity is increased or decreased.
Furthermore, by utilizing the two potentiometers, you can control the speed of the servo motors. We will discuss this aspect further in 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:
ESP8266 based Coronavirus Tracker for your country
NodeMCU ESP8266 Monitoring DHT11/DHT22 Temperature and Humidity with Local Web Server
Home Automation with ESP8266 Web Server & Relay Module Control Appliances from Local Network
Interfacing DHT11 Humidity and Temperature Sensor with Arduino & LCD
IoT Based Flood Monitoring System Using NodeMCU & Thingspeak
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);
}