I am trying to build a sun tracking system as quick as possible.
I am using this system, one 180 deg servo and for the bottom one continous servo.
I am also using 4 phototransistors sensors that are connected to 0 to 3 analog input.
My idea is that to messaure each second (or less) the input from the 4 phototransistors and compare them to each other.
their input should be the same when they face the sun.
I want to measure the x and y axis and then move the servos corospanding.
I have tried a few codes I found on-line, but since I'm a begginer, I will appreciate any help with building this code (I need to build this unit asap since it only for demostrating a rapid idea).
their input should be the same when they face the sun.
Yeah, they should, but they probably won't be - or they will be close to "the same" when they aren't facing the sun, due to reflections or diffusion effects...
What you should do it arrange the detectors in a 4-square arrangement, then put a cross-shaped "shadow baffle" between them (or four black tubes, with the detectors at the bottom) that extends out from them a few inches/cm, like so (bad ASCII art ahead!):
D | D
--+-- "D" = detector
D | D
You would also do well to see what others have done before to get ideas on how to implement things (hint: you don't even need electronics or motors to track the sun - it can and has been done by heat alone working on expanding fluid driving hydraulic-style mechanisms!).
Solar tracking mechanisms are older than dirt; for the application of power generation, you are still looking at close to 300 years of experimentation (yes, solar energy applications are that old). Modern systems using electronics and motors to track the sun date back a long time as well, but most of what you will find useful will go back only to the 1970s or so. Look up the "Mother Earth News" archive for many articles on the subject...
Thank you for your reply.
I had placed the sensors in like a compass:
N
W E
S
the idea is that when (for example) 'W' sensors gets less light then 'E' sensor, the bottom servo will move towards 'W' position (this is actually the continues servo).
The same with 'N' and 'S' sensors, but with 180 deg servo.
I will appreciate a quick example of code, so I will be able to get things started..
#include <Servo.h>
Servo myservo;
int pos = 100; // Variable to store the servo position.
int inputPhotoLeft = 1; // Easier to read, instead of just 1 or 0.
int inputPhotoRight = 0;
int Left = 0; // Store readings from the photoresistors.
int Right = 0; // Store readings from the photoresistors.
void setup()
{
myservo.attach(9); // Attach servo to pin 9.
}
void loop()
{
// Reads the values from the photoresistors to the Left and Right variables.
Right = analogRead(inputPhotoLeft);
Left = analogRead(inputPhotoRight);
// Checks if right is greater than left, if so move to right.
if (Left > (Right +10))
{
if (pos > 22)
{
pos -= 1;
myservo.write(pos);
}
}
if (Right > (Left +10))
{
if (pos > 5)
{
pos += 1;
myservo.write(pos);
}
}
delay(20);
}
So far so good, problem is I want to use continues servo (instead of 180 degrees one).
What do I need to change in the code in order to work with a continues servo?
(update): I had wrote a code -->
#include <Servo.h>
Servo myservo;
int pos = 100; // Variable to store the servo position.
int inputPhotoLeft = 1; // Easier to read, instead of just 1 or 0.
int inputPhotoRight = 0;
int Left = 0; // Store readings from the photoresistors.
int Right = 0; // Store readings from the photoresistors.
void setup()
{
myservo.attach(9); // Attach servo to pin 9.
}
void loop()
{
// Reads the values from the photoresistors to the Left and Right variables.
Right = analogRead(inputPhotoLeft);
Left = analogRead(inputPhotoRight);
// Checks if right is greater than left, if so move to right.
if (Left > (Right +2))
{
pos = 101;
myservo.write(pos);
}
if (Right > (Left +2))
{
pos = 99;
myservo.write(pos);
}
delay(500);
}
for my continues servo. when the servo gets '100' signal, it stops. i managed to use the servo, but the problem is it's never stops.. just vibrating from side to side (tried to play with the delay, but I think it's something else).
What do I need to change in the code in order to work with a continues servo?
I am not even sure why you need a continuous rotation servo...? You might need a servo that moves more than 180 degrees (which do exist), but not a continous servo.
To use a continuous servo, since the potentiometer in it is effectively "disconnected", you will need to provide your own feedback mechanism for position; an external potentiometer connected to the platform as it rotates, with the wiper connected to an analog input, would work OK.
I think you would be able to work it out from there.
Regarding the orientation of the sensors; your right to orient them the way you did (that's the way it is done, but I had forgotten to mention that - good job) - you still might want to set up the shadow baffle, though.
Also - remember to add a routine to move the pan/tilt platform back to the east for the next morning; you will also need to account for cloud cover (so it doesn't try to hunt for the sun on an extremely cloudy day). Not sure what to do with a very overcast day...
Hi.
Regarding the contentious servo. I actually using it inside a building to track a flash-light. so, I do need a continuous servo for it to move to all directions.
with the code (I uploaded), I managed to move the servo pretty well, the only problem was that it never stopped (bit shaky).