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 a $3 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.
Try It Yourself · Five paper questions 15 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?
Reveal
Red is the middle wire of the connector, so it's +5 V (this convention is universal). Of the other two, signal is the lighter-coloured / odd-coloured one in the convention — here white is on the "signal" end. So blue = GND, red = +5 V, white = signal. If you're unsure, look at the connector — the colour with no other match is signal.
An SG90 gets a steady 1.7 ms pulse every 20 ms. What angle does it sit at, approximately?
Reveal
The pulse width maps linearly: 1.0 ms = 0°, 2.0 ms = 180°. So 1.7 ms is 70% of the way from 1.0 to 2.0, which is 70% × 180° = ~126°. (The official mapping is approximate — different SG90s vary by ±5°.)
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?
Reveal
Torque = force × distance. 200 g = 0.2 kg, arm = 4 cm. Torque required = 0.2 × 4 = 0.8 kg·cm. Doubling that for a safety margin gives 1.6 kg·cm. The SG90 (1.8 kg·cm) is marginal; the MG90S (2.2 kg·cm) is more comfortable; the S3003 (3.2 kg·cm) is overkill but smooth. Pick MG90S — affordable, sturdy enough, metal gears survive accidental over-rotation.
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?
Reveal
The internal regulator on a cheap servo usually has no reverse-polarity protection. The motor doesn't turn (it's reverse-biased), the control IC tries to run on −5 V, and within a few seconds you may smell the IC failing. Some students get lucky and the servo just doesn't do anything until they fix it; many don't. Always check polarity twice on a 3-wire connector.
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?
Reveal
You received a continuous-rotation servo (sometimes labelled SG90R or FS90R) that's been mislabelled as a positional SG90. On a CR servo, the pulse width sets the speed, not the angle: 1.5 ms = stop, 1.0 ms = full speed one way, 2.0 ms = full speed the other. Commanding 90° (which the library translates to a 1.5 ms pulse) should mean "stop", but the neutral point is rarely exact, so a CR servo drifts. The clue: the servo doesn't have hard end-stops at 0° and 180° — you can keep turning the horn by hand forever.
Mini-Challenge · 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.
Reveal one good choice
Required torque = 0.18 kg × 6 cm = 1.08 kg·cm. Add a 2× safety margin → 2.2 kg·cm. The MG90S hits exactly that, costs the same as an SG90, and the metal gears survive accidental knocks against the phone case. The S3003 also works but is heavier (37 g) and noisier — overkill for a phone.
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.
Reveal one good choice
The load is essentially weightless. Torque demand is < 0.05 kg·cm. The SG90 is perfect — cheap, quiet, and the plastic gears never see real force. Save your metal-gear servos for jobs that need them.
A 5-cm latch arm presses a spring-loaded clasp closed. The clasp takes about 0.5 kg of force to compress.
Reveal one good choice
Torque = 0.5 kg × 5 cm = 2.5 kg·cm. Plus a 2× safety margin = 5 kg·cm. The S3003 is the only one of the three with enough torque (3.2 kg·cm — still marginal but workable if the latch isn't a worst-case fit). For a really stiff clasp, look at MG996R (a metal-gear, 10 kg·cm step up that's common in robotics kits). This is also a hint about why Level 3 introduces external motor drivers (L03-08): once you cross 1 A continuous current draw, you outgrow the UNO's 5 V regulator.
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.
Homework 5 min
Open one up (optional but recommended). If you have a broken or surplus SG90 — or a teacher does — unscrew the four case screws and look inside. You should be able to spot the four parts you read about today: the small DC motor, the gear train, the pot at the base of the output shaft, and the tiny green control board. Take a photo for class.
Required exercises:
- Re-draw the 90° servo waveform from §4 from memory in your notebook. Label the pulse width and the period.
- Find one product around your house that almost certainly uses a hobby-class servo. Common candidates: small robot toys, RC cars, the camera assembly inside some webcams, locks on hotel-room safes. Photograph it and bring the photo.
- Skim L02-26 (Smart Bin Lid) again. Tomorrow we revisit the same
Servo.hsketch with the new vocabulary — you should find it makes much more sense the second time.
Bring back next class:
- Your re-drawn waveform.
- Your product photo + a one-sentence guess at why the designer chose a servo there (rather than a DC motor or a stepper).
- Your SG90 with horn detached — we'll re-fit it together at the start of L03-02.