Skip to content
RoboLearn
Not completed

Servo motors

What you’ll learn

  • How a servo holds an exact angle
  • How to control one with the Servo library
  • How to power several servos safely

Inside a servo

A hobby servo (like the SG90) contains a small DC motor, a gearbox, a potentiometer that measures the output angle, and a control circuit. You tell it an angle; it drives the motor until the potentiometer says it’s there, then holds. That’s closed-loop control in one small box.

The signal

Servos read a pulse sent about 50 times a second. The pulse width sets the angle: roughly 1 ms → one end, 1.5 ms → middle, 2 ms → other end (many servos accept about 0.5–2.5 ms for their full 0–180° travel). The Servo library makes the pulses for you:

#include <Servo.h>
Servo s;
s.attach(9); // signal on pin 9
s.write(90); // go to 90°

Wires

Wire colour (usual) Connect to
Brown or black GND
Red 5 V (servo power)
Orange or yellow Signal pin

Power

One small SG90 can run from the Arduino’s 5V pin when it isn’t loaded. Several servos, or larger ones, need their own 5–6 V supply (with grounds connected), or the Arduino will reset when they move.

Continuous rotation servos

Some servos are modified to spin all the way round. For these, write(90) means stop, lower values spin one way and higher values the other.

Finished this lesson?