I bought my Servo motors from InMotion who imported them from SparkFun.
It's easy to control a Servo with Arduino using the libraries distributed with the Arduino IDE, but with only three wires, how is that controlled?
A servo motor expects a PWM signal with a very specific period and duty time.
Usually a 20ms period and a 1ms to 2ms as duty time.
On a regular servo the minimal duty cycle means a 0º position, the maximum corresponds to 180º and half way equals 90º.
On a full rotation servo, each period to motor rotates acording to the duty cycle.
Under 1,5ms rotates counter-clockwise and above 1,5ms rotates clockwise.
Controlling a servo from Arduino:
To test the theoretical knowledge I tried to run this simple sketch:
void setup() {
// put your setup code here, to run once:
pinMode(9, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(9, HIGH);
delay(2);
digitalWrite(9, LOW);
delay(18);
}
Worked fine!
But for the best control, why not use a tested and proven library?
So I used Arduino's IDE Sweep example that rotates the Servo from side to side (0 to 180 degrees and back) using a class designed for that purpose.
The Sweep example seems simple and self-explanatory for me to give more detail about it.
In my full rotation servo I noticed that it rotated more going counter-clockwise than when moving clockwise.
I don't know why does it happen...
No comments:
Post a Comment