S+−servoATmega328P5 V220 Ω1N4001SDG6 V motor6 V1servo.attach(9);2servo.write(90);3servo.write(180);4analogWrite(3, 191);5analogWrite(3, 0);pin 9one 20 ms framepin 3pin 9pin 3GND1500 µs1472 µs2400 µsPWM 191currentspike!coil current0
Back: the chip and a servo on pin 9; middle: a MOSFET on pin 3 switching a 6 V motorFront: the firmware card and the two pin signals over timeTokens: pulses, currents and the spike as they moveA servo reads the width of a pulse sent every 20 ms: the Arduino Servo library turns write(90) into 1472 µs and write(180) into 2400 µs, and the servo turns until its own sensor agrees. A DC motor reads nothing: an IRLZ44N switches its 6 V with PWM, and it spins at the average, 191 ÷ 255 × 6 V ≈ 4.5 V. A 1N4001 flyback diode carries the coil's current at every off-edge; the low-side switch sets speed, not direction.

A servo: angle from a pulse

  1. A hobby servo hides a DC motor, gears, a position sensor and a small control circuit in one box. It has three wires: power, ground and signal. You never drive its motor yourself: you send an angle, and it turns there and holds it.

A DC motor: speed from PWM

Switching a coil safely

What happens

;; step 1/11 · servo-inside
hobby servo   motor + gears + position sensor + control circuit
wires         power (red), ground (black or brown),
              signal (yellow, orange or white)
feedback      it turns until the sensor reads the angle you asked for

Servos differ. The Arduino library maps 0 to 180 degrees onto 544 to 2400 µs by default, while many servos reach their ends nearer 1000 and 2000 µs; servo.attach(pin, min, max) sets your servo's own range. The figure turns the horn on the library's scale. The Servo library uses Timer1 on the Uno, so the motor is on pin 3, whose PWM comes from Timer2 at about 490 Hz. Pins 5 and 6 run at about 980 Hz but give higher-than-expected duty cycles.