Published 2026-04-21
This guide provides a complete, practical explanation of how to control the rotation of a standardservomotor.servomotors do not spin continuously like regular DC motors; instead, they move to a specific angular position (e.g., 0°, 90°, or 180°) and hold that position. The most reliable and widely used method to achieve this precise directional control is by generating a Pulse Width Modulation (PWM) signal with a specific timing pattern. This article covers the exact working principle, required hardware connections, coding logic examples, common troubleshooting steps, and a final action plan. All information is based on industry-standard specifications and verified practices.
Aservomotor’s rotation angle is determined solely by the width of an electrical pulse sent every 20 milliseconds (ms). This signal is known as acontrol pulse.
Signal period: 20 ms (50 Hz frequency) – consistent across almost all standard servos.
Pulse width range: Typically from 0.5 ms to 2.5 ms.
0.5 ms pulse → rotate to 0° (full counter-clockwise position)
1.5 ms pulse → rotate to 90° (center / neutral position)
2.5 ms pulse → rotate to 180° (full clockwise position)
> Verifiable source: This timing standard is published in the official datasheets of major servo manufacturers (e.g., Futaba, Hitec, Tower Pro) and is consistent with the RC hobby industry protocol.
Key takeaway: The servo’s internal control circuit compares the incoming pulse width with the current position feedback from a potentiometer attached to the output shaft. Any difference triggers the motor to rotate in the correct direction until the two match. This closed-loop system gives you precise, repeatable angular control.
To implement servo rotation control, you need the following items (no specific brands required):
Real-world case: A hobbyist building a remote-controlled robot arm used exactly these components. The servo was powered separately from the microcontroller to avoid voltage drops. By varying the pulse width from 0.5 ms to 2.5 ms in 0.1 ms steps, the arm joint moved smoothly from 0° to 180°.
Most standard servos use a 3-pin connector with the following color codes (check your servo’s datasheet):
Brown or Black → Ground (GND) – connect to common ground of power supply and microcontroller.
Red → Power (Vcc) – connect to +5V or +6V DC supply. Do not power a servo directly from a microcontroller’s 5V pin if it draws more than 200mA; use a separate battery pack.
Orange or Yellow → Signal (PWM input) – connect to a PWM-capable digital pin on the microcontroller.
Step-by-step connection:
1. Connect all grounds (servo GND, microcontroller GND, and power supply negative terminal) together.
2. Connect servo power (red wire) to the positive terminal of the external battery pack.
3. Connect servo signal (orange wire) to the chosen PWM pin on the microcontroller.
> Critical safety note: Never connect a servo’s red wire directly to a microcontroller’s 5V output if the servo requires more than 500mA peak current – it can damage the board. Always use a separate power source for high-torque servos.
Below is a generic code logic that works on almost any microcontroller platform. The example uses standard functions to generate a 50 Hz PWM signal and change the pulse width.
Pseudo-code (for understanding):
setup():
set PWM pin as output
set PWM frequency to 50 Hz (period = 20 ms)
loop():
// Rotate to 0°
set pulse width = 0.5 ms
delay(500) // wait 0.5 seconds for servo to move
// Rotate to 90°
set pulse width = 1.5 ms
delay(500)
// Rotate to 180°
set pulse width = 2.5 ms
delay(500)
![]()
Practical implementation (C-style for Arduino-compatible boards):
#include // Standard servo library
Servo myServo; // Create servo object
void setup() {
myServo.attach(9); // Signal pin 9, 50Hz auto-configured
}
void loop() {
myServo.write(0); // 0° (internally sets 0.5ms pulse)
delay(1000);
myServo.write(90); // 90° (1.5ms pulse)
delay(1000);
myServo.write(180); // 180° (2.5ms pulse)
delay(1000);
}
If your library does not provide a write() method, you can manually generate the PWM using timer interrupts. The exact pulse width must be held for the required duration, then the signal pin set low for the remainder of the 20 ms period.
Even with correct code, you may observe that the servo does not rotate to the expected endpoints. This is due to manufacturing tolerances.
Common situation: A user bought two identical servos. One rotated exactly 0°–180° with 0.5–2.5 ms pulses, while the other only moved from 10° to 170° with the same signal.
Solution – Calibrate the pulse limits:
1. Start with a 1.5 ms pulse (center).
2. Gradually decrease the pulse width in 0.01 ms steps until the servo stops moving. That lowest pulse corresponds to your servo’s physical 0° position.
3. Gradually increase the pulse width from 1.5 ms until the servo stops moving. That highest pulse corresponds to your servo’s physical 180° position.
Record these calibrated values and use them in your code instead of the nominal 0.5 ms and 2.5 ms. Most servos work within 0.6–2.4 ms after calibration.
Some applications (e.g., robot wheels) require unlimited rotation, not just 180° movement. Standard servos can be modified into continuous rotation servos by removing the mechanical stop on the output gear and replacing the feedback potentiometer with two fixed resistors. However, for most users, buying a purpose-built continuous rotation servo is recommended.
Control method for continuous rotation servos:
1.5 ms pulse → stop
>1.5 ms (e.g., 1.7 ms) → rotate clockwise at proportional speed
Core point to remember: Achieving precise servo rotation is entirely about generating the correct pulse width (0.5–2.5 ms) within a 20 ms period. No other method gives you the same accuracy and simplicity.
Actionable recommendations:
1. Start with a test circuit – Use a single servo, a 5V battery pack, and any microcontroller board. Upload the example code that sweeps from 0° to 180° in 10° steps.
2. Calibrate every new servo – Always run the calibration routine (section 5) before finalizing your project. This eliminates positioning errors.
3. Use a dedicated power supply – Never rely on the microcontroller’s 5V pin for more than one small servo. External 5V/2A supplies are inexpensive and prevent resets.
4. Verify with an oscilloscope or logic analyzer – If you encounter persistent issues, measure the actual pulse width on the signal pin. It must be stable and within 0.5–2.5 ms.
5. Document your calibrated values – Write down the min and max pulse widths for each servo in your project. This ensures repeatability if you replace a servo later.
By following this guide, you will achieve reliable, repeatable servo motor rotation control in any robotics or mechatronics project. Always refer to your servo’s datasheet for exact specifications, and when in doubt, test the pulse width range empirically using the calibration method described above.
Update Time:2026-04-21
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.