Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

Arduino Projects

Hello and Welcome to The IoT Projects. In this article, you will learn to make a Dual Axis Solar Tracker Arduino Project Using LDR and Servo Motors in Step by Step manner. In this project, we are going to use some Light Sensitive Sensors like (LDR) to track the sunlight and direct the solar panels towards the areas that Increase its efficiency. I have divided the article into 7 segments as:

Components required for this project

The following list is the list of all the components that are required for this project:

  • 1 x Mini Breadboard
  • 1 x Arduino UNO
  • 2 x Micro Servo – SG90
  • 4 x LDR ( Photoresistor) Sensor
  • 4 x 10k-ohm resistors
  • 2 x 10k Potentiometer
  • 3D body parts Design ( Download from here)

Our Popular Arduino Based Projects:

Interfacing Temperature and Humidity Sensor with Arduino

DIY Mobile Phone using GSM Module & Arduino with Nextion Display

Simple Weather station using Arduino & BME280 Barometric Pressure Sensor

RFID Based Attendance System Using NodeMCU with PHP Web App

Capacitive Soil Moisture Sensor with OLED Display & Arduino

Working Principle of LDR Sensor

Here, LDR Works as a light detector. It is also known as a photoresistor. Actually, It is a light Sensitive device. As shown in the graph, the resistance decreases as light falls on it. In this project, we are using 4 LDRs to detect the Sunlight. And when they send Signal to the Arduino, It will guide two Servo Motors to better place the solar panel to maximize its efficiency.

Interface LDR Photo Resistor to Arduino and Control LEDs
Working Process of LDR

Project Simulation

Here, we will show you a complete overview of this project. Later on, we will discuss its wiring system. But, now we will stimulate this project.

Project Simulation

When we power on the Arduino all the sensors and servo motors are into the actions. As you can see the above image. Usually, when we increase the light intensity on the LDR Sensor, the signal is sent to the Arduino. And Hence it guides the two servo motors to better place the solar panel. To increase its efficiency. Actually, you can see here as we increase or decrease the light intensity the Servo Motors are into their actions.

Using these two potentiometers you can control the speed of Servo Motors as well. We will talk about it later in the programming section.

Tinkercad Dual Axis Solar Tracker Arduino Simulation file

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

Interfacing Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors
Interfacing Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors
  • Connect 5volt pin from the Arduino to the Lower horizontal row of the breadboard.
  • Similarly, connect the GND pin from the Arduino to a second lower horizontal row of the breadboard.
  • Extend the 5 volt and GND Rows to the upper horizontal rows of the breadboard respectively.
  • Now connect the power pins of both Vertical and Horizontal servo motor to the 5 volts.
  • Similarly, Connect the GND pin of the Both Horizontal and Vertical Servo motor to the Ground.
  • Now, connect the Signal pin of the Vertical Servo Motor to the Digital Pin No. 10 of the Arduino.
  • Again, connect the Signal pin of the horizontal Servo Motor to the Digital Pin No. 9 of the Arduino.
  • Connect one terminal of both potentiometers to the Ground and Other end terminals of both potentiometer to the VCC 5 volt.
  • Now, connect all LDRs one terminal to the 5 volt and other terminals to the Ground Through 10k-ohm resistors.
  • Let’s connect the wiper pin of the potentiometer-1 one to the Analog Pin A4 and A5 to another wiper pin of Potentiometer-2.
  • Connect bottom left LDR voltage Divider point to A1 pin of Arduino.
  • Again, Connect Top Left LDR voltage Divider Point to A0 pin of the Arduino.
  • Similarly, Top Right LDR Voltage Divider Point to the A2 pin.
  • Finally, Connect the Bottom Right Voltage Divider Point of LDR to the A3 pin of the Arduino.

Programming Arduino for Dual Axis Solar Tracker Project

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

#include <Servo.h> 

Configuration for Horizontal servo.
The Servo Horizontal is set to 180 degrees.
Servo Horizontal Limit When Signal is High is set to 175 degrees.
Again, Servo Horizontal Limit when Signal value is low is set to 5 degrees.

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

This is the Servo Configuration for Vertical
The Servo Vertical is set to 45 degrees.
Servo Vertical Limit When Signal is High is set to 60 degrees.
Also, Servo Vertical Limit when Signal value is low is set to 1 degree.

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

LDR Pin Connections
ldrlt is for Top Left
ldrrt is for Top Right
ldrld is for Down Left
ldrrd is for Down Right

// 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

On void setup, we have attached the vertical and Horizontal servo signal pin. and the servo rotation for the horizontal is set to 180 degrees. and similarly, the vertical servo is set to 45 degrees. we have also set a delay of 2.5 seconds.

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

In the Void loop() Function, we read the value for the analog pin of the Arduino connected to LDRs. and then calculate the average of vertical and horizontal.

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 and IF-ELSE statements are defined to loop the program and calculate the average values of the respective LDR’s. Finally, this code helps to change the degree of the servo motor. So that it can be more effective.

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


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);
 
}

Connecting all the parts together

Connecting all the printed parts together

Video Tutorials

Conclusion

Finally, we have completed Interfacing Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors. Now, you can use this Project to track the solar panel and increase its efficiency by 40%. We hope you found this project useful! Drop a comment below if you have any doubts or queries. We’ll do our best to answer your questions.

Alsan Parajuli

I am a WordPress enthusiast, a hardworking and highly positive person. I always believes in practicality rather than theoretical knowledge. With my curiosity and fast learning skills, I managed to learn everything on my own. I love coding, editing, writing and rummaging around Internet. I am passionate about IoT Projects, Digital marketing, website designing, and reviewing. Moreover, I had been contributing to WordPress Biratnagar as an active member since 2018.

https://theiotprojects.com/

1 thought on “Dual Axis Solar Tracker Arduino Project Using LDR & Servo Motors

Leave a Reply