Unit C - Actuators & Displays

13. Servo Motors

Command and safely power a closed-loop position actuator.

Estimated time 3 hours

Learning outcomes

  • Describe a hobby servos motor, gears, sensor and controller
  • Relate pulse width to requested angle
  • Use Servo.h
  • Provide a suitable external supply

Parts and preparation

Uno, small hobby servo, 10 k ohm potentiometer and regulated 5-6 V supply.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

Libraries for this lesson

In Arduino IDE 2 open Tools → Manage Libraries…. Search by the Library Manager name and install the package by the exact author below. Similar names from other authors can use different APIs and will break the example.

IncludeLibrary Manager nameAuthorInstall note
Servo.hServoArduinoBuilt-in with Arduino AVR Boards. No Library Manager install required.
Servo Motors instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

Closed-loop actuator

A servo compares the requested position with feedback from an internal potentiometer and drives its geared motor to reduce the error.

Control signal

Typical position pulses repeat about every 20 ms. Around 1 ms, 1.5 ms and 2 ms usually represent one end, centre and the other end, but exact limits vary.

Power

Servo current rises while moving and can be very high when stalled. Use a regulated external supply sized for the servo and always join grounds.

Wiring and safe build sequence

Breadboard wiring for lesson 13: Servo Motors
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. Servo signal -> D9
  2. Servo red -> external regulated +5 V
  3. Servo brown/black -> external GND
  4. External GND -> Uno GND
  5. Pot wiper -> A0; outer legs -> 5 V/GND
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
#include <Servo.h>

Servo arm;

void setup() {
  arm.attach(9);
}

void loop() {
  int raw = analogRead(A0);
  int angle = map(raw, 0, 1023, 10, 170);
  arm.write(angle);
  delay(15);
}

How the code works

  1. The 10-170 degree limits reduce the risk of driving against mechanical end stops.
  2. write requests a position; it does not confirm the shaft reached it.

Test and record evidence

Expected result: The servo follows the potentiometer smoothly over a safe range.

Practical evidence checklist

Common faults and checks
  • Resetting or jitter usually indicates weak power or missing common GND.
  • Disconnect the mechanical load while testing limits.
Extension challenge: Add two calibrated angle limits and print the requested angle.

Check your understanding

Q1. Why is a servo closed-loop?

Show answer

It uses internal position feedback to correct its shaft position.

Q2. Why use external power?

Show answer

Movement and stall current can exceed the Uno regulator/USB capability.