servomotor-funcionamiento-pwm-control-posicion

The Servomotor: Muscle, Brain, and PWM

  • 5 min

A hobbyist servomotor is an actuator with a motor, gearbox, position sensor, and closed-loop controller.

Imagine you want the rudder of a radio-controlled airplane to move 30 degrees to the right and stay there, resisting the force of the wind.

  • A DC motor would need a gearbox, sensor, and external controller.
  • A stepper could do it, with different trade-offs in weight, power consumption, and control.

The solution is the Servomotor. A little black box containing a motor, a gearbox, and an electronic brain capable of correcting its own position in real-time.

What’s inside the box?

If you open up a typical servo (like the popular blue SG90 or the powerful MG995), you’ll find four key elements:

  1. DC Motor: A standard, small, and fast motor.
  2. Gearbox (Reduction Drive): A gear train (plastic or metal) that reduces the motor’s speed to gain enormous force (Torque) .
  3. Potentiometer: This is the key. It’s connected to the output shaft. When the servo arm rotates, the potentiometer rotates with it.
  4. Control Circuit (The Brain): It reads the potentiometer to know the current angle of the shaft.

Motor Comparison

NeedDC MotorStepperServo
SpeedHighMediumLow
Force (Torque)Low (without gearbox)High (At standstill)Very High
PrecisionNone (unless with encoder)High (Digital)High (Analog)
ControlSimple (2 wires)Complex (4 wires + Driver)Very Simple (3 wires)
FeedbackNoNo (Blind)Yes (Knows its position)
RotationInfiniteInfiniteLimited (180°)

Closed-Loop Control

The servomotor operates using a constant feedback system. It’s a miniature automatic control system.

The Command: You tell it: “Go to 90 degrees.”

The Comparison: The internal chip reads the potentiometer. “I am currently at 0 degrees.”

The Error: It calculates the difference.

The Action: The chip turns on the DC motor at full power forward.

The Braking: As it approaches 90, the error decreases. When the potentiometer reads 90 degrees, the chip turns off the motor.

What happens if you try to turn it by hand? The potentiometer will detect that the angle has changed (e.g., to 85 degrees). The chip will detect the error and turn on the motor to push it back to 90 degrees. The servo has active holding torque.

The Control Signal: A Very Special PWM

We had already seen PWM is used to regulate voltage (0% to 100%). In servos, we use PWM, but in a different way.

In this case, the servo signal is a pulsed signal that transmits the desired position through the exact duration of the pulse.

The standard for analog servos is a 50 Hz signal (one cycle every 20ms). Within those 20ms, we send a HIGH pulse whose duration defines the angle:

  • 1.0 ms Pulse: → Angle 0 degrees (Full left).
  • 1.5 ms Pulse: → Angle 90 degrees (Center).
  • 2.0 ms Pulse: → Angle 180 degrees (Full right).

If the pulse period is less than 20ms (the frequency), the servo doesn’t care. What matters is the width of the active pulse.

These times vary slightly depending on the brand, sometimes it’s 0.5ms to 2.5ms, but the concept is the same.

Types of Servos

These are the most common. They have a mechanical stop that prevents them from turning more than half a turn. They are ideal for robotic arms, grippers, rudders, and hexapod robot legs.

These are servos designed or modified to rotate continuously.

  • The mechanical stop has been removed.

  • The feedback circuit is modified to interpret the center point as a stop.

  • Behavior:

    • 1.5ms Pulse (90°) → Motor Stopped.
    • 2.0ms Pulse (180°) → Spins fast forward.
    • 1.0ms Pulse (0°) → Spins fast backward.
  • You no longer control the position; you control the speed. They are used as motors with an easy-to-control gearbox for robot wheels.

Digital vs. Analog

Physically, they look the same from the outside.

  • Analog: Sends pulses to the motor at 50Hz. They have less holding torque and make a characteristic hum under load.
  • Digital: Have an internal microprocessor that sends pulses to the motor at 300Hz. They react faster and have more torque, but consume more battery and make a higher-pitched noise.

The Power Supply Problem (Brown-out)

The number 1 mistake when using servos with Arduino: “I connect the servo to the 5V pin of the Arduino and, when it moves, the Arduino resets.”

A small servo (SG90) can draw peaks of 500mA when starting up. A large servo (MG995) can draw 2 Amperes. The Arduino’s regulator can’t handle that. The voltage drops, and the brain shuts down.

Power the servos with an external power source (batteries, battery pack, or dedicated 5V supply). And a fundamental detail: Connect the grounds (GND) of the external source and the Arduino, otherwise the control signal won’t work.