Hardware Reference
In-Depth Information
A servo motor is a motor assembly with additional sensors and logic. In short,
an embedded microcontroller reads the angle of the output shaft, and controls
a small motor.
Controlling Servo Motors
Most motors require only two wires: one for the power and one for the ground.
Stepper motors are slightly different, having several wires to move a motor by
a specii c number of degrees, but still have no embedded intelligence. (Stepper
motors are explained in Chapter 15.) Servo motors are different; most require
three wires. One wire is for power, one is for the ground connection, and the
third one is for sending orders to the servo motor.
Servo motors use pulse width modulation (PWM) to receive instructions. Pulse
width modulation uses short and precise pulses of digital signals to transmit
information. PWM was i rst presented in Chapter 4.
A servo expects a pulse every 20 milliseconds. The length of the pulse instructs
the servo motor to move to a specii c angle. The PWM signals vary between
a ½ and 2 ½ milliseconds. A ½ millisecond pulse instructs the servo motor
to move to its minimum position, and a 2 ½ millisecond pulse tells the Servo
motor to move to its maximum position. A 1 ¼ millisecond pulse will move to
the central position.
The question is, “How exactly can this be done in an Arduino?” The PWM
interface on an Arduino does not have the same timings as servo motor controls,
and it is easy to make a mistake and make a pulse longer than 2 milliseconds.
Fortunately, the Arduino abstraction layer makes this extremely easy, requiring
only a few instructions.
Most boards allow up to 12 Servo motors to be connected at any one time,
with the exception of the Arduino Mega, which can control up to 48 motors.
However, this comes at a small price. Using the Servo library automatically
disables PWM operations on pins 9 and 10. Again, the Arduino Mega is
an exception and can happily use up to 12 Servo motors without interfer-
ence. Any more than 12 servo motors results in PWM being disabled on
pins 11 and 12.
NOTE In Arduino 0016 and earlier, only two servos were supported, on pins 9 and 10.
Connecting a Servo Motor
Servo motors typically have three wires. The power wire, usually red, is con-
nected to the power rail. The ground wire, usually black or brown, is connected
to the ground rail. The third wire, usually yellow or orange, is the signal wire
 
Search WWH ::




Custom Search