Mayur Rabadiya
Published © LGPL

Sun Tracking Solar System

This system is to get 100% sun energy. In this system solar panel will move in the direction of sun from sun rise to sun set.

IntermediateFull instructions provided1 hour28,211
Sun Tracking Solar System

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Analog Devices LDR Sensor
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
solar panel
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×4

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Sun tracking solar system

Code

Sun tracking solar system

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

Credits

Mayur Rabadiya

Mayur Rabadiya

5 projects • 27 followers

Comments