Three motor families — DC, servo, stepper — trade control granularity for complexity. But they all bow to the same three ideas: switch power instead of burning it (PWM), reverse polarity with four switches (the H-bridge), and tame the inductive kickback (the flyback diode). Master those and you can drive anything that spins.
You have a 6 V hobby DC motor, a fresh 6 V battery, and a potentiometer. You want to slow the motor down, so you do the obvious thing: wire the pot in series, like a dimmer for a lamp. Crank it up and the motor spins. Turn the knob to "slow it down" and… the pot gets scorching hot, the motor barely slows before it shudders to a stall, and a minute later there's a wisp of smoke and a melted wiper. Meanwhile your friend's robot runs the same motor at any speed from a crawl to full tilt, cool to the touch, driven by a single microcontroller pin.
What is the micro doing that your potentiometer isn't? The answer is the spine of this entire chapter. A series resistor controls speed by dissipating the unwanted energy as heat. The microcontroller controls speed by switching the motor fully on and off thousands of times a second, so the average power is whatever fraction you choose — with almost no waste. This trick is called pulse-width modulation (PWM), and it is why nothing in a well-designed motor drive ever melts.
Let's see exactly why the resistor cooks. Say the motor's winding resistance is about 3 Ω and at full speed it draws roughly 1 A from 6 V. To halve the voltage at the motor you'd add a 3 Ω series pot. Now the circuit is two 3 Ω resistances in series, so the current drops and the pot itself sinks a big chunk of the power.
A typical trimpot is rated for a fraction of a watt. Three watts in a part rated for 0.25 W is a meltdown. Worse, the motor is not a fixed resistor: as it slows, its self-generated back-voltage (back-EMF, Chapter 4 here) collapses, so it tries to draw even more current near stall — right when the pot is hottest. The control scheme fights itself.
Drag the speed knob from full to slow. The bars compare where the power goes in two schemes: a series resistor (red = wasted heat) vs PWM switching (teal = delivered, tiny loss). Watch the resistor's heat peak in the middle — the worst place for it.
The humble brushed DC motor is the simplest electromechanical device you'll meet: two leads, and that's the whole interface. Apply a voltage one way, it spins one way; reverse the voltage, it spins the other way; more voltage, faster. There's no logic, no protocol, no feedback wire. That brutal simplicity is its appeal — and its limitation.
Inside, a wound coil (the rotor or armature) sits in the field of permanent magnets (the stator). Current through the coil makes it an electromagnet; it's pushed by the stator field and rotates. A clever mechanical switch called the commutator — a split ring with carbon brushes — flips the coil's current every half-turn so the push never reverses. The motor keeps spinning as long as current flows.
Two facts govern its behavior. First, speed rises with applied voltage: a motor rated 6 V at 6000 rpm spins roughly proportionally slower at lower voltage. Second, the spinning coil generates its own opposing voltage, the back-EMF, proportional to speed:
This single equation explains everything. At full speed under no load, ω is high, so Vbemf is large and nearly cancels Vapplied — the current I = (Vapplied − Vbemf)/R is small. But the moment you stall the shaft (ω = 0), Vbemf collapses to zero and the full supply drives current through just the tiny winding resistance. That's the dreaded stall current.
Torque is proportional to current: T = kT × I. More current means more twist. Since stall kills the back-EMF, stall current is enormous — often 1000% or more of the free-running current. A motor that sips 0.3 A spinning freely can demand 3–5 A locked.
DC motors typically spin 3000–8000 rpm and come rated for 1.5–24 V. Two practical limits bracket the supply: run them below about 50% of rated voltage and they may not produce enough torque to overcome their own friction — they stall and just heat up. Run them above about 130% of rated voltage and they overheat and wear the brushes fast. The usable window is narrower than you'd guess.
Slide the applied voltage on a 6 V / 6000 rpm motor. Watch speed, back-EMF, and current. Toggle "stalled" to lock the shaft and see the current spike. Note the safe band (50–130%).
Chapter 0 showed the problem. Here's the fix in full. Instead of feeding the motor a partial voltage through a resistor, we feed it the full supply — but only for a fraction of each tiny time slice. Switch fully on, then fully off, then on again, thousands of times per second. The motor's mechanical inertia and electrical inductance can't respond to each individual pulse; they average them. The motor behaves as if it's running on the average voltage.
The fraction of each cycle the switch is ON is the duty cycle. The averaging gives a beautifully simple result:
And because the switch is never partway on, almost no power is burned in the switching transistor. When it's on, the voltage across it is near zero (so I²R loss is tiny). When it's off, the current is zero (so no loss). All the delivered power reaches the motor. That's why a PWM drive can sit at 30% speed indefinitely without warming up, while the series pot at 30% would be an inferno.
You have a 12 V motor that spins about 6000 rpm at full voltage. You want roughly 4000 rpm. Since speed tracks average voltage, find the voltage first:
So you program a 67% duty cycle. At a 1 kHz PWM frequency (period = 1 ms), the ON time per cycle is thigh = 0.667 × 1 ms ≈ 0.67 ms, with 0.33 ms off. No resistor, no heat, exact speed.
If you switch too slowly (say 20 Hz), you'll hear and feel the pulses — the motor cogs and whines audibly. Push the frequency well above hearing (1–20 kHz) and it goes silent and smooth, because the motor's inductance filters the chop into clean average current. The trade-off: faster switching means the transistor spends more total time mid-transition, where it does dissipate — so very high frequencies bring back a little switching loss. Audio-band-just-above (~20 kHz) is the usual sweet spot.
Slide the duty cycle. The scope trace shows the switched waveform; the gauge shows Vavg = duty×12 V; the motor spins at the corresponding speed. Below 50% the rotor stalls (red) — just like the real thing.
A DC motor reverses when you reverse the polarity of the voltage across its two leads. Swap the wires and it spins backward. But you can't swap wires in software. So how does a robot reverse a motor under microcontroller control? With four switches arranged in the shape of an H — the H-bridge.
Picture the motor as the horizontal bar of the H. Above it sit two switches connecting each motor lead to the positive supply (call them the high-side switches, top-left A and top-right B). Below it, two more connect each lead to ground (low-side, bottom-left C and bottom-right D). The motor's left lead joins A and C; the right lead joins B and D.
To drive the motor forward, close one diagonal pair: A + D. Now the left lead is at +V and the right lead is at ground — current flows left-to-right, motor spins forward. To reverse, close the other diagonal: B + C. Now the right lead is +V and the left is ground — current flows right-to-left, motor spins backward. Two diagonals, two directions. It's that clean.
Here's the elegance: you don't need a separate speed-control circuit. PWM one of the active diagonal switches on and off, and you control speed and direction with the same four transistors. Want forward at 60%? Hold A on, PWM D at 60%. Want to brake? Close both low-side switches (C + D) — this shorts the motor's two leads together, and the spinning rotor's own back-EMF drives a current that opposes its motion, stopping it fast. (Both low-side on with the motor between them is safe; it's both on one side that shorts the supply.)
Click the four switches (A, B top; C, D bottom) to open/close them. Close the A+D diagonal for forward, B+C for reverse. Close both on one side and the bridge flashes a SHORT warning. The motor in the middle spins to match.
Tip: click a switch directly on the diagram to toggle it.
Every motor is, electrically, a coil of wire — an inductor. And inductors have a stubborn personality: the current through them cannot change instantly. Push current through a winding, then suddenly open the switch, and the inductor refuses to let that current stop. It generates whatever voltage it takes to keep the current flowing for an instant — and "whatever it takes" can be hundreds of volts, even from a 6 V supply.
This is the inductive kickback (also called back-EMF in the switching sense, distinct from the speed-back-EMF of Chapter 1). The governing law is the inductor equation:
When you open a switch, you're trying to drive dI/dt to a huge negative value in a fraction of a microsecond. With dt tiny, VL spikes enormous. That spike appears across your switching transistor as a reverse voltage and punches a hole right through it — one of the most common ways beginners destroy a driver transistor.
Place a diode across the motor winding, oriented so it's normally reverse-biased (cathode to +V, anode to the switched node). In normal operation, current flows through the motor and the diode does nothing. But the instant the switch opens and the inductor tries to fling its voltage the "wrong" way, that voltage now forward-biases the diode. The diode opens a path, and the inductor's current circulates harmlessly in a loop through the winding and diode, decaying gently as its energy bleeds off as heat.
The standard parts are the rectifier diodes 1N4001 or 1N4002 — cheap, robust, and fast enough for motor switching. In an H-bridge you need four of them (one across each transistor), and most integrated driver ICs (like the L293D) build them in. For relays and solenoids — also inductors — the exact same flyback diode is mandatory.
A switch drives a motor-inductor. Click "Open Switch" to interrupt the current. Without the diode, the voltage spikes — "BANG!" Toggle the flyback diode on, then open the switch again: the current loops safely and the spike clamps to ~0.7 V above the rail.
A DC motor spins; it has no idea where it is. Often you don't want endless spinning — you want an arm to swing to exactly 37° and hold there. That's the job of an RC servo: a small geared DC motor packaged with a position sensor (a potentiometer on the output shaft) and a control circuit, all in one box with three wires — power, ground, and signal.
Inside, the servo runs a tiny closed loop. The control circuit compares where the shaft is (read from the feedback pot) against where it's told to be (from the signal wire), and drives the motor to null the difference. When the arm reaches the commanded angle, the error is zero and the motor stops, holding position against load. You command position; the servo handles the rest.
The genius of the servo standard is how the command is encoded: a pulse width, not a voltage or a number. The signal wire receives a pulse roughly every 20 ms (a ~50 Hz frame), and the duration of each pulse sets the target angle:
The angle is linear in pulse width across the 1.0–2.0 ms window:
Servos run on 4.8–6.0 V and pull surprising current under load, so power them from a stout supply, not the microcontroller's regulator. Generating the pulse is trivial: a 555 timer in monostable mode, a dedicated PWM peripheral, or — the modern path — one line of an Arduino Servo library call (servo.write(135)), which translates the angle to the 1.75 ms pulse for you.
Slide the pulse width from 1.0 to 2.0 ms. The horn rotates 0–180°; 1.5 ms snaps to 90° (neutral). The 20 ms frame and the internal feedback-pot dial are shown live.
The servo gives you precise position over ~180°, with feedback. The stepper gives you precise position over unlimited rotation, without feedback — open loop. You don't tell a stepper an angle; you tell it to take a certain number of discrete steps, and it clicks around exactly that far. Pulse it 50 times, it advances 50 steps. No sensor, perfectly repeatable. This is why steppers run 3D printers, CNC machines, and camera mounts.
Inside, the stator has several coils (phases) arranged in a ring, and the rotor is a toothed magnetic gear. Energize one coil and the nearest rotor tooth snaps into alignment with it. Energize the next coil in sequence and the rotor advances by one tooth-pitch — one step. Cycle the coils in order (1000 → 0100 → 0010 → 0001 → repeat) and the rotor walks around the ring, one crisp step per coil change.
How far is one step? It's set entirely by the mechanical tooth count, expressed as the step angle:
Steppers come with different lead counts that tell you the internal wiring: 4 leads = bipolar (two coils, driven by an H-bridge per coil), 5 or 6 leads = unipolar (center-tapped coils, simpler drive), and 8 leads = universal (wire it either way). Step angles range from a coarse 90°/step up to a fine 0.72°/step. Unipolar steppers are the friendliest to drive — a chip like the ULN2003 (seven Darlington switches with built-in diodes) just grounds each coil in turn.
Press Step+ / Step− to fire the four stator coils in sequence (1000→0100→0010→0001). The toothed rotor snaps to the energized coil. Toggle half-step to insert two-coil-on positions and halve the angle.
A microcontroller pin can source maybe 20 mA at 5 V. A motor wants amps at 6, 12, or 24 V. You cannot wire a motor straight to a GPIO pin — the pin (and likely the whole chip) will die. Between the brain and the muscle you always need a buffer / driver stage: a transistor or driver IC that takes the pin's tiny logic-level signal and switches the motor's big current.
The simplest case — one DC motor, one direction — is a single transistor (a logic-level MOSFET or a Darlington) with the motor and a flyback diode in its drain/collector circuit. The pin's PWM signal switches the transistor; the transistor switches the motor. Add the flyback diode from Chapter 4 and you're done. For bidirectional control, you need the full four-switch H-bridge of Chapter 3.
| IC | What's inside | Best for |
|---|---|---|
| ULN2003 | 7 Darlington switches + built-in flyback diodes | Unipolar steppers, relays, one-direction loads |
| L293 / L293D | Dual H-bridge (two motors, both directions); 'D' adds internal diodes | Two DC motors or one bipolar stepper, ~600 mA |
| L298 | Dual H-bridge, higher current (~2 A/channel) | Bigger DC motors & bipolar steppers |
| SAA1027 | Stepper translator (handles sequencing internally) | Unipolar steppers from simple step/direction inputs |
You rarely hand-roll the timing anymore. On an Arduino, analogWrite(pin, 170) emits a ~67%-duty PWM for DC speed; the Servo library turns servo.write(135) into the 1.75 ms pulse; the Stepper library turns stepper.step(50) into the 50-pulse coil sequence for a 90° move on a 1.8° motor. The software hides the protocol — but the hardware (driver IC + flyback diodes + separate supply) is still entirely your responsibility, and that's where projects fail.
Toggle each protection element to see what happens to the signal chain. Remove the driver and the pin overloads; remove the diode and the transistor gets a kickback spike; share the supply and the micro browns out.
Three motor families, one toolkit. Whatever you're driving, the same three ideas recur: PWM to set average power without burning heat, the H-bridge to reverse polarity in software, and the flyback diode to tame the inductive kickback. Choosing the right motor is the first decision; the toolkit is the same afterward.
| DC Motor | RC Servo | Stepper | |
|---|---|---|---|
| Motion | Continuous spin | Constrained angle (~0–180°) | Continuous, in discrete steps |
| Position control | None (open shaft) | Precise, closed-loop (built-in pot) | Precise, open-loop (count steps) |
| Feedback | None | Internal pot | None needed |
| Control signal | PWM duty (speed) | Pulse width 1.0–2.0 ms (angle) | Step + direction pulses |
| Wires | 2 | 3 (V, GND, signal) | 4 / 5 / 6 / 8 |
| Speed / torque | High speed, low precision | Moderate, holds position | Low speed, high holding torque |
| Use it for | Wheels, fans, pumps | Steering, arms, pan/tilt | 3D printers, CNC, precise positioning |
| Concept | Formula / fact | Tab |
|---|---|---|
| Resistive loss | P = I²R — why the series pot melts | 0 |
| Motor voltage balance | Vapplied = I·R + Vbemf; Vbemf = keω | 1 |
| Torque & stall | T = kT·I; Istall = V/R (back-EMF = 0) | 1 |
| Safe voltage band | stalls below ~50% rated, overheats above ~130% | 1, 2 |
| PWM average | Vavg = duty × Vsupply | 2 |
| H-bridge | diagonal pair = direction; same side = SHORT | 3 |
| Inductive kickback | VL = L·(dI/dt); clamp to ~0.7 V above rail | 4 |
| Servo pulse | 1.0/1.5/2.0 ms = 0°/90°/180°; frame ~20 ms | 5 |
| Servo angle | angle = (pulse−1.0)/(2.0−1.0)×180° | 5 |
| Stepper | step_angle = 360°/steps-per-rev; half-step halves it | 6 |
| Driver ICs | ULN2003, L293/L298, SAA1027; flyback diodes 1N4001/2 | 7 |
You can now drive a wheel, swing an arm, or position a print head — and protect every transistor on the way. Next, Chapter 16 turns electrons into sound.