Hardware & cameraFreeRaspberry Pi OS

gpiozero

The friendliest way to control LEDs, buttons, motors, sensors and robots from Python. Pre-installed on Raspberry Pi OS.

What you use it for

  • LEDs, buttons and buzzers
  • Motors, servos and robots
  • Distance, motion and light sensors

Commands

See your Pi's header in the terminal
pinout
Blink an LED on GPIO17
python3 -c "from gpiozero import LED; from signal import pause; LED(17).blink(); pause()"

Pro tips

  • Pins use GPIO (BCM) numbers, not physical pin numbers.
  • Classes like Robot, DistanceSensor and AngularServo save dozens of lines.