Robotics & Arduino
Lesson 2 · Refinement

Let’s spin!

Our servo’s “hello world”: test its movement and calibrate its range.

Angles and pulses.

For this lesson, we use a positional servo with a nominal range of 0° to 180°.

The Arduino Servo library’s default pulse range is 544 to 2400 microseconds (µs).

These numbers describe how long the signal stays HIGH. They are not the 0–255 PWM values we used for LED brightness.

Library defaults are not a guarantee of a particular motor’s travel. Arduino Servo library reference ↗

Why calibrate manually?

Low-cost hobby servos can vary. Their potentiometer, motor, gears, and control electronics are not all identical.

So 544 µs may not mean exactly 0°, and 2400 µs may not mean exactly 180°.

How do we find out? Move it in small steps and watch what happens.

Print the pulse width to the Serial Monitor. Compare the command with the movement, then adjust the limits in our code.

Serial shows the command we sent. A normal three-wire servo does not report its measured position back to Arduino.

500? 2500? Those are guesses.

Below 544, we could imagine 500 µs.
Above 2400, we could imagine 2500 µs.

They are possible test limits, not a range to sweep blindly. Our particular servo may reach its mechanical stop much earlier.

Use the servo’s specified range. Begin near its center — commonly 1500 µs — and approach each end in small steps. If it stops moving or strains or buzzes at the end, back off immediately.

Keep the usable limits we actually observe. Do not force the motor to reach an assumed 180°.

Meet our fifth code segment: INCLUDE.

Notice the new line:

#include <Servo.h>

This includes the library’s C++ header, making its declarations available to our program.

Welcome to the fifth segment of our Arduino code!

INCLUDE → DECLARE → INIT → RUN → LOGIC

One task. Three ways to write it.

1 — Basic.
Set a pulse, observe, and adjust.

2 — A loop with a direction flag.
Use a variable to decide which way to step.

3 — A for loop.
Let the loop manage the small steps.

We’ll build each version next.