Updates: 3
Hey guys. This is my first post on this forum and I am sharing with you guys my arduino solar tracking project. I am building a solar panel that will track the sun and adjust its position accordingly. I plan to use:
4 photo-resistor sensors
2 servo motors (lynx motion pan and tilt) - bought from robotshop
arduino uno and a few other things.
UPDATE:2
Ok, so I have 4 photo resistor sensors hooked up (top, bottom, left and right) and i have them hooked up to my 2 servos (2 each respectively).Basically my code works by finding the highest input from the sensors and the servos will move accordingly. This is so I can balance my servos at roughly the position of the light source.It is working correctly and I am going into a showcase for my school later today.
Update 3:
So I havent changed the code much since my last update but I have been working on plotting the data on graphs so i can more easily troubleshoot a few of the small problems ive been having. Ive attached a picture below of graphs I have made. One issue I am having is that my sensors are not consistent. One is really jumpy and another will display different values each time it is reset. Its kind of annoying but it might be because of how cheap they are. I am thinking of getting some more to see if that is problem. Any way, the software to plot the data is called bridge control panel from Cypress. Seems to work well and was easy enough to install and get working.
Heres a picture of it and the code is below
Let me know what you guys think or if you guys have any suggestions as this is my first arduino project. I will be updating this thread as the project develops
ignore the comments in the code as they may not be correct.
//Leathels code
#include <Servo.h>
Servo topServo; // create servo object to control a servo
Servo bottomServo;
// a maximum of eight servo objects can be created
int lightPinLeft = 1; //define a pin for Photo resistor
int lightPinRight = 4; //define a pin for Photo resistor
int lightPinTop = 5; //define a pin for Photo resistor
int lightPinBottom = 0; //define a pin for Photo resistor
int topPos = 0; // variable to store the servo position
int bottomPos =0;
int reset = 0;
void setup()
{
Serial.begin(9600); //Begin serial communcation
bottomServo.attach(3); // attaches the servo on pin 9 to the servo object
topServo.attach(2);
}
void loop()
{
delay(150);
int LSleft =analogRead(lightPinLeft)-20;
int LSright =analogRead(lightPinRight);
int LStop =analogRead(lightPinTop)-320;
int LSbottom =analogRead(lightPinBottom);
// RX8 [h=43] @1Key1 @0Key1
Serial.print("C");
Serial.write(LStop>>8);
Serial.write(LStop&0xff);
Serial.write(LSbottom>>8);
Serial.write(LSbottom&0xff);
Serial.write(LSright>>8);
Serial.write(LSright&0xff);
Serial.write(LSleft>>8);
Serial.write(LSleft&0xff);
if (LSright < LSleft&& bottomPos <180 && LSleft-LSright >25 && reset ==0) // while right is less than left pos goes down 1
{
bottomPos++;
bottomServo.write(bottomPos);
}
if (LStop < LSbottom&& topPos>100 && LSbottom-LStop >15 && reset ==0) // while right is less than left pos goes down 1
{
topPos--;
topServo.write(topPos);
}
if (LSright > LSleft && bottomPos > 0 && LSright-LSleft >25 && reset ==0) // while right is more than left pos goes up 1
{
bottomPos--;
bottomServo.write(bottomPos);
}
if (LStop > LSbottom && topPos < 170 && LStop-LSbottom >15 && reset ==0) // while right is more than left pos goes up 1
{
topPos++;
topServo.write(topPos);
}
if (LStop-LSbottom <30 || LSbottom-LStop <30 && topPos >170&& reset ==0)
{
topPos--;
topServo.write(topPos);
}
if (LStop-LSbottom <30 || LSbottom-LStop <30 && topPos <170 && reset ==0)
{
topPos++;
topServo.write(topPos);
}
if(topPos >=169 && LStop > LSbottom)
{
reset ==1;
}
if (reset==1 && bottomPos >=10)
{
bottomPos--;
}
if (bottomPos <=10)
{
reset==0;
}
Serial.print ("top=");
Serial.println (LStop);
Serial.print ("bottom=");
Serial.println (LSbottom);
Serial.print ("rightpos=");
Serial.println(LSright);
Serial.print("leftpos=");
Serial.println(LSleft);
}