Arduino 2 Axis Servo Solar Tracker
Arduino 2 Axis Servo Solar Tracker
Living
Outside
Play
Technology
Workshop
Table of Contents
Arduino 2-axis servo solar tracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Step 4: Wiring it up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
Image Notes
1. Arduino Uno
2. breadboard
3. x-axis servo
4. y-axis servo
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
Image Notes
1. drill hole for the servo output shaft to fit in. Then glue it
2. cut off the plastic holding this side of the mirror
3. ziptie + hot glue
Image Notes
1. draw an "X" from here
2. to here
3. and here
4. to here, to find the center
5. hot glue
Image Notes
1. hole goes here
2. setscrew goes here
3. rough up the surface of the plastic so the hot glue sticks better
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
Image Notes
1. sensor
2. sensor
3. sensor
4. insulate the wires and more hot glue
5. ribbon cable wires
Image Notes
1. 5V
2. 5V
3. input 1
4. input 2
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
Image Notes
1. this side goes against the back of the mirror
Image Notes
1. not what I'm using but the closest pic I found. My sensor has 4 leads all parallel
to each other.
Step 4: Wiring it up
Take a look at the pics for the wiring diagram and schematic. (sorry about the confusing scheamtic, still learning Fritzing)
***EDIT (04/03/13)*** Changed the images to reflect the proper wiring and cleaned it up a bit.
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
int tilth;
void setup () {
vservo.attach(9); // attaches the servo on pin 9 to the servo object
hservo.attach(10); // attaches the servo on pin 10 to the servo object
divisor = 10; // this controls the speed of the servo. lower number = higher speed
sensitivity = 5; // this controls the sensitivity of the tracker. lower number = higher sensitivity. if your tracker is constantly jittering back and forth increase the number
Serial.begin(19200); // open serial com
Serial.print("SolarTracker ready!");
pinMode(BOTTOM, INPUT); // set the inputs
pinMode(TOPLEFT, INPUT);
pinMode(TOPRIGHT, INPUT);
pinMode(TILTL, INPUT);
pinMode(TILTH, INPUT);
}
void loop () {
tiltl = digitalRead(TILTL); // read the tilt sensor
tilth = digitalRead(TILTH);
tlsense = analogRead(TOPLEFT); // read the light sensors
trsense = analogRead(TOPRIGHT);
bsense = analogRead(BOTTOM);
//bsense = bsense * 1.05; // I had to adjust the value of this sensor to make it more accurate. you might have to do the same but start by leaving it alone
tavg = (tlsense + trsense)/2; // get an average value for the top 2 sensors
diff = abs(tavg - bsense); // this judges how far the tracker must turn
spd = diff/divisor; // and adjusts the speed of the reaction accordingly
spd = max(spd, 1); // sets the minimum speed to 1
Serial.print("\nTOP: "); Serial.print(tavg, DEC); // print the sensor values to the serial com
Serial.print("\tBOTTOM:"); Serial.print(bsense, DEC);
Serial.print("\tLEFT:"); Serial.print(tlsense, DEC);
Serial.print("\tRIGHT:"); Serial.print(trsense, DEC);
if((tavg < bsense) & (diff > sensitivity) && (tiltl == LOW) && (tilth == LOW)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor and the
tilt sensor is in the correct range
vservo.write(90 - spd); // send servo command to turn upward plus add speed
Serial.print("\tState: "); Serial.print("UP!");
}else if((tavg < bsense) & (diff > sensitivity) && (tiltl == HIGH) && (tilth == LOW)){ // if the average value of the top sensors is smaller (more light) than the bottom sensor
and the tilt sensor is in the correct range
vservo.write(90 - spd); // send servo command to turn upward plus add speed
Serial.print("\tState: "); Serial.print("UP!");
}else if((tavg > bsense) & (diff > sensitivity) && (tiltl == HIGH) && (tilth == LOW)){ // if the value of the bottom sensor is smaller (more light) than the average value of the
top sensors and the tilt sensor is in the correct range
vservo.write(90 + spd); // send servo command to turn downward plus add speed
Serial.print("\tState: "); Serial.print("DOWN!");
}else if((tavg > bsense) & (diff > sensitivity) && (tiltl == LOW) && (tilth == HIGH)){ // if the value of the bottom sensor is smaller (more light) than the average value of the
top sensors and the tilt sensor is in the correct range
vservo.write(90 + spd); // send servo command to turn downward plus add speed
Serial.print("\tState: "); Serial.print("DOWN!");
}else{ // for every other instance
vservo.write(90); // stop the y-axis motor
Serial.print("\tState: "); Serial.print("STOP!");
}
tlsense = analogRead(TOPLEFT); // read the top 2 sensors again because they have probably changed
trsense = analogRead(TOPRIGHT);
//trsense = trsense * 1.03; // again I had to adjust the value of one sensor to make the tracker more accurate
diff = abs(tlsense - trsense); // reset the diff variable for the new values
spd = diff/divisor; // and generate a speed accordingly
spd = max(spd, 1); // set the minimum speed to 1
if((tlsense < trsense) & (diff > sensitivity)){ // if the top left sensor value is smaller (more light) than the top right sensor
hservo.write(90 + spd); // send servo command to turn left
Serial.print("\tState: "); Serial.print("LEFT!");
}else if((tlsense > trsense) & (diff > sensitivity)){ // if the top left sensor value is larger (less light) than the top right sensor
hservo.write(90 - spd); // send servo command to turn right
Serial.print("\tState: "); Serial.print("RIGHT!");
}else{ // for every other instance
hservo.write(90); // stop the x-axis motor
Serial.print("\tState: "); Serial.print("STOP!");
}
delay(10); // delay 10ms
}
Arduino polls the sensors and reacts accordingly making sure never to tilt too far down or up. The difference in light determines how fast the tracker should react.
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
Related Instructables
Clock Based
solar tracker
experiment
(video) by
gaiatechnician
servo based
dual axis solar
tracker (video)
by
Jestin_Cubetech
solar tracker by
aiwa19
A Strong Simple
Sun Tracker by
Mud Stuffin
DIY Solar
Tracker by
pdaniel7
Advertisements
Comments
30 comments Add Comment
jaykentchriss says:
jaykentchriss says:
robinmitchell says:
jaykentchriss says:
McAldo says:
That's a wonderful way to approach the problem, thanks for sharing it.
dpmdmph says:
Did you have to calibrate ur continuous servos first, before putting them in ur project?
DaBlakus says:
aplavins says:
robinmitchell says:
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
aplavins says:
aplavins says:
aplavins says:
aplavins says:
I updated the diagrams on the instructable. They are both the same, just different views.
If I need to adjust the potentiometer in the servo meter, how would i do that?
Also, is the arduino code correct. Do i just copy and paste it. then upload it to the arduino board?
robinmitchell says:
aplavins says:
maewert says:
Adam,
Cool project! Great for an all-purpose tracker. For a specific purpose (solar) tracker you may wish to consider using a polar mount instead of an alt-az
mount. This will mean that only one motor would move to track the sun throughout the day. Since the position of the sun is predictable, you could compute
its position and not rely on sensors. (This might mean that you might need to change to steppers instead of servos and power off the motors when they don't
need to move maybe using a worm gear drive which holds its position after the motors are unpowered.)
Your solution could generate some electricity even from moonlight since it would track the brightest object and not necessarily only Mr. Sun however! You
might need an algorithm to determine if it is worth the electricity spent in the motors to eek out the most current (I'd hate to see a bank of solar cells track the
headlights from a passing car at night!) Actually I WOULD like to see that! It would make me back up a few times!
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
aplavins says:
gtoal says:
Graver says:
aplavins says:
Graver says:
aplavins says:
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/
http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/