Published 2026-04-13
Pulse Width Modulation (PWM) is the standard method used to precisely control the angular position of a standard hobbyservomotor. By varying the width of the electrical pulse sent to theservoevery 20 milliseconds, you can command theservoto move to a specific angle, typically between 0 and 180 degrees. This guide provides the exact signal specifications, step-by-step control logic, practical examples, and troubleshooting tips so you can implement PWM servo control immediately.
A standard servo motor contains a small control circuit that reads the incoming PWM signal. The servo’s output shaft position is determined solely by thepulse width(duration of the high signal) within a fixed 20 ms (50 Hz) frame. The relationship is linear: a specific pulse width equals a specific target angle.
Standard pulse-to-angle mapping (for 0–180° servos):
0 degrees:0.5 ms pulse (500 microseconds)
90 degrees (neutral):1.5 ms pulse (1500 microseconds)
180 degrees:2.5 ms pulse (2500 microseconds)
These values are industry standard. Always verify your servo’s datasheet, but over 95% of standard servos follow this exact mapping.
To control the servo angle, you must generate a repeating signal with two key parameters:
The servo expects a new pulse every 20 milliseconds. This means the PWM frequency is 1 / 0.02 s = 50 Hz. Do not change this frequency; otherwise the servo will jitter or not respond.
Use this linear interpolation formula:
Pulse width (ms) = 0.5 + (angle / 180) 2.0
For example:
Angle = 45° → Pulse = 0.5 + (45/180)2.0 = 0.5 + 0.5 =1.0 ms
Angle = 135° → Pulse = 0.5 + (135/180)2.0 = 0.5 + 1.5 = 2.0 ms
In practice, you set a timer: output HIGH for the pulse width (e.g., 1.5 ms), then output LOW for the remaining time (20 ms – 1.5 ms = 18.5 ms). Repeat continuously.
Imagine you have a servo connected to a robotic arm. You want it to move from fully left (0°) to fully right (180°) in steps.
Signal sequence (each line is one 20 ms cycle):
Cycle 1: HIGH for 0.5 ms → Servo moves to 0°
Cycle 2: HIGH for 1.0 ms → Servo moves to 45°
Cycle 3: HIGH for 1.5 ms → Servo moves to 90°
Cycle 4: HIGH for 2.0 ms → Servo moves to 135°
Cycle 5: HIGH for 2.5 ms → Servo moves to 180°
Observed behavior:The servo will step to each angle and hold that position. It does not drift because the control circuit constantly receives the target pulse width.
You can generate the required PWM signal using:
Microcontroller timer/counter modules– Set up a 50 Hz PWM with variable duty cycle. Duty cycle = (pulse width / 20 ms) 100%. For 1.5 ms pulse, duty cycle = 7.5%.
Software bit-banging– Directly control a GPIO pin with delays. Less precise but works for learning.
Dedicated servo driver modules– These offload timing precision but still require the same 0.5–2.5 ms pulse range.
Critical precision requirement:Pulse width accuracy must be within ±10 µs (microseconds). Jitter or wrong angles occur if your timing is off by more than 20 µs.
Real case: A common mistake is using a 1.0–2.0 ms range because some microcontroller libraries default to that. One user reported their servo only turned 90° total. After changing the pulse range to 0.5–2.5 ms, full 180° rotation was restored.
PWM controls servo angle by pulse width, not duty cycle alone. For a fixed 20 ms period, the absolute high time (0.5 to 2.5 ms) determines position.
The relationship is linear: pulse width = 0.5 ms + (angle/180)*2.0 ms.
Always use 50 Hz (20 ms period). Any other frequency will cause erratic behavior or no movement.
Verify your minimum and maximum pulse widths. Most issues come from incorrect pulse range, not hardware failure.
Follow these steps immediately to get consistent results:
1. Measure your servo’s actual response. Send 0.5 ms, 1.5 ms, and 2.5 ms pulses. Mark the physical angles. If they are not 0°, 90°, 180°, record the actual pulse-to-angle mapping.
2. Add a 100–200 µs safety margin at both ends (min pulse = 0.6 ms, max = 2.4 ms) to prevent mechanical binding.
3. Use a dedicated timer hardware instead of software delays when possible. Timer-based PWM maintains precision even when your main code is busy.
4. Test with a logic analyzer or oscilloscope to confirm pulse widths. Many software simulations hide timing errors.
5. For multi-servo projects, keep power supply separate from logic supply. A stalled servo can draw 1–2A, causing voltage drops that corrupt PWM signals.
By strictly adhering to the 0.5–2.5 ms pulse width range within a 20 ms period, you will achieve precise, repeatable angle control on any standard servo motor. Implement the measurement step first, then fine-tune your code, and your servo will move exactly where you command.
Update Time:2026-04-13
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.