Learning Goals 5 min
Welcome to Level 3. You already met one servo at the very end of L2 (Smart Bin Lid, L02-26) — we used it as a black box. Today we open that box. By the end of this lesson you will be able to:
- Explain in your own words how a hobby servo turns a pulse width into a shaft angle — the "pulse-position" control scheme that hasn't changed since the 1960s.
- Identify the three wires of a typical SG90 or MG90S by colour, name and role (GND, +5 V, signal), and know what happens if you swap any two of them.
- Pick the right servo for a small project from the three classroom families: plastic-gear micro (SG90), metal-gear micro (MG90S), and standard-size (S3003-class) — based on torque, current draw and noise.
Warm-Up 10 min
Open your kit and pull out the SG90 you used in L02-26. Hold it up to the light and look at the orange (or yellow) horn on top — that's the output shaft you can command to any angle from 0° to about 180°.
Three quick questions before we start
- How many wires does your servo have? Why three and not two like a plain DC motor?
- If you plug the red wire to GND and the brown wire to +5 V — i.e. swap power and ground — what do you predict will happen? (Don't try it!)
- You command the servo to 90°. It physically rotates and gets there. How does the servo know it's reached 90° and not 85° or 95°?
Reveal initial answers
- Three wires: power, ground, signal. A DC motor only needs two because the voltage you apply is the command. A servo needs an extra wire because the command is a sequence of pulses, not a steady voltage.
- Reverse-polarity protection on cheap servos is minimal. Best case: it doesn't move and gets warm. Worst case: the internal H-bridge IC pops, releasing the magic smoke. Always double-check power polarity before energising a servo.
- There's a tiny potentiometer inside the servo geared to the output shaft. The control board compares the pot's voltage to the commanded position and runs the motor until they match. It's a closed-loop control system in one cheap package — which is exactly why we love it.
Hold that "closed loop" idea — we'll come back to it in Cluster D (PID, Level 4) when we build robots that balance.
New Concept · Pulse-position control 25 min
What's inside the case
A hobby servo is four components glued together in a plastic shell:
| Part | What it does |
|---|---|
| Small DC motor | Spins very fast (thousands of RPM), but with almost no torque. |
| Gear train (plastic or metal) | Reduces RPM by ~300× and multiplies torque by the same factor. |
| Potentiometer | Mechanically linked to the output shaft. Its wiper voltage encodes the current angle. |
| Control board (tiny PCB) | Reads the incoming pulse, reads the pot, drives the motor until both match. |
The signal — a pulse every 20 ms
The signal wire doesn't carry a voltage that means "angle". It carries a steady stream of short pulses, one every 20 milliseconds (50 Hz). The width of each pulse — typically 1.0 ms to 2.0 ms — is the command:
| Pulse width | Commanded angle | Notes |
|---|---|---|
| 1.0 ms | 0° | Full counter-clockwise on most servos. |
| 1.5 ms | 90° | Centre / neutral position. |
| 2.0 ms | 180° | Full clockwise on most servos. |
| 20 ms | (period) | The space between two pulses — the servo holds its position. |
If pulses stop arriving, most servos slowly relax and become movable by hand (no holding torque). If they keep arriving with the same width, the servo stays at that angle and actively pushes back against any force trying to move it — that's the "hold" feel.
Why we never write that timing by hand
Generating a 1.5 ms pulse every 20 ms while your sketch is also doing other work is fiddly. The Arduino has a built-in Servo library that uses hardware timers to generate the pulses in the background — your code just calls servo.write(90) and the library handles the rest. You'll use it in L03-02.
The three wires, colour-coded
There's a long-standing colour convention. Read the table carefully — the "Futaba" column matches most SG90s you'll find in school kits:
| Role | Futaba (most common) | JR | Hitec |
|---|---|---|---|
| GND | Brown or Black | Brown | Black |
| +5 V | Red | Red | Red or Brown |
| Signal | Orange, Yellow or White | Orange | Yellow |
Whatever the brand, red is always in the middle of the 3-wire connector. If you find a connector with red on the end, it's probably not a hobby-servo connector at all — check before plugging in.
Three classroom servos compared
| Servo | Weight | Stall torque | Peak current | Best for |
|---|---|---|---|---|
| SG90 (plastic gears) | ~9 g | ~1.8 kg·cm | ~500 mA | The default. Lightweight builds, demos, the smart-bin lid. |
| MG90S (metal gears) | ~13 g | ~2.2 kg·cm | ~700 mA | Same size, sturdier. Pan-tilt mounts, classroom robots that get dropped. |
| S3003 (standard size) | ~37 g | ~3.2 kg·cm | ~1.0 A | Lifting a real load — RC cars, classroom indicator needle on a big dial. |
Torque is the rotational force the servo can apply. "1.8 kg·cm" means it can hold up 1.8 kg hanging from a 1 cm arm — or 0.9 kg from a 2 cm arm, and so on. For the smart-bin lid (a 2 g cardboard flap on a 5 cm arm) you need 0.01 kg·cm. The SG90 has 180× the headroom we need.
Worked Example · The 50 Hz signal on a scope (paper version) 20 min
You may not have an oscilloscope at home, but you can sketch one on paper. Today we'll draw the servo signal for three commanded angles so the timing is concrete in your head before we let the library hide it.
One frame, three pulse widths
Draw a horizontal axis labelled in milliseconds from 0 to 40. Draw a horizontal line near the bottom at "0 V" and another high up at "+5 V".
Pulse 1 — commanded 0°
- From 0 ms to 1.0 ms, the line jumps up to +5 V.
- From 1.0 ms to 20.0 ms, the line drops to 0 V (idle).
- At 20.0 ms, jump up again to +5 V for 1.0 ms (next frame starts).
Visually: a thin rectangle, then a long gap, then another thin rectangle, repeating forever.
Pulse 2 — commanded 90°
- +5 V from 0 ms to 1.5 ms (half again as wide as before).
- 0 V from 1.5 ms to 20 ms.
- Repeat at 20 ms.
Pulse 3 — commanded 180°
- +5 V from 0 ms to 2.0 ms (twice as wide as the 0° pulse).
- 0 V from 2.0 ms to 20 ms.
- Repeat.
Quick maths — the duty cycle
You met duty cycle in L02-03. What's the duty cycle of the 1.5 ms / 20 ms servo signal?
Reveal
Duty = on-time ÷ period = 1.5 ÷ 20 = 7.5 %. The signal is on for only a small fraction of each frame — the servo's control board is timing the rising edge to the falling edge to figure out the commanded angle, not measuring the average voltage. This is fundamentally different from the "average voltage = brightness" PWM you used to fade an LED.
What changes if the period drifts?
The servo specification calls for one pulse every 20 ms (50 Hz). Some hobby servos are tolerant of 10 ms to 30 ms periods, but a digital servo expecting a tight 300 Hz refresh rate will jitter or misbehave if you feed it 50 Hz pulses, and vice versa. The library handles this for you — you just need to know the pulses are there, in the background, while your loop() runs.
Tiny preview of next lesson's code
You won't write the timing — you'll write this:
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9); // signal pin
myServo.write(90); // centre
}
void loop() { }That tiny sketch is generating the 1.5 ms-every-20 ms signal we just drew, in the background, while doing nothing else. Two lines of setup; the library does the work.
Basic 5 min
No wiring today. Write your answers in your notebook, then reveal one at a time.
You receive a mystery servo. The three wires are blue, red, white. Which is signal, which is power, which is ground?
Challenge 1 5 min
An SG90 gets a steady 1.7 ms pulse every 20 ms. What angle does it sit at, approximately?
Challenge 2 5 min
You want a servo to hold up a 200 g toy car on a 4 cm arm so you can lift it like a tiny crane. What stall torque do you need at minimum, and which classroom servo would you pick?
A student plugs an SG90 in with the connector flipped — power and ground are swapped, signal is still on the right pin. What's most likely to happen on power-up?
You buy "SG90" servos on a marketplace. The lid says SG90, but one of them keeps spinning slowly forever when you command 90°. What kind of servo did you actually receive, and how does its "90°" command differ from the standard one?
Challenge 3 · Pick the servo for three real builds 15 min
For each scenario, pick one of the three classroom servos (SG90, MG90S, S3003) and justify your choice in 2–3 sentences. Use the torque table from §3 and the current-budget rules from L02's power lessons.
A phone camera (180 g) is mounted 6 cm from the servo's shaft. The servo must pan smoothly through 180° on demand. You'll use a 4 × AA pack for the servo's 5 V rail.
A printed paper dial behind a lightweight (1 g) cardboard arrow. The needle is glued to the servo horn; it must sweep 0° (empty) to 180° (full) in response to a sensor reading.
A 5-cm latch arm presses a spring-loaded clasp closed. The clasp takes about 0.5 kg of force to compress.
Recap 5 min
A hobby servo is a self-contained closed-loop position system: motor + gears + pot + control board, all controlled by a pulse-position signal at ~50 Hz. The pulse width — 1.0 to 2.0 ms — sets the angle. Three wires: red is +5 V (always in the middle), brown/black is GND, the third colour is signal. Three classroom servos cover most projects: SG90 for weightless / decorative, MG90S for sturdier robotics, S3003 for real torque. Next lesson you stop drawing the signal and start commanding it — meet the Servo library.
- Servo motor
- A small motor with an internal position sensor and controller, commanded to specific angles by a timed pulse signal. "Hobby servo" is the small (9 g–40 g), 5 V, 3-wire family.
- Pulse-position modulation
- A control scheme where the width of a recurring pulse — not its amplitude or frequency — carries the command. Hobby servos use 1.0 ms (0°) to 2.0 ms (180°) at a 20 ms period.
- Stall torque
- The maximum rotational force the servo can apply before it gives up and stops. Measured in kg·cm (or oz·in). A 2 kg·cm servo can hold 2 kg hanging from a 1 cm arm, or 1 kg from a 2 cm arm.
- Pulse period (refresh rate)
- How often a fresh pulse arrives at the servo. 20 ms = 50 Hz for analog servos; digital servos can refresh faster.
- Continuous-rotation servo
- A modified servo with the pot disconnected and the end-stops removed — its pulse width sets speed, not angle. Useful as a cheap gearmotor; confusing if you didn't expect one.
- Closed loop
- Any control system that compares a measurement (here: the pot voltage) to a target and corrects until they match. Open-loop = command and hope.
- Servo horn
- The plastic or metal arm that fits onto the servo shaft and transmits motion to whatever you're moving. Comes in single-arm, double-arm, cross and round shapes.
Extra Mission 5 min
Part 1 — Design a servo helper for home or school
Pick one small job that needs something to turn to a set angle. Ideas: a flag that pops up when post arrives, a pet-food flap, or a weather pointer. On paper, design a servo gadget that does it.
Your design must include:
- The job, in one sentence.
- The two angles it moves between, for example 0° closed and 90° open.
- Which servo you pick (SG90, MG90S or S3003), with the torque sum that proves it is strong enough.
- A drawing of the three wires, showing which colour goes to signal, +5 V and GND.
Part 2 — Make it
Wire an SG90 to your UNO: brown to GND, red to 5V, orange to D9. Upload the preview sketch from the Worked Example. Then change it so the servo moves between the two angles in your design. It should wait 2 seconds at each angle, forever.
Use only the calls in the preview: attach(), write() and delay(). If the horn hits something, change your angles, not the horn.
Bring back next class: your design, your uploaded sketch, and a photo of the horn at each angle.