Home > Industry Insights >Custom Drive
TECHNICAL SUPPORT

Product Support

How to Set Servo Rotation Angle: The Complete Practical Guide

Published 2026-04-05

01How to SetservoRotation Angle: A Complete Practical Guide

Setting aservomotor to a specific rotation angle is a fundamental task in robotics, automation,and DIY electronics. This guide provides you with the exact steps, code logic, and calibration methods to make any standardservorotate to any angle you need—without relying on any specific brand or product. You will learn the universal pulse-width principle, the step-by-step programming approach, and how to troubleshoot common angle errors. By the end, you will be able to set servo angles accurately and repeatedly.

1. Core Principle: How Servo Rotation Angle Is Controlled

All standard servos use aPulse Width Modulation (PWM)signal to determine their rotation angle. The control signal is a 50 Hz frequency (period = 20 milliseconds). Within each 20 ms period, a high pulse (the “on” time) tells the servo where to go.

1.0 ms pulse→ 0 degrees (full counter‑clockwise on most servos)

1.5 ms pulse→ 90 degrees (center position)

2.0 ms pulse→ 180 degrees (full clockwise)

These values are the industry standard. However, actual endpoints may vary slightly between individual servos. The table below shows the universal relationship:

Pulse Width Corresponding Angle
1.0 ms
1.25 ms 45°
1.5 ms 90°
1.75 ms 135°
2.0 ms 180°

> Key fact: The pulse width changes the angle linearly. For any angle between 0° and 180°, the required pulse width = 1.0 ms + (angle/180) × 1.0 ms.

2. Step-by-Step Method to Set Any Rotation Angle

Follow these four universal steps. No brand‑specific software or hardware is assumed.

Step 1: Connect the Servo Correctly

A standard servo has three wires:

Brown or Black– Ground (connect to GND of your controller)

Red– Power (5V for most servos; check your servo’s voltage rating)

Orange or Yellow– Signal (connect to a PWM‑capable pin)

> Critical warning: Do not power a servo directly from a microcontroller’s 5V pin when under load. Use a separate 5V power supply capable of providing at least 1A per servo.

Step 2: Generate a 50 Hz PWM Signal

Configure your microcontroller or servo driver to produce a 50 Hz signal (20 ms period). Then set the pulse width according to your target angle.

Example calculation: To set 45°

Pulse width = 1.0 + (45/180)×1.0 = 1.0 + 0.25 = 1.25 ms

Example calculation: To set 135°

Pulse width = 1.0 + (135/180)×1.0 = 1.0 + 0.75 = 1.75 ms

Step 3: Write the Control Code (Generic Pseudo‑code)

The following logic works on any platform (Arduino, Raspberry Pi, ESP32, etc.):

Set PWM frequency = 50 Hz Set PWM resolution = 1 µs (microsecond) steps function setAngle(angle_degrees): if angle_degrees 180: angle_degrees = 180 pulse_width_us = 1000 + (angle_degrees / 180)1000 # pulse_width_us is between 1000 and 2000 Write PWM signal: period = 20000 µs, high_time = pulse_width_us

Step 4: Test and Measure the Actual Rotation

After uploading your code, observe the servo horn. If the horn does not move to the expected position, follow the calibration in Section 4.

3. Real‑World Common Case: Setting a Robotic Arm Joint

Consider a simple robotic arm with three joints (shoulder, elbow, wrist). You want the elbow joint to move from 30° to 120° over 2 seconds.

Case steps:

1. Identify the servo for the elbow.

2. Write a loop that gradually increases the angle:

Start angle = 30° → pulse width = 1.0 + (30/180)×1.0 = 1.1667 ms

End angle = 120° → pulse width = 1.0 + (120/180)×1.0 = 1.6667 ms

3. Increment the angle by 1° every 20 milliseconds (50 steps per second).

旋转角度设置舵机视频_舵机旋转角度的程序_舵机怎么设置旋转角度

4. Total duration = (120‑30) steps × 0.02 s = 1.8 seconds (approximately).

Result: The elbow moves smoothly from 30° to 120° without jerking. This method is used in thousands of hobbyist and educational robots daily.

4. Calibration: Fixing Angle Errors (No Two Servos Are Identical)

Even with the correct 1.0–2.0 ms range, you may find that a command for 90° results in 85° or 95°. This is normal due to manufacturing tolerances. Calibrate each servo individually:

Calibration Procedure

1. Command the servo to 0° (send 1.0 ms pulse).

2. Mark the actual position on the horn.

3. Command the servo to 180° (send 2.0 ms pulse).

4. Mark the actual position.

5. Measure the true angle range. For example, if the physical range is only 170°:

True minimum pulse = 1.0 ms (still works)

True maximum pulse = 2.0 ms gives 170° → to get 180°, you would need 2.058 ms.

6. Instead of altering the standard range, map your desired angle to the actual range:

actual_angle = desired_angle × (true_max_angle / 180)

Example: If true max angle = 170°, to get a desired 90°:

actual_angle = 90 × (170/180) = 85°→ send pulse for 85°.

This linear mapping ensures that the physical horn goes exactly where you want.

5. Common Mistakes That Prevent Correct Angle Setting

Avoid these errors to guarantee success:

Mistake Consequence Fix
Using 60 Hz (16.6 ms period) instead of 50 Hz Servo jitters or does not hold position Set PWM frequency exactly to 50 Hz
Pulse width below 0.5 ms or above 2.5 ms Servo may overheat or hit internal stops Limit pulse to 1.0–2.0 ms
Insufficient power (e.g., drawing 2A from a 500mA regulator) Servo resets or moves erratically Use a separate 5V/2A supply
Changing angle too fast (instant jump from 0° to 180°) Mechanical shock, stripped gears Add small delays (15–30 ms per degree)
Forgetting to re‑calibrate after changing servo Angles are off by 5–10° Run calibration (Section 4) for each new servo

6. Advanced: Setting Angles Beyond 180° (Continuous Rotation Servos)

Some servos are modified for continuous rotation. In that case, the pulse width no longer sets an absolute angle. Instead:

1.5 ms→ stop

(e.g., 1.3 ms) → rotate one direction at speed proportional to the difference

>1.5 ms(e.g., 1.7 ms) → rotate the opposite direction

For continuous rotation servos, “setting an angle” is not possible without a feedback sensor (encoder). Use a standard servo (0–180°) for absolute angle positioning.

7. Actionable Conclusion: Your Next Steps

Core principle repeated: Servo rotation angle is set by generating a 50 Hz PWM signal with a pulse width between 1.0 ms (0°) and 2.0 ms (180°). The relationship is linear.

Immediate action plan:

1. Connectyour servo to a dedicated 5V power supply (not your microcontroller’s 5V pin if more than one servo).

2. Generatea 50 Hz PWM signal on any GPIO pin using your preferred platform’s servo library or raw PWM.

3. Calculatethe pulse width:pulse_us = 1000 + (desired_angle/180)1000.

4. Testwith 0°, 90°, and 180°. Mark the actual positions.

5. Calibrateusing the mapping formula in Section 4 if the positions are off by more than 2°.

6. Gradually movebetween angles by changing the angle by 1–2° every 20–50 ms to avoid mechanical stress.

By following this guide, you can set any standard servo to any angle between 0° and 180° with ±1° accuracy. No brand‑specific tricks are needed—only the universal PWM standard that all servos obey.

Update Time:2026-04-05

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.

Mail to Kpower
Submit Inquiry
+86 0769 8399 3238
 
kpowerMap