The Servo Motor

Learn to control a mechanism by turning a servo motor to a specific angle.

LESSON COMPASS

What will you use this page for?

Core idea

A servo motor is a motor that turns to a specific angle we ask for (usually somewhere between 0 and 180 degrees) and then holds that position, which makes it useful for moving an arm, a lid or a steering part with precision.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Thinking a servo spins continuously A servo does not make full turns; it only moves within a certain angle range (usually 0–180 degrees). If you want a wheel to keep spinning, you need a DC motor, which we will meet in the next lesson, not a servo. Forcing it past 180 degrees Giving the servo an out-of-range value…

Next connection

The DC Motor and Motor Driver: We will meet motors that spin continuously and see why we need a motor driver to run them safely.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration30–45 min
PrerequisiteThe Humidity Sensor
ContentStandard lesson · 1,631 words
Last updated

One-sentence summary

A servo motor is a motor that turns to a specific angle we ask for (usually somewhere between 0 and 180 degrees) and then holds that position, which makes it useful for moving an arm, a lid or a steering part with precision.

Why does this matter?

So far, sensors taught us how to *measure* the world. The humidity sensor could tell us whether the soil was dry or wet. But measuring on its own is not enough. A robot has to *do* something with what it measures. This is where the word actuator comes in: an actuator is the part that turns an electrical signal into movement. A servo motor is one kind of actuator.

We use servo motors in everyday life without noticing. The part that turns the steering of a remote-control car, bends the wrist of a robot arm or opens and closes a toy dinosaur's mouth is often a small servo motor. A sensor tells us "what is happening"; a servo motor is one of the ways a robot shows us "what it will do about it."

This lesson is our first real step from measuring to moving.

What does a servo motor do?

It turns to a specific angle

Think about an ordinary motor: when you switch it on, it spins and spins and spins, like a fan or a wheel. A servo motor is different. If you tell a servo "go to 90 degrees," it turns to exactly 90 degrees and stops there. If you say "go to 0 degrees," it returns to its starting position.

Most educational servos move between 0 and 180 degrees. That means they can sweep about half a circle, but they cannot make a full turn.

You can picture it like a door handle:

Whatever angle you choose, the servo goes there and tries to stay there until you send a new command.

What is inside? (a simple idea)

If we opened up a servo's case, we would find:

This circuit keeps asking one question: "What angle was I asked for, and what angle am I at now?" If the two are different, it turns the motor a little in the right direction. When they match, it stops. This is why a servo can find the angle you want and hold it. We call this a closed-loop system, meaning a system that keeps checking itself.

How do we control a servo?

We talk to it with a signal (the idea)

A servo has three wires:

We tell the servo which angle we want by sending short electrical pulses down the signal wire. The board sends a small pulse about 50 times per second. The length of that pulse decides the angle. This way of setting an angle by changing the pulse length is called PWM (pulse width modulation).

Roughly:

Here is the good news: we do not have to work out these pulses by hand. Boards like the micro:bit or Arduino have ready-made commands that do this for us. We simply write the angle we want.

Example code: move an arm

Suppose we attach a cardboard arm to the servo and want to wave it between two positions. Let's write the idea as pseudocode first:

Start
Repeat forever:
  Send the servo to 0 degrees
  Wait 1 second
  Send the servo to 180 degrees
  Wait 1 second

The same idea in Arduino style looks like this:

#include <Servo.h>
Servo arm;              // we named our servo "arm"

void setup() {
  arm.attach(9);        // servo signal is on pin 9
}

void loop() {
  arm.write(0);         // go to 0 degrees
  delay(1000);          // wait 1 second
  arm.write(180);       // go to 180 degrees
  delay(1000);          // wait 1 second
}

The logic of the code matches the pseudocode exactly: go to one angle, wait, go to the other angle, wait, repeat.

Example: open a lid based on a sensor

Robotics really begins when we combine the servo with the sensors from earlier lessons. For example, here is a simple rule that opens a box lid when someone comes close:

Start
Repeat forever:
  Read the distance
  If the distance is less than 15 centimetres
    Send the servo to 90 degrees   (lid open)
  Otherwise
    Send the servo to 0 degrees    (lid closed)

Here the sensor *measures* and the servo *moves* based on that measurement. This whole module is really about joining those two ideas together.

Mini practice

For this activity you need a servo motor, a micro:bit or Arduino, a few jumper wires and a piece of cardboard. Do it together with an adult.

  1. Connect the servo's signal wire to a pin on the board, and its plus and minus wires to a suitable power connection.
  2. Tape a small piece of cardboard to the tip of the servo; this will be your "arm."
  3. Write a program that sends the servo to 0 degrees, then 90 degrees, then 180 degrees. Wait 1 second between each angle.
  4. Watch whether the arm goes to exactly the same three positions each time.
  5. Now change the angles: 0, 45, 90, 135, 180. How did the movement change?

Write this in your notebook: when you gave the arm an angle, did it go where you expected? If not, remember that this is a "debugging" question we will explore in the next lessons.

Common mistakes

Thinking a servo spins continuously

A servo does not make full turns; it only moves within a certain angle range (usually 0–180 degrees). If you want a wheel to keep spinning, you need a DC motor, which we will meet in the next lesson, not a servo.

Forcing it past 180 degrees

Giving the servo an out-of-range value such as write(200) does not work and can strain the motor. Keep values between 0 and 180.

Powering the servo straight from a board pin

Even a small servo can pull more current while moving than a board pin can safely give. This can freeze or restart the board. Use the board's proper power connection or a separate low-voltage battery pack for power.

Powering the servo while attaching the arm

If you turn the servo by hand while it is powered, your finger could get pinched and the gears could be damaged. Attach the arm first, then switch the power on.

Safety note

A servo motor is a moving part. Even though it is small, we still follow safety rules:

Lesson summary

Check questions

  1. What is the main difference between a servo motor and an ordinary motor that spins continuously?
  2. What angle range do most educational servos move within?
  3. Through which wire, and how (conceptually), do we tell a servo the angle we want?
  4. Why should we not power a servo directly from a board pin?
  5. When we combine a sensor with a servo, what job does each one do?

Answers

  1. An ordinary motor spins continuously when switched on; a servo goes to a specific angle and stops there.
  2. Usually between 0 and 180 degrees, which is about half a circle.
  3. Through the orange/yellow signal wire, using short electrical pulses. The length of the pulse sets the angle; this is called PWM. The board produces these pulses for us.
  4. While moving, a servo can pull more current than a board pin can give, which may restart or damage the board. So we use a proper power connection or a separate low-voltage source.
  5. The sensor measures the environment (for example, distance), and the servo moves based on that measurement (for example, opening the lid).

Source and verification note

For “The Servo Motor”, verification focuses on whether the relationship between Why does this matter? and It turns to a specific angle remains consistent across examples. Sensor readings can change with the model, supply voltage and environment. Thresholds in the lessons are therefore examples; a real project should use a measurement table and calibration.

Next lesson

The DC Motor and Motor Driver: We will meet motors that spin continuously and see why we need a motor driver to run them safely.

Start QuizBack to Sensors and Actuators
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.