Servo motor controlled by pulse width modulation from an Arduino
This simple example shows how to oscillate a servo motor back and forth automatically. Servos respond to the pulse width modulation (PWM) of a signal, meaning that changes in the width of DC current pulses cause changes in the rotation of the servo's armature.
Whereas most applications of PWM deal with the duty cycle of the pulses (i.e. the relative duration of the signal, as compared to the duration of no signal), servos respond to the absolute width of the pulses. In other words, a pulse of a particular duration will always move the servo to a particular rotation angle, regardless of how much time exists between pulses (within limitations, of course).
- Why do we add a delay after rotating the servo?
- What is the pulse width that corresponds with a 45 rotation?
- Why doesn't the Arduino reliably turn a servo motor at the same time as it plays a sound from a piezo speaker using the tone() function?