Servo motor controlled by pulse width modulation from an Arduino

From Knowledge Kitchen
Jump to navigation Jump to search


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).


The circuit

Servo circuit with Arduino


The code

Oscillating servo motor circuit Arduino code


Questions

  1. Why do we add a delay after rotating the servo?
  2. What is the pulse width that corresponds with a 45 rotation?
  3. 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?


What links here