Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Robotics servo control uses pulse width modulation, or PWM, to send position commands to a motor controller inside a servo. This cheat sheet helps students connect signal timing, angle control, wiring, and starter code in one reference. It is useful when building robot arms, steering mechanisms, grippers, pan-tilt cameras, and other moving parts.

Students need it because small timing or wiring mistakes can cause jitter, weak motion, or damaged components.

The most important idea is that a servo reads the width of a repeating control pulse, not the average voltage like a simple DC motor speed controller. A typical hobby servo expects a pulse about every 20 ms, with about 1.0 ms for one end, 1.5 ms for center, and 2.0 ms for the other end. Duty cycle is calculated with duty cycle = pulse width / period x 100%.

Calibration adjusts the exact pulse limits so the servo moves safely without hitting mechanical stops.

Key Facts

  • PWM stands for pulse width modulation, and it controls a signal by changing how long the signal stays high during each repeating period.
  • Period and frequency are related by frequency = 1 / period, so a 20 ms servo period equals 50 Hz.
  • Duty cycle is calculated with duty cycle = high time / period x 100%, where high time is the pulse width.
  • A common hobby servo range is 1.0 ms to 2.0 ms, with 1.5 ms usually near the center position.
  • For a 20 ms period, a 1.5 ms pulse has duty cycle = 1.5 / 20 x 100% = 7.5%.
  • A simple angle map is pulse width = min pulse + angle / 180 x (max pulse - min pulse) for a 0 to 180 degree servo.
  • Servo power should usually come from a separate 5 V to 6 V supply, but the servo ground and controller ground must be connected together.
  • Calibration means testing and setting safe min, center, and max pulse values before using the servo in a robot mechanism.

Vocabulary

PWM
Pulse width modulation is a control method that sends repeated on-off pulses and changes the high-time of each pulse.
Pulse width
Pulse width is the amount of time a PWM signal stays high during one cycle, often measured in milliseconds or microseconds.
Duty cycle
Duty cycle is the percent of one PWM period during which the signal is high.
Frequency
Frequency is the number of repeating PWM cycles per second, measured in hertz.
Servo calibration
Servo calibration is the process of finding safe pulse values that match the servo's real center and motion limits.
Common ground
Common ground means connecting the ground of the controller and the ground of the servo power supply so they share the same signal reference.

Common Mistakes to Avoid

  • Using duty cycle alone to describe servo position is wrong because most hobby servos respond to pulse width, usually in microseconds or milliseconds.
  • Forgetting to connect common ground is wrong because the servo signal has no reliable voltage reference and the servo may jitter or ignore commands.
  • Powering several servos directly from a small microcontroller pin is wrong because signal pins cannot supply the high current a moving servo needs.
  • Commanding 0 degrees or 180 degrees without calibration is risky because the servo may hit a mechanical stop and draw too much current.
  • Confusing frequency with pulse width is wrong because frequency sets how often pulses repeat, while pulse width sets the commanded servo position.

Practice Questions

  1. 1 A servo signal has a 20 ms period and a 1.0 ms high pulse. What is the duty cycle?
  2. 2 A controller sends a 50 Hz PWM signal. What is the period in milliseconds?
  3. 3 Using pulse width = 1000 microseconds + angle / 180 x 1000 microseconds, what pulse width commands 90 degrees?
  4. 4 Why should a robot use a separate servo power supply with a shared ground instead of powering a servo only from a microcontroller signal pin?

Understanding Servo & PWM Control Reference

Inside a standard positional servo is more than a motor. A small circuit compares the commanded pulse with feedback from a potentiometer connected to the output shaft. The difference tells the circuit which way to drive the motor.

As the shaft approaches the requested position, the difference becomes smaller. The motor slows or stops when the feedback matches the command.

This feedback loop explains why a servo can hold an arm in place against a light load. It also explains why a servo may hum when it cannot quite reach the requested position.

The command value does not guarantee a precise physical angle. Gear backlash, worn parts, supply voltage, temperature, load, and the shape of the attached mechanism can change the result. A servo marked as 180 degree travel may safely move through less than that range.

Some servos are designed for continuous rotation. Their pulse commands set direction and speed rather than shaft position.

Check the servo type before writing angle based code. For a robot arm, measure real positions with a ruler, protractor, or marked test board instead of trusting the label.

Power problems are one of the main causes of unreliable motion. A servo can draw a brief large current when starting, reversing, or pushing a load. A controller board may still appear powered while its voltage drops enough to reset or corrupt its signal output.

Use wires that are short and thick enough for the expected current. Place a suitable capacitor near the servo power connection when the system has sudden current demands. Keep the controller signal wire away from noisy motor wires where possible.

A shared ground gives the signal a common voltage reference. Without it, the servo cannot reliably tell what counts as a high or low signal.

Good calibration begins with no load or a mechanism that can move freely. Start near the center command, then move in small steps toward each end while watching for buzzing, shaking, or contact with a mechanical stop. Record safe limits that leave a small margin before either stop.

Use those limits in software rather than assuming every servo has identical travel. In code, command a new position, allow time for movement, then continue with other tasks instead of using long blocking delays. For smooth motion, change the target in small increments at a controlled rate.

This reduces shock on gears, linkages, and objects held by a gripper. If a servo jitters while idle, inspect the power supply, ground connection, loose connectors, mechanical load, and repeated commands that change by tiny unwanted amounts.