Home / Learn / Electronics basics

Motors for makers: DC motors, servos and stepper motors explained

New to this? Read from the top. Already know the basics? Jump to Going deeper for intermediate and advanced detail.

Three kinds of motor: a DC motor driven by an H-bridge for speed and direction, a hobby servo that moves to an angle set by a 1 to 2 millisecond pulse, and a stepper motor that turns in fixed steps
Beginner

Making something move is where many projects get exciting, and where many microcontrollers get damaged. This guide covers the three types of motor makers use, what each is good for, and how to drive them without resetting or frying your board.

The golden rules

  • Never power a motor from a microcontroller pin. Pins supply milliamps; motors want hundreds of milliamps or amps.
  • Give motors their own supply, or at least don't run them from the board's on-board regulator. Motor current spikes cause voltage dips that reset microcontrollers.
  • Connect the grounds of the motor supply and the microcontroller together, so the control signals have a reference.
  • Suppress the spikes: motors are inductive, so use a driver with built-in protection, or a flyback diode. See diodes explained.

DC motors

A brushed DC motor spins when you apply a voltage. Its speed rises with voltage, and the current it draws rises with the load. When it's prevented from turning, it draws its stall current, which can be many times its no-load current, and every motor draws a burst close to that each time it starts. Size your driver and supply for the stall current.

  • Speed: controlled with PWM through a transistor or MOSFET. See PWM explained.
  • Direction: needs an H-bridge, four switches that can apply the supply either way round across the motor.

H-bridge driver boards

DriverSwitchesNotes from the datasheet
L298N modulesBipolar transistorsCommon and robust, but the bridge loses roughly 2 to 3 V at 1 A, so a 6 V supply gives the motor much less than 6 V, and the chip gets hot.
TB6612FNGMOSFETsTwo motors, 1.2 A per channel continuous (3.2 A peak), motor supply up to 13.5 V. Much lower losses than the L298.
DRV8833MOSFETsTwo motors, motor supply 2.7 to 10.8 V: suits small battery-powered robots.

Hobby servos

A hobby servo is a small DC motor, a gearbox, a position sensor and a control circuit in one box. You send it a pulse every 20 ms, and the pulse width (about 1 to 2 ms) sets the angle, usually over about 180°. It holds that position against a load. The popular SG90 micro servo is rated at 4.8 V.

Servos are perfect for steering, flaps, pointers and grippers. They draw short current spikes of several hundred milliamps when they move, so power them from a separate 5 V supply, not the Arduino's 5 V pin, and add a large capacitor (a few hundred µF) across the servo supply. On an Arduino, the Servo library handles the timing:

#include <Servo.h>

Servo arm;

void setup() {
  arm.attach(9);      // signal wire to pin 9
}

void loop() {
  arm.write(0);       // one end
  delay(1000);
  arm.write(90);      // centre
  delay(1000);
  arm.write(180);     // other end
  delay(1000);
}

"Continuous rotation" servos look the same but the pulse width sets speed and direction instead of angle.

Stepper motors

A stepper moves in fixed steps when its coils are energised in sequence, so it can turn an exact angle without any feedback. That's why 3D printers and plotters use them. They hold their position strongly when powered, but they draw current even when stopped and can lose steps if overloaded.

28BYJ-48 with a ULN2003 board

The cheap 5 V geared stepper in most starter kits. The motor itself takes 32 full steps per turn, and the gearbox reduces that by about 63.7:1, giving about 2,038 full steps per turn of the output shaft (many tutorials round it to 2,048, so a full turn drifts a little). It's slow and weak but easy to drive from four pins through the ULN2003 board.

NEMA 17 with an A4988 or DRV8825 driver

The standard 3D printer motor: usually 200 steps per turn (1.8° per step). These need a proper stepper driver module, which takes just two pins (STEP and DIR) and controls the coil current. You must set the driver's current limit to suit the motor, using the small potentiometer and the reference voltage formula for your board. Too high and the motor and driver overheat; too low and it skips steps. Never disconnect a stepper from its driver while it's powered, as that can destroy the driver.

Which motor should I use?

You needUse
Continuous spinning: wheels, fans, pumpsDC motor with an H-bridge or MOSFET driver
Move to an angle and hold it, within about 180°Hobby servo
Exact, repeatable positioning or slow controlled rotationStepper motor and driver
Intermediate and advanced

Going deeper

Back-EMF and why current falls as speed rises

A spinning DC motor also acts as a generator, producing a back-EMF proportional to its speed that opposes the supply. The current is (Vsupply − back-EMF) ÷ Rwinding. At standstill there's no back-EMF, so the current is V ÷ R, the stall current. As it speeds up, the back-EMF rises and the current falls. Torque is proportional to current, so a DC motor gives most torque at stall and none at its no-load speed, with peak mechanical power at about half the no-load speed.

Braking and coasting

H-bridge drivers usually offer two ways to stop: coast (all switches off, so the motor spins down freely) and brake (both motor terminals connected together, so the back-EMF drives a current that slows the motor quickly). The TB6612FNG's truth table shows both modes. Choose deliberately: brake for robots that must stop on a line, coast for fans and gentle stops.

Stepper torque falls with speed

Each step, the driver must build current in an inductive coil. At higher step rates there isn't time for the current to reach its set value, so torque falls off. Drivers like the A4988 chop a higher supply voltage to force the current in faster, which is why stepper drivers run at 12 to 24 V even when the motor's rated voltage is low. The current limit, not the voltage, protects the motor.

Microstepping

Microstepping drives the two coils with stepped sine and cosine currents so the rotor sits between full steps. It makes movement smoother and quieter, but the extra positions aren't as accurate or as stiff as full steps, so a 1/16 microstepped motor doesn't have sixteen times the precision.

Sources

The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.