Wiring guide

How to wire a servo to a Raspberry Pi Pico

To wire a servo to a Raspberry Pi Pico, connect GND to GND, VCC to VBUS (5 V from USB) and PWM to GP16 (physical pin 21). The servo takes 5 V on its power wire, while the signal wire comes from a 3.3 V pin, which an SG90 reads as high without a level shifter. The sketch below uses the Servo (Servo.h) library. It sweeps the horn from 0 to 180 degrees and back, printing a line at each end.

  • 3.3 V logic
  • Library: Servo.h
  • 3 wires
Raspberry Pi Pico · servolive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

Servo to Raspberry Pi Pico wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

Servo pinRaspberry Pi Pico pinWire colorWhy
Brown (GND)GNDblueThe signal is measured against this, so it must be shared with the board.
Red (V+)VBUS (5 V from USB)redAn SG90 wants 4.8 to 6 V. At 3.3 V it barely moves, so it takes the 5 V rail, not 3V3.
Orange (signal)GP16 (physical pin 21)amberAny GP pin; the RP2040 has a PWM slice behind every one.
Voltage

Power and logic levels for servo and Raspberry Pi Pico

Logic level

The Raspberry Pi Pico’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The servo takes 5 V from VBUS (5 V from USB). That is the Raspberry Pi Pico’s 5 V rail, so the part shares the current the board can supply.

This pair

The servo runs from VBUS (5 V from USB) while its signal comes from a 3.3 V pin. That works: an SG90 reads anything above about 2 V as high, so no level shifter is needed. On a real bench, a servo under load can pull more current than USB gives; then power it from its own 5 V supply and join the grounds.

Pins to leave alone

The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.

The sketch

The working code for the Raspberry Pi Pico

Library: Servo (Servo.h). This is the sketch the circuit above runs.

Servo sweep on Raspberry Pi Pico GP16 (physical pin 21)
#include <Servo.h>

const int SERVO_PIN = 16;   // signal, GP16 (physical pin 21)
Servo servo;

void setup() {
  Serial.begin(115200);
  servo.attach(SERVO_PIN);        // 544 to 2400 us, 50 times a second
  Serial.println("Sweeping");
}

void loop() {
  for (int angle = 0; angle <= 180; angle += 2) {
    servo.write(angle);
    delay(15);
  }
  Serial.println("at 180");
  for (int angle = 180; angle >= 0; angle -= 2) {
    servo.write(angle);
    delay(15);
  }
  Serial.println("back at 0");
}
Output

What you should see

The servo horn turns from 0 to 180 degrees in about 1.4 seconds and then back. The serial monitor, at 115200 baud, prints Sweeping once, then at 180 at the top of each sweep and back at 0 at the bottom.

A servo that buzzes or does not move is almost always a missing common ground or a supply that sags under load.

The serial monitor prints this, recorded from the circuit above running for two and a half seconds:

Sweeping
at 180
Pitfalls

Common mistakes wiring a servo to a Raspberry Pi Pico

Powering the servo from 3V3

The Raspberry Pi Pico’s 3.3 V regulator is sized for the chip, not a motor, and an SG90 at 3.3 V jitters or stalls. The red wire goes to VBUS (5 V from USB).

Forgetting the common ground

With the servo on a separate supply and only the signal wire to the board, the servo has nothing to measure the pulse against and twitches at random. Connect the supply’s ground to the board’s GND.

Counting physical pins instead of GP numbers

The sketch says 15, which means GP15, and that is physical pin 20 on the header. Counting 15 pins down the side lands on a different GPIO, and the part never answers.

Build your own servo project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.