11-18-2011
Solar Tracker
I built a solar tracker like this one modified to use my Arduino. If you haven't seen any videos by ScienceOnline before, you're in for a real treat! Check out their website too http://hilaroad.com/ for some more great ideas and scientific knowledge.
This was my first real Arduino project and I think it went rather well. I learned a lot but now I really need to get out in the sun to do some real testing. I'd still like to use this to power some other projects and / or add some other features... so many empty pins on that RBBB board.
a few pics
parts & materials
- RBBB board from Moderndivice.com - $13.00
- x2 Monocrystalline Solar Cells ( 37 x 66mm ) from solarbotics.com - $8.25 ea
- x2 Large Servos from - sparkfun.com - $12.95 ea
- 5V voltage regulator
- x4 photocells
- x2 10k Ω resistors
- IN4004 rectifier diode from radioshack ( 276-1103 )
- x4 rechargeable NiMH AA batteries 1,2V 1800mAh
- battery holder
- bread board
- wood
- metal bracket left over from ikea furniture
- wire
schematic
initial code ( get the most recent code on github)
#include <Servo.h>
//create servo objects to control servos
Servo horizontalServo; //bottom - 0 points to x
Servo verticalServo; //top - 75 approx straight up, 180 seems too much, 170 max maybe
int photoresistorHorizontal = 0;
int photoresistorVertical = 1;
int horizontalDegree;
int verticalDegree;
//smoothing
const int numReadings = 10;
int Hreadings[numReadings]; // the readings from the analog input
int Hindex = 0; // the index of the current reading
int Htotal = 0; // the running total
int Haverage = 0; // the average
int Vreadings[numReadings];
int Vindex = 0;
int Vtotal = 0;
int Vaverage = 0;
void setup(){
Serial.begin(9600);
horizontalServo.attach(9); //bottom - horizontal
verticalServo.attach(10); //top - vertical
pinMode(photoresistorHorizontal, INPUT);
pinMode(photoresistorVertical, INPUT);
// initialize all the readings to 0:
for (int thisHReading = 0; thisHReading < numReadings; thisHReading++){
Hreadings[thisHReading] = 0;
}
for (int thisVReading = 0; thisVReading < numReadings; thisVReading++){
Vreadings[thisVReading] = 0;
}
}
void loop(){
horizontalDegree = map(analogRead(photoresistorHorizontal),0,1023,0,179);
horizontalDegree = 179 - horizontalDegree; //have to make opposite since soldering messup
verticalDegree = map(analogRead(photoresistorVertical),0,1023,0,90); // 60 degrees max for vertical servo
//average horizontal
Htotal= Htotal - Hreadings[Hindex];
Hreadings[Hindex] = horizontalDegree;
Htotal= Htotal + Hreadings[Hindex];
Hindex = Hindex + 1;
if (Hindex >= numReadings){
Hindex = 0;
}
//average verticle
Vtotal = Vtotal - Vreadings[Vindex];
Vreadings[Vindex] = verticalDegree;
Vtotal = Vtotal + Vreadings[Vindex];
Vindex = Vindex + 1;
if (Vindex >= numReadings){
Vindex = 0;
}
// calculate the average:
Haverage = Htotal / numReadings;
Vaverage = Vtotal / numReadings;
horizontalServo.write(Haverage);
verticalServo.write(Vaverage);
delay(15);
}
Follow up
Let me know if you have any suggestions or improvements email me

5V
pin D9 = horizontal servo
pin D10 = vertical
pin A0 = horizontal photoresistor (white) 10k resistor in between
pin A1 = vertical photoresistor (blue) 10k resistor in between
*/