DIY Sun‑Tracking Solar Power System with Arduino UNO
Components and supplies
Arduino UNO
×
1
Analog Devices LDR Sensor
×
1
Solderless Breadboard Full Size
×
1
solar panel
×
1
SG90 Micro-servo motor
×
2
Jumper wires (generic)
×
1
Resistor 1k ohm
×
4
Apps and online services
Arduino IDE
About this project
It seems you can'twalk down the street these days without coming across a solar panel. You canfind them for mobile charging in rural areas, as well as simple little sidewalkpath lights. Solar is easy to use, readily available, and inexpensive.
Every panel you seein your day to day life is in a fixed position. While this approach isextremely simple and meets the needs of most small applications, it isn'tproducing as much energy as it could be.
Our tracker isa dual axis tracker, meaningit tracks in both X and Y. To put it into even more simple terms, it goes left, right, up, and down. This means once you have your tracker set up you willnever need to change or adjust anything, since anywhere the sun moves yourtracker will follow.
Code
Sun tracking solar system
Sun tracking solar systemArduino
This is code for suntracking solar system.
/*
* Author: Mayur Rabadiya
* Email: mayurrabadiya994@gmail.com
* Code: Sun tracking solar system
*/
#include<Servo.h> // library for servo motor
Servo s; // define Vertival servo
Servo sh; // define horizontal servo
int start1 = 90; // initially starting from 90 degree
int start2 = 90;
int L1 = A0; //for read data from LDR1
int L2 = A1; //for read data from LDR2
int L3 = A2; //for read data from LDR3
int L4 = A3; //for read data from LDR4
int a = 15;
void setup()
{
s.attach(9); //connect vertical servo to pin 9 of arduino
sh.attach(10); //connect horizontal servo to pin 10 of arduino
pinMode(L1, INPUT); //define LDR as input
pinMode(L2, INPUT);
pinMode(L3, INPUT);
pinMode(L4, INPUT);
s.write(start1); //it will start servo from 90 when we reset system
sh.write(start2);
delay(2000);
}
void loop()
{
int LDR1 = analogRead(L1); //read value from LDR
int LDR2 = analogRead(L2);
int LDR3 = analogRead(L3);
int LDR4 = analogRead(L4);
int plus14 =(LDR1+LDR4); //average of two corner LDR
int plus23 =(LDR2+LDR3);
int plus12 =(LDR1+LDR2);
int plus34 =(LDR3+LDR4);
int diff1= abs(plus14 - plus23); // difference to take proper value
int diff2= abs(plus23 - plus14);
int diff3= abs(plus12 - plus34);
int diff4= abs(plus34 - plus12);
if((diff1 <= a) || (diff2 <= a))
{
//difference is less then 15 so do nothing
}
else
{
if(plus14 > plus23) //move vertical servo in lessthen 90 degree
{
start2= --start2;
}
if(plus14 < plus23)
{
start2 = ++start2; //move vertical servo in greaterthen 90 degree
}
}
if(plus12 > plus34 )
{
start1= --start1; // move horizontal servo in lessthen 90 degree
}
if(plus12 < plus34)
{
start1= ++start1; //move horizontal servo in greaterthen 90 degree
}
s.write(start1);
sh.write(start2);
delay(100);
}