All tutorials

3 · Outputs & actuators

Drive a servo motor

Intermediate18 min

Goal

Sweep a servo from 0° to 180° and back.

Why it matters

The servo reads pulse width (1 to 2 ms): that is position modulation.

Steps

  1. 01Add a servo motor on pin 9.
  2. 02Sweep the angle from 0 to 180 with a for loop.
  3. 03Leave 15 ms between each degree so the arm can follow.
  4. 04Do the return trip.

This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.

Next tutorials