DIY SOLAR TRACKER 

How to Make it :- full video in hindi click here

CODE:- 

#include <Servo.h>

int ur=A0;

int uf=A1;

int dr=A2;

int df=A3;

int vur;

int vuf;

int vdr;

int vdf;

int au;

int af;

int ad;

int ar;

int servoh;

int servov;

Servo hz;

Servo vt;

void setup() {

  // put your setup code here, to run once:

pinMode(ur,INPUT);

pinMode(uf,INPUT);

pinMode(dr,INPUT);

pinMode(df,INPUT);

hz.attach(9);

vt.attach(10);

Serial.begin(9600);

}


void loop() {

  // put your main code here, to run repeatedly:

vur=analogRead(ur);

vuf=analogRead(uf);

vdr=analogRead(dr);

vdf=analogRead(df);

au=(vur + vuf) / 2;

ad=(vdr + vdf) / 2;

ar=(vdr + vur) / 2;

af=(vdf + vuf) / 2;

if (au>ad) {

  servov=++servov;

 if (servov>130) {

  servov=130; 

}else if (au<ad) {

  servov=--servov;

  if (servov<3) {

    servov=3;

  }

}

vt.write(servov);

if (ar>af) {

  servoh=++servoh;

  if (servoh>170) {

    servoh=170;

  }

}else if (ar<af) {

  servoh=--servoh;

  if (servoh<3) {

    servoh=3;

  }

}

hz.write(servoh);

Serial.println(servoh);

Serial.println(servov);

delay(50);

}