Hello my name is Rodrigo I am starting to program using Arduino. I am currently trying to do a single axis solar tracker, as the solar panel is not small I installed two 10 kg cm servo motors on each side of the solar panel, therefore they will have to rotate in opposite directions. I wrote this code which is attached below, but my problem is the code works for little time and 1 minute later the servo motors stop and start to rotate very fast but with a big gap between rotations. Thanks!
Solar_tracking_2ldr.ino (733 Bytes)
What do you see if you print the values of val1 and val2 before testing them ?
Are the values reasonable ?
How are the LDRs wired ?
Why have you not got any tests for the servos reaching their limits of movement ?
This:
if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {
}
else {
if(val1 > val2)
{
pos = --pos;
}
if(val1 < val2)
{
pos = ++pos;
}
}
Is equivalent to:
if (abs(val1 - val2) > tolerance) {
if (val1 > val2) --pos;
else ++pos;
}
You also need to add a check to limit pos from decrementing past 0 and incrementing past 180.
Verify your analog inputs are not bouncing a lot. You might want to average the last few readings.
I am not convinced that they are equivalent, l think that
Pos=++Pos;
Is undefined behavior.
wildbill:
I am not convinced that they are equivalent, l think that
Pos=++Pos;
Is undefined behavior.
Indeed I think you are correct.
Hi,
Welcome to the forum.
Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How are you powering your project?
How are you powering the servos?
Can you please post link to specs/data of the servos.
What model Arduino are you using?
You have to be aware that even when a servo is stationary they can still be consuming current if there is ANY torque on their shafts.
So if the servos are not EXACTLY mirror image of each others positions, you will have a push/pull situation.
DC drive motors and limit switches would have been easier to implement.
Do you have a DMM?
Thanks... Tom...