arduino SOLAR TRACKER Photoresistors and Servo

Hello world! Today i build a arduino SOLAR TRACKER with a mini solar panel a servo and 2 Photoresistors.

Schematic:
arduino SOLAR TRACKER
Simply wire it up like the schematic and it should work.

You need to play with the photoresistors a bit to get the arduino SOLAR TRACKER to work. If you take a look at the video you see how i created a small wall between the 2 Photoresistors, to make it work properly. Good luck!

Parts list:
Arduino uno, I used the robotdyn uno.
2x photoresistor.
1x servo.
2x 10 k Resistor
Jumper wire set MM/FF/MF.

Code:

#include <Servo.h> 
 
Servo myservo; 
int pos = 90;   // initial position
int sens1 = A1; // photoresistor 1 pin
int sens2 = A0; //photoresistor 2 pin
int tolerance = 2;
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pinMode(sens1, INPUT);
  pinMode(sens2, INPUT);
  myservo.write(pos);
  delay(2000); // a 2 seconds delay while we position the solar panel
}  
 
void loop() 
{ 
  int val1 = analogRead(sens1); // read the value of sensor 1
  int val2 = analogRead(sens2); // read the value of sensor 2
 
  if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
    //do nothing if the difference between values is within the tolerance limit
  } else {    
    if(val1 > val2)
    {
      pos = --pos;
    }
    if(val1 < val2) 
    {
      pos = ++pos;
    }
  }
 
  if(pos > 170) { pos = 170; } // reset to 180 if it goes higher
  if(pos < 0) { pos = 0; } // reset to 0 if it goes lower
  
  myservo.write(pos); // write the position to servo
  delay(50);
}

What is a photoresistor?
A photoresistor (or light-dependent resistor, LDR, or photocell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.
read more

Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

2 thoughts on “arduino SOLAR TRACKER Photoresistors and Servo”

Leave a Reply

Your email address will not be published. Required fields are marked *