Servo Motors
Overview
Use the Servo library to move a positional servo through a sequence of angles.
Builds on
Before You Start
Test this servo separately from the motor-driver circuit. Confirm the servo model, usable angle range, and suitable supply with Mr. Willis.
Materials
- Arduino Uno R3, USB cable, and Arduino IDE with Servo library
- Positional servo, male-to-male jumper wires, and an approved servo supply
Safety
Disconnect power before rewiring
Unplug Arduino USB and disconnect or switch off every other supply before changing wires. Check polarity and connections before restoring power.
You've got it when…
- The servo moves through the requested positions without binding.
- Your notebook contains the actual wiring/supply table and complete final code.
Collaboration & AI
Compare observations and troubleshoot with classmates. Each student must understand the wiring or design and prepare their own submission.
AI — AIAS Level 1, No AI: Complete the code or design yourself without AI assistance. AI Assessment Scale
Servo Motor Overview
A positional servo motor moves to an angle and holds it, rather than spinning continuously like a DC gearmotor. Many classroom servos cover roughly 0° to 180°, but the usable range depends on the model.
Inside are a DC motor, gears, a position sensor, and a control circuit. This feedback system checks the shaft position and adjusts the motor to reach the requested angle. The Arduino sends timed pulses along the signal wire; pulse width specifies the position. This is different from controlling motor speed with analogWrite().
Wiring
-
Disconnect all power and wire the servo using male-to-male jumper wires and the table below. Use the Arduino Pinout to locate pin
3andGND.Servo wire Connection Orange (signal) Arduino pin 3 Red (power) Teacher-approved servo supply within the servo’s voltage rating Brown (ground) Supply ground, shared with Arduino GND Choose the servo supply with Mr. Willis
Use an external supply with voltage and current capacity suitable for the actual servo. Connect its ground to Arduino
GND, but do not connect its positive output to the Arduino5Vpin while USB is connected.A small, unloaded servo may be tested from Arduino
5Vonly with teacher approval. Servo startup or stall current can exceed what the board can supply. Do not connect a servo directly to an unspecified battery pack: excess voltage can damage it. A suitable separate supply avoids overloading the Arduino; it does not justify exceeding the servo's rated voltage.
Code
The Arduino Servo library handles the pulse timing. A library is reusable code that provides functions for a particular task. There are many Arduino libraries. If Servo.h is unavailable in your installation, install the official Servo library through the IDE's Library Manager.
-
Start a new sketch and put this include directive at the very top:
-
Below it, declare the signal pin and create a
Servoobject. The namemyservoidentifies this servo; names such asleftServoorflagServocan describe its purpose in a robot. -
Attach the object to the signal pin in
setup(): -
Add this
loop()to request positions in 45-degree increments, pausing half a second at each position. -
Have the supply and wiring checked, keep the horn free of obstructions, then power and upload. Verify the position sequence. If the servo binds, buzzes continuously at an endpoint, or becomes hot, disconnect power and ask Mr. Willis to check the usable angle range.
Combining this with the motor lab
On an Uno R3, the Servo library uses a timer that disables PWM from
analogWrite()on pins9and10. The motor-driver lab uses pin10, so those examples cannot be combined unchanged. This servo lab is a separate circuit. Servo library documentation -
Copy the wiring table into your notebook, identifying the actual approved supply, and paste your complete final code.
Turn It In
- Submit the following notebook entry:
- Notebook entry: wiring table identifying the approved supply, and complete final Arduino code
How It's Graded
One score from 0–4 covers the required work and evidence. Verification may be shown during the lab; the required uploads are listed above.
| Score | Evidence |
|---|---|
| 4 Excellent | The complete code and actual wiring/supply table agree; the servo position sequence is verified without binding or power problems. |
| 3 Above Average | The servo operation, final code, and wiring table are complete and working, with only minor errors or omissions in clarity or verification. |
| 2 Average | The servo operation, final code, and wiring table have significant gaps, errors, or missing evidence. |
| 1 Below Average | The required work is largely incomplete or nonfunctional, with little usable evidence. |
| 0 Failing | No submission or no evidence of the required work. |
Converted from the original lab.