PyRasp

← All practice problems

Raspberry Pi Pico practice problem · Raspberry Pi Pico

Servo sweep

MediumBudget $10MicroPython

An SG90 servo is wired to the Pico: signal on GP12, power on VBUS (5 V) and ground on GND. Its angle follows the pulse width, at 50 Hz:

  • 0.5 ms → 0°
  • 1.5 ms → 90° (the middle)
  • 2.5 ms → 180°

Turn it to 0°, wait 1 s, then turn it to 180° and wait. Use PWM at 50 Hz: PWM(Pin(12), freq=50) and duty_ns(500_000) / duty_ns(2_500_000).

More in Raspberry Pi Pico