how to make automatic dual axis solar tracker using arduino

           Homemade dual axis solar tracker



Hello and welcome to the RC Invention projects. In this article, you will learn to make a dual axis solar tracker using Arduino, servo motor and LDR. Ingoing to use some  this poject, we are use some light sensitive sensors like LDR to track the sunlight and direct the solar panel towards the sun that increase its efficiency 

Components required for this projects.

1. Arduino Uno or Nano.

2. servo motor (2nos).

3. LDR (Light Depending Resistor).

4. Resistor ( 1k to 10k ohm ) any one.

5. Solar panel .

6. PVC sheet .


Circuit Diagram


Arduino Code - 01

  #include <Servo.h>


// 180 horizontal MAX

Servo horizontal; // horizontal servo


int servoh = 180; // 90; // stand horizontal servo


int servohLimitHigh = 180;

int servohLimitLow = 65;


// 65 degrees MAX

Servo vertical; // vertical servo


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


int servovLimitHigh = 120;

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


// name.attacht(pin);


horizontal.attach(9);


vertical.attach(10);


horizontal.write(180);


vertical.write(45);


delay(3000);


}


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(avt);


Serial.print(" ");


Serial.print(avd);


Serial.print(" ");


Serial.print(avl);


Serial.print(" ");


Serial.print(avr);


Serial.print(" ");


Serial.print(dtime);


Serial.print(" ");


Serial.print(tol);


Serial.println(" ");


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


{


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)


{


// nothing


}


horizontal.write(servoh);


}


delay(dtime);


}


Arduino Code - 02


int topleft;

int topright;

int downleft;

int downright;

int waittime = 1;


void setup() {

  pinMode(9, OUTPUT);

  pinMode(10, OUTPUT);

  TCCR1A = 0;

  TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);

  TCCR1B = 0;

  TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);

  ICR1 = 40000;

  OCR1A = 3000;

  OCR1B = 3600;

}


void loop() {

  topleft = analogRead(A0);

  topright = analogRead(A1);

  downleft = analogRead(A2);

  downright = analogRead(A3);


  if (topleft > topright) {

    OCR1A = OCR1A + 1;

    delay(waittime);

  }

  if (downleft > downright) {

    OCR1A = OCR1A + 1;

    delay(waittime);

  }

  if (topleft < topright) {

    OCR1A = OCR1A - 1;

    delay(waittime);

  }

  if (downleft < downright) {

    OCR1A = OCR1A - 1;

    delay(waittime);

  }

  if (OCR1A > 4000) {

    OCR1A = 4000;

  }

  if (OCR1A < 2000) {

    OCR1A = 2000;

  }

  if (topleft > downleft) {

    OCR1B = OCR1B - 1;

    delay(waittime);

  }

  if (topright > downright) {

    OCR1B = OCR1B - 1;

    delay(waittime);

  }

  if (topleft < downleft) {

    OCR1B = OCR1B + 1;

    delay(waittime);

  }

  if (topright < downright) {

    OCR1B = OCR1B + 1;

    delay(waittime);

  }

  if (OCR1B > 4200) {

    OCR1B = 4200;

  }

  if (OCR1B < 3000) {

    OCR1B = 3000;

  }

}



Comments

Popular posts from this blog

How to make talking Voltmeter at home

how to make taking distance measurement device using Arduino and ultrasonic sensor

How to make voltmeter using Arduino