EngineeringMaker LabKits

Build guide

Featured project

Servo Motor Control

Learn how timed pulses represent position. You will wire a servo with a shared ground, generate a 50 Hz PWM signal, convert angles into pulse widths, and avoid common power problems.

Last updated

Build Time
40-60 minutes
Estimated Cost
$12-$22
Skill Level
Easy
Raspberry Pi PicoRaspberry Pi PicoPWMServoMotion
  • Middle School
  • High School
  • Adult Beginners
  • Homeschool

Skills

What You'll Learn

  • Understand pulse width control for hobby servos
  • Generate PWM with MicroPython
  • Share ground between control and power circuits
  • Recognize symptoms of an undersized power source

Preparation

Required Parts

Gather these components before starting the build.

  • Qty: 1Raspberry Pi PicoMicroPython installed
  • Qty: 1SG90 micro servo5 V hobby servo
  • Qty: 1BreadboardFor power distribution
  • Qty: 3Jumper wiresSignal
  • Qty: 1Regulated 5 V supplyRecommended for reliable motion

Wiring

Circuit Diagram

The servo signal wire connects to GP16. Servo power uses regulated 5 V, and the external supply ground must connect to Pico GND.

Build

Step-by-Step Instructions

Work through each stage in order and disconnect power before changing the wiring.

1. Connect a common ground

Connect the external 5 V supply ground to both the servo ground and a Pico GND pin. A common reference is required for the control pulse.

2. Wire power and signal

Connect servo power to regulated 5 V and its signal wire to GP16. Check the servo manufacturer’s wire colors before applying power.

3. Upload the sweep program

Run the code with the servo horn unobstructed. It should move through 0, 90, 180, and back to 90 degrees.

4. Calibrate safe limits

If the servo strains near either end, narrow the pulse range in set_angle until motion is smooth and quiet.

Programming

Project Code

Upload servo-sweep.py after completing the circuit.

servo-sweep.pypython
from machine import Pin, PWM
from time import sleep

servo = PWM(Pin(16))
servo.freq(50)

def set_angle(angle):
    pulse_us = 500 + (angle / 180) * 2000
    duty = int(pulse_us * 65535 / 20000)
    servo.duty_u16(duty)

while True:
    for angle in (0, 90, 180, 90):
        set_angle(angle)
        sleep(1)

Problem solving

Troubleshooting

The servo jitters or resets the Pico

Use a separate regulated 5 V supply for the servo and connect its ground to Pico ground.

The servo moves in the wrong direction

Swap the angle values in your sequence; direction depends on the order of commanded positions.

The servo buzzes at an endpoint

Reduce the minimum or maximum pulse range so the horn is not driven against its mechanical stop.

Common questions

FAQ

Can the Pico power the servo directly?

A tiny unloaded servo may move

Why is PWM set to 50 Hz?

Standard analog hobby servos typically expect one position pulse about every 20 milliseconds.

Can I control two servos?

Yes

Go deeper

Related Tutorials and Resources

Project complete

Ready for Ultrasonic Distance Sensor?

Measure distance with an HC-SR04 sensor and display live readings in centimeters.

Reuse your kit

More projects you can build with this kit

Keep using the SunFounder Raspberry Pi Pico Ultimate Starter Kit instead of starting with a new parts list.