A Simple Solar Follower That Has Dual Axes: 13 Steps (with Pictures)

Upload the code here to the Arduino.

you can modify the code to change the sensitivity of the sensors and the speed of the servos

#include // include Servo library

// 180 horizontal MAX Servo horizontal; // horizontal servo

int servo = 180; // 90; // servo horizontal booth

int servohLimitHigh = 180; int servohLimitLow = 65;

// 65 degrees MAX Vertical Servo; // vertical servo

int servov = 45; // 90; // stand servo vertical

int servovLimitHigh = 80; int servovLimitLow = 15;

// LDR pin connections // name = analogpin;

int ldrlt = 0; // LDR top left - BOTTOM LEFT <- BDG

int ldrrt = 1; // LDR top rigt - BOTTOM RIGHT

int ldrld = 2; // LDR down left - TOP LEFT

int ldrrd = 3; // ldr down rigt - TOP RIGHT

void setup () {Serial.begin (9600);

// servo connections

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 = analogRead (4) / 20; // read potentiometers

// int tol = analogRead (5) / 4;

int dtime = 10; int tol = 50;

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

Serial.print ("");

Serial.print ("");

if (-1 * tol> dvert || dvert> tol) // check if the diffirence is in the tolerance else change vertical angle )

servov = ++ servov;

if (servov> servovLimitHigh)

servov = servovLimitHigh;

else if (avt

if (servov

servov = servovLimitLow;

if (avl & gt; avr)

servoh = -servoh;

if (servoh

servoh = servohLimitLow;

else if (avl

servoh = ++ servoh;

if (servoh> servohLimitHigh)

Related news