Circuit 3D

Servo and stepper motors

A servo motor turns to an angle and holds it, following the width of a control pulse of about 1 to 2 ms, repeated every 20 ms. A stepper motor turns in fixed steps as its coils are switched in sequence, usually 200 to a turn, so each step is 360° ÷ 200 = 1.8°.

θ = 360° ÷ N

where N is the steps per turn, usually 200, so each step is 1.8°; microstepping divides each step further.

Servos suit robot arms and steering; steppers suit 3D printers and CNC machines, which count steps instead of measuring position, running open loop.

What is a servo motor?

A servo motor is a small DC motor, a gearbox, a position sensor and a control circuit in one case, which turns its output shaft to an angle you choose and holds it there.

The sensor is usually a potentiometer on the output shaft. The control circuit compares its reading with the angle the pulse asks for and drives the DC motor until they match. Figure 1 turns a servo with its pulse.

0123 ms, every 20 ms 1.5 ms 0° 90° 180°

1.5 ms pulse: (1.5 ms − 1 ms) ÷ 1 ms × 180° = 90°, the center; it holds there as long as the pulses continue.

Figure 1. A typical hobby servo, sent a pulse every 20 ms: about 1 ms turns it to one end, 1.5 ms to the center and 2 ms to the other end. Many accept 0.5 to 2.5 ms for a wider swing.

How do you control a servo motor?

To control a servo motor, send it a pulse every 20 ms, 50 times a second: about 1 ms for one end of its travel, 1.5 ms for the center and 2 ms for the other end.

A servo has three wires: ground, usually brown or black; power, red, often 5 V; and signal, orange, yellow or white. A microcontroller makes the pulses, as Arduino’s Servo library does. A continuous-rotation servo turns the pulse into speed instead, standing still at 1.5 ms.

What is a stepper motor?

A stepper motor turns in fixed steps, usually 200 to a turn, as its coils are energized in sequence; it can turn any number of turns and stop on any step.

Its toothed rotor lines up with whichever coils are energized, so each switch moves it one step. Because the steps are exact, a controller can track its position just by counting them, running open loop, with no sensor. Figure 2 shows the idea with two coils.

A B A B Step 1 coil B forward

Step 1: coil B is driven forward, so the rotor lines up with the right pole: 1 × 90° in this four-step sketch, or 1 × 1.8° = 1.8° in a 200-step motor.

Figure 2. A simplified two-coil stepper, one coil at a time. A real one’s toothed rotor and stator split each turn into 200 steps of 1.8°, but the coils switch in the same order.

How do you drive a stepper motor?

To drive a stepper motor, use a driver chip that switches its coils: the controller sends one pulse per step on a step pin and sets the direction on another.

Drivers such as the A4988, DRV8825 and TMC2209 also limit the coil current and offer microstepping, feeding the coils in-between currents to split each step into up to 16 or more for smoother, quieter motion. Figure 3 turns step rates into speed.

02505007501,000 rpm 240 rpm

800 full steps a second: 800 × 1.8° = 1,440° a second, or 240 rpm.

Figure 3. A 200-step motor driven at a steady step rate, in full steps or sixteenth microsteps. Microstepping is smoother, but takes 16 times the pulses for the same speed.

What is the difference between servo, stepper and DC motors?

A DC motor spins whenever it is powered; a servo turns to and holds an angle, measuring its position; a stepper moves in exact steps, counting them instead.

Servos are closed loop and usually limited to about 180°. Steppers turn without limit and hold firmly while powered, but can silently lose steps if overloaded, as nothing checks them. DC motors are the cheapest and fastest, but need a sensor to know where they are.

How do you work out servo pulses and stepper steps?

To work out a servo’s pulse, scale the angle into its 1 to 2 ms range, so 90° of 180° is 1.5 ms; for a stepper, multiply steps per turn by microsteps.

Example 1: a servo’s pulse

A servo turns from 0° to 180° over pulses of 1 to 2 ms, sent every 20 ms. What pulse turns it to 45°?

Given
a servo taking 1 to 2 ms for 0° to 180°, pulsed every 20 ms
Find
the pulse width for 45°, and its duty cycle
Solution
t = 1 ms + 45° ÷ 180° × 1 ms = 1.25 msDuty = 1.25 ms ÷ 20 ms = 6.25%
Answer
1.25 ms, a 6.25% duty cycle

Example 2: steps on a leadscrew

A 200-step motor, driven at 1/16, turns a leadscrew with a 8 mm lead. How many steps move it 1 mm?

Given
a 200-step motor at 1/16 steps, turning a leadscrew that moves 8 mm a turn
Find
the steps per millimeter, and the distance per step
Solution
Steps a turn: 200 × 16 = 3,200Steps per mm: 3,200 ÷ 8 mm = 400; each step moves 2.5 µm
Answer
400 steps per mm

Summary

Key equations

  • θ = (t − 1 ms) ÷ 1 ms × 180° a servo’s angle
  • θ = 360° ÷ N a stepper’s step
  • rpm = steps/s × 60 ÷ (N × microsteps) a stepper’s speed
  • steps/mm = N × microsteps ÷ lead on a leadscrew

Key terms

Pulse width
How long each control pulse lasts.
Closed loop
Measures its position and corrects it.
Open loop
Counts commands; doesn’t measure.
Microstepping
Splitting each step into smaller ones.

Practice problems

  1. What pulse width centers a typical hobby servo?

  2. A stepper takes 200 steps a turn. What angle is each step?

  3. Which motor knows its position from a sensor inside it?

  4. A 200-step stepper is driven in sixteenth steps. How many microsteps make one turn?

  5. How often does a hobby servo expect a control pulse?

FAQ

What is the difference between a servo and a stepper motor?

A servo moves to a commanded angle using feedback from a sensor inside it, usually over about 180°. A stepper turns in fixed steps, any number of turns, counted without feedback.

How far can a servo turn?

Most hobby servos turn about 180°. Continuous-rotation servos spin freely instead, with the pulse setting speed and direction.

Can an Arduino power a servo?

A single micro servo may run from the board’s 5 V pin, but its current peaks can reset the board. Use a separate 5 to 6 V supply, with a shared ground, for anything larger.

Why does my stepper motor skip steps?

It is being asked to accelerate or turn faster than its torque allows, or the driver’s current limit is set too low. Slow it down, ramp its speed, or raise the current.

What is microstepping?

Driving a stepper’s coils with in-between currents to split each full step, for example into 16, for smoother and quieter motion.

Do stepper motors hold their position when stopped?

Yes, while powered: the energized coils hold the rotor with their holding torque. Unpowered, only a small detent torque remains.

What is a 28BYJ-48?

A small, cheap stepper with a built-in gearbox, often sold with a ULN2003 driver board. Its gearing gives roughly 2,000 full steps per turn of the output shaft.

How do you control a servo motor with an Arduino?

Connect its signal wire to a digital pin, its power to 5 V and ground, and call the Servo library’s write(angle), which sends the 1 to 2 ms pulses for you.