May be someone has experience the same thing to me when
trying to 'program' servo motor with Arduino. The problems are, servo motor get
vibrating/shaking after we gave the order to go to a certain angle, and the
second issue, the servo motor drifts when the program runs the first time (booting).
Maybe the problem is trivial to those who already an expert, but it may also be
very useful for those who are frantically looking for a solution :)
Servo Motor Problem and Solution
Okay, maybe I wrote out a solution to the second problem
first, the easy one :).
Servo motor moves itself shortly after the program runs. After I troubleshoot, the
root cause of this problem is function attach
(); of servo.h library declaration. So for those of you who put this function
block void setup (); try removed
first, then re-upload the sketch. Problem solved :). Simple but bullseye :). You can declare this
function shortly before telling the servo motor to a certain angle with the
command (e.g) myservo.write (90);.
Second problem, the servo motor vibrating or shaking after
we finished telling it towards a certain angle (after myservo.write(); command ). First, we must analysis the root cause.
As we know, a servo motor only knows 'angle' parameter in its life cycle. Once it
was given orders to go to a certain angle, it will forever be towards the
corner even though it was in destination angle. This is why the servo motor
will vibrates/shakes if it has been settled in the destination angle. Servo
motor will continuously toward the angle, so the effect of servo motor will
vibrate/shake.
Motor Servo Vibrating/Shaking Solutions
What's the solution? It turned out to easily technique. Just
call function detach(); after you
ordered toward a certain angle then servo motor will stop from vibrating/shaking.
So if we ordered a servo motor to a certain angle we should write a complete
code as follows:
#include <Servo.h>;
Servo Myservo;
void setup () {
}
void loop () {
Myservo.attach (9);
Myservo.write (90);
delay (1000);
Myservo.detach ();
delay (1000);
Myservo.attach (9);
Myservo.write (0);
delay (1000);
Myservo.detach ();
delay (1000);
delay (1000);
}
With the sketch above, you will attach servo motors on pin 9,
toward the corner 900,stops shortly (1 second) to wait for the servo
motor rotates to angle 900 and detach it, so it won’t to vibrate/shake.
Alternately, the servo motor will rotate to the angle 00 in a few
next scripts. In order to know the difference, please try to remove Myservo.detach (); command, and compare the results
when there is same command.
This is end of my brief tutorial, may be useful for who is
looking for, or at least to note myself so do not forget later.
ConversionConversion EmoticonEmoticon