LESSONMotors & Drivers · Part 3EP.33 · 20 s

Servo motor: stop at an exact angle

// WHAT YOU WILL LEARN

Inside a servo (motor + gears + pot feedback), pulse width = angle, 3-wire hookup and servo.write() to 0°, 90°, 180°.

// LESSON NOTES

A motor that stops at an EXACT angle 🎯 (the servo we promised!)

1️⃣ WHAT'S INSIDE: a small DC motor + gears (slow it down, make it strong) + a POT on the output shaft that measures the angle + a little control chip.
The chip compares TARGET vs NOW. Not equal? The motor turns. Equal? It stops. It checks this nonstop, so it holds the angle.

2️⃣ THE SIGNAL: one pulse every 20 ms (50 times a second). The pulse WIDTH is the angle: about 1 ms = 0°, 1.5 ms = 90°, 2 ms = 180° (exact range varies by servo).

3️⃣ JUST 3 WIRES (SG90): brown = GND, red = 5V, orange = signal → pin 9. One small servo is fine on the Uno's 5V. Big servos need their own 5–6 V supply (join the GNDs).

4️⃣ THE CODE:
#include <Servo.h>
Servo s;
s.attach(9);
s.write(0) → s.write(90) → s.write(180), delay(1000) each.
Shown at real speed (an SG90 moves about 60° in 0.1 s).

CODE FROM THIS LESSON
#include <Servo.h>
Servo s;
s.attach(9);

Related lessons