DemetrisEng
Published © GPL3+

Solar Tracker 35W with DC Motors

Solar tracking photovoltaic (dual axis) that follows the sun, using LDR sensors and two DC motors.

IntermediateShowcase (no instructions)37,106
Solar Tracker 35W with DC Motors

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
It's used to control the two motors
×1
LDR, 1 Mohm
LDR, 1 Mohm
×4
Resistor 10k ohm
Resistor 10k ohm
×6
Resistor 1k ohm
Resistor 1k ohm
×4
Industrial Pushbutton Switch, Push-Pull
Industrial Pushbutton Switch, Push-Pull
×4
Slide Switch
Slide Switch
×2
Geared DC Motor, 12 V
Geared DC Motor, 12 V
×2
SparkFun Solder-able Breadboard
SparkFun Solder-able Breadboard
×2
Photovoltaic 35W
×1
LM2596
This component is used to regulate the voltage. Because voltage from pv can exceed 12V, LM2598 gives output voltage 12V.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Circuit

You can use 1 breadboard instead of two. I just put second breadboard for the 4 LDRs above the Photovoltaic which is far from the first breadboard.

Download this schematic for more clear vision of Arduino pins

Circuit

LM2596 and L298 shown in the picture

Download the other schematic for more clear vision of Arduino pins

Code

Solar Tracker

Arduino
Arduino Code. NOTE: The names of the ldrs in the code do not correspond with their place in the breadboard!
/* Solar Tracker Code with 4 buttons for manual orientation and
  4 ldr sensors to automaticaly traking the sun.

*/
//set constant pin numbers
int wbuttonPin = 4;
int ebuttonPin = 2;
int tbuttonPin = 8;
int bbuttonPin = 12;
int switch1Pin = 7;
int switch2Pin = 5;
int eldr = A0;
int wldr = A1;
int tldr = A2;
int bldr = A3;
int IN1 = 13;
int IN2 = 9;
int IN3 = 10;
int IN4 = 11;
int eastldr = 0;
int westldr = 0;
int topldr = 0;
int botldr = 0;
int error = 0;
int poserror = 0;
int tberror = 0;
int tbposerror = 0;
int westbutton = 0;
int eastbutton = 0;
int topbutton = 0;
int botbutton = 0;
int onoffswitch = 0;
int singledualswitch = 0;
void setup() {
  pinMode (A0, INPUT);
  pinMode (A1, INPUT);
  pinMode (A3, INPUT);
  pinMode (A4, INPUT);
  pinMode (8, INPUT_PULLUP);
  pinMode (12, INPUT_PULLUP);
  pinMode (13, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  pinMode (11, OUTPUT);
  pinMode (4, INPUT_PULLUP);
  pinMode (2, INPUT_PULLUP);
  pinMode (5, INPUT_PULLUP);
  pinMode (7, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {Serial.print("start programm");
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  onoffswitch = digitalRead(switch1Pin);
  singledualswitch = digitalRead(switch2Pin);
  while  (onoffswitch == LOW  ) {
    //manual rotating of the panel

    eastldr = analogRead(A0);
          westldr = analogRead(A1);
          topldr = analogRead(A2);
         botldr = analogRead(A3);
    
    eastbutton = digitalRead(ebuttonPin);
                 if (eastbutton == HIGH)
  { digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    } // rotate to east side when you push the right button
    else {
      digitalWrite(IN1, LOW);
    }
    westbutton = digitalRead(wbuttonPin);
                 if (westbutton == HIGH)
  { digitalWrite(IN2, HIGH);
    } //rotate to west side when you push the left button
    else {
      digitalWrite(IN2, LOW);
    }
    topbutton = digitalRead(tbuttonPin);
                if (topbutton == HIGH)
  { digitalWrite(IN4, HIGH);
    } //rotate to west side when you push the left button
    else {
      digitalWrite(IN4, LOW);
    }
    
    botbutton = digitalRead(bbuttonPin);
              if (botbutton == HIGH)
{ digitalWrite(IN3, HIGH);
  } //rotate to west side when you push the left button
  else {
    digitalWrite(IN3, LOW);
  } onoffswitch = digitalRead(switch1Pin);
    singledualswitch = digitalRead(switch2Pin);
    Serial.println(eastldr);
Serial.println(westldr);
Serial.println(topldr);
Serial.println(botldr);
}
   
//automaticaly rotating of the panel
//check east-west orientation first


                                      /* if (eastldr < 400 && westldr < 400)
                                         {digitalWrite(IN1,HIGH)
                                         delay(7500)
                                         digitalWrite(IN1,LOW)}*/
onoffswitch = digitalRead(switch1Pin);
singledualswitch = digitalRead(switch2Pin);
while  (onoffswitch == HIGH && singledualswitch == LOW ){
  eastldr = analogRead(A0);
          westldr = analogRead(A1);
          topldr = analogRead(A2);
         botldr = analogRead(A3);
                    error = (((eastldr+topldr)/2) - ((westldr+botldr)/2));
                            poserror = abs(error);
                                     if (poserror > 10){
 if (error > 0) {
   digitalWrite(IN2, HIGH);

//  Serial.print("IN2 HIGH");
  }
  else if (error < 0)    {
   digitalWrite(IN1, HIGH);
//Serial.print("IN1 HIGH");
  }}
  else if (poserror <= 10 )  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
//Serial.print("LOW BOTH");
    }

Serial.println(eastldr);
Serial.println(westldr);
Serial.println(topldr);
Serial.println(botldr);

onoffswitch = digitalRead(switch1Pin);
singledualswitch = digitalRead(switch2Pin);}

onoffswitch = digitalRead(switch1Pin);
singledualswitch = digitalRead(switch2Pin);



  while  (onoffswitch == HIGH & singledualswitch == HIGH ){
         topldr = analogRead(A2);
         botldr = analogRead(A3);
         eastldr = analogRead(A0);
         westldr = analogRead(A1);
                 
                  
                  tberror = (((topldr+westldr)/2) - ((botldr+eastldr)/2));
                            tbposerror = abs(tberror);
    
 
                   error = (((eastldr+topldr)/2) - ((westldr+botldr)/2));
                            poserror = abs(error);
                                     if (poserror > 10){
 if (error > 0) {
   digitalWrite(IN2, HIGH);

//  Serial.print("IN2 HIGH");
  }
  else if (error < 0)    {
   digitalWrite(IN1, HIGH);

//Serial.print("IN1 HIGH");
  }}
  else if (poserror <= 10 )  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    }

Serial.println(eastldr);
Serial.println(westldr);
   if (tbposerror > 10)
{ if (tberror > 0) {
    digitalWrite(IN4, HIGH);

}    else if (tberror < 0)    {
      digitalWrite(IN3, HIGH);

    }
  }
  else if (poserror <= 10 )  {
    digitalWrite(IN4, LOW);
    digitalWrite(IN3, LOW);
  }
  onoffswitch = digitalRead(switch1Pin);
singledualswitch = digitalRead(switch2Pin);}
onoffswitch = digitalRead(switch1Pin);
singledualswitch = digitalRead(switch2Pin);
  delay(200);

}

Credits

DemetrisEng

DemetrisEng

1 project • 14 followers

Comments