Atlas Robotics
Motor ControlBasic

What is a servo motor? A motor with its own position control loop

Atlasbot · 16/8/2026 · 11 min read

What is a servo motor? A motor with its own position control loop
The servo already has a motor + sensor + control circuit inside

DC motors often need an additional driver (H-bridge) and separate encoder if they want accurate position control. The Servo motor (often shortened to "servo", common in RC models) solves both of those tasks neatly inside the motor housing — only a single signal wire is needed to command "turn to this angle".

Key concepts

A standard hobby servo has 3 wires: power (+), GND (-), and control signal. Inside the compact plastic case are already integrated: a small DC motor, gear reduction wheel, a potentiometer that measures the current shaft rotation angle, and a small control circuit that compares the desired angle with the measured angle and then adjusts the motor itself — in other words, the position control loop is already inside the servo, the MCU doesn't need to do it itself.

Controlled by PWM pulse width

The standard hobby servo receives commands via the width of a PWM pulse that repeats every 20ms:

Pulse widthCamera angle
1.0 ms0°
1.5 ms90° (center)
2.0 ms180°

Regular servo only rotates within a limited range (usually 0°-180°), different from continuous rotation servo (continuous rotation servo) - a variant that has removed the mechanical limit, uses pulse width to control speed and direction of rotation instead of angle, operating more like a DC motor with a built-in driver than a conventional position servo.

In short: Servo = motor + encoder (potentiometer) + driver + position control loop, pre-packaged in one block — exchanging convenience (only 1 signal wire) for limited power and accuracy compared to self-assembling DC motor + encoder + PID.

How it works

MCU generates PWM pulses (cycle 20ms, width 1-2ms)
        ↓
The control circuit inside the servo reads the pulse width
        ↓
Compare with current angle (read from internal potentiometer)
        ↓
Automatically adjust the internal motor to rotate to the required angle

Generate servo control signals using the Arduino library:

#include <Servo.h>

Servo myServo;

void setup() {
  myServo.attach(9);   // Signal pin
}

void loop() {
  myServo.write(90);   // Command rotation to 90° — the library automatically generates the correct PWM pulse
}

Technical details

Formulas

The relationship between the desired angle and the pulse width is linear in the range 1.0-2.0ms corresponding to 0°-180°:

Pulse width (ms) = 1.0 + (angle / 180) × 1.0

For example: angle = 45°
Pulse width = 1.0 + (45/180) × 1.0 = 1.25ms

Arduino's Servo library performs this calculation itself inside the write() function — the user only needs to think in degrees, without needing to manually calculate the pulse width in microseconds.

Parameters

Torque and response speed vary widely depending on servo size — choosing the wrong type for the actual load is a common cause of "weak, underpowered" servo:

Servo typeTypical TorqueOperating voltage
Micro servo (VD: SG90)~1.8 kg·cm4.8 – 6V
Standard size servo (eg: MG996R)~10 kg·cm4.8 – 7.2V
High power servo (for robot arms/legs)20 kg·cm or moreDepending on type, usually 6-12V

Register / Bit / Byte

On an MCU that generates servo pulses using a hardware Timer (similar to the ARR/CCR principle mentioned in the DC Motor article), the servo requires a Timer cycle configuration of exactly 20ms (50Hz frequency) — even small cycle deviations can cause some servos to react unstable or vibrate slightly continuously even though the required angle value remains unchanged.

Protocol

In addition to traditional analog PWM, some higher-end servos (e.g., the Dynamixel series used in manipulators/humanoid robots) use the serial digital bus protocol (usually via UART half-duplex on 1 wire) — allowing multiple servos to be connected on the same bus (similar to the addressing idea of Modbus/CAN learned), and at the same time read back the current position/current/temperature of each servo, which regular analog PWM servo cannot do.

Practical applications

Servos are often used for pan-tilt (horizontal-vertical rotation) mechanisms mounted on cameras or distance sensors on AMRs — allowing the robot to "scan" the surrounding area without rotating the entire robot body, or for steering mechanisms on vehicle-like robots (Ackermann) that need to steer precisely at a specific angle. With these joints, position accuracy is more important than speed/power — the true strength of servo compared to self-assembling DC motor + encoder + PID just to hold a fixed angle.

Practical example

#include <stdio.h>

int main() {
    int angles[] = {0, 45, 90, 135, 180};

    for (int i = 0; i < 5; i++) {
        float pulse_ms = 1.0 + ((float)angles[i] / 180.0) * 1.0;
        printf("Goc %3d do -> do rong xung = %.2fms\n", angles[i], pulse_ms);
    }
    return 0;
}
Output:
Goc   0 do -> do rong xung = 1.00ms
Goc  45 do -> do rong xung = 1.25ms
Goc  90 do -> do rong xung = 1.50ms
Goc 135 do -> do rong xung = 1.75ms
Goc 180 do -> do rong xung = 2.00ms

The results match the lookup table in the Main Concepts section (1.0ms = 0°, 1.5ms = 90°, 2.0ms = 180°) — confirming that the linear formula applies correctly to the entire angle range, not just 3 landmarks.

Common mistakes

  • Command the angle beyond the actual mechanical limit of the servo — although the mathematical formula accepts any value from 0-180°, some servos have narrower mechanical limits — trying to force the servo to rotate beyond the limit causes the wheel teeth to jam, which can wear/break the plastic teeth inside.
  • Insufficient current source when many servos are operating at the same time — each servo can pull a peak current of a few hundred mA to more than 1A when resisting a load or starting to move — supplying power from the same weak 5V source as the MCU to many servos at the same time can easily cause voltage drops, causing both the MCU and servo to operate abnormally.
  • Signal wire is too long without noise protection — analog PWM signals (without error correction mechanism like digital bus) are susceptible to noise on long wires, manifesting as the servo continuously shaking slightly even though the sent angle value is stable.
  • Confusing continuous rotation servo with regular position servo — calling write(90) on continuous rotation servo does not return it to 90° but makes it stop rotating (because the middle pulse width is interpreted as "0 speed"), which is completely different from the expected behavior if the two are confused.

Conclusion

Servo motors package the motor, position sensor, and control loop in one block — a quick solution for joints requiring precise positioning with moderate power, in exchange for the convenience of assembling a complete DC motor + encoder + PID system yourself. The next article in the category is about Stepper Motor — a completely different approach to position control, without the need for sensor feedback but requiring its own specific driver and control.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

What is a servo motor? A motor with its own position control loop — Atlas Robotics