ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Raspberry Pi & IoT Engineering• 6 min read

Controlling Hardware with GPIO Zero

Control physical LEDs, buzzers, relays, and pushbuttons using Python and the beginner-friendly gpiozero library.

Blinking an LED with gpiozero

from gpiozero import LED; led = LED(17); led.blink() handles software PWM and pin management with clean Python syntax.

Blinking an LED with GPIO Zero
from gpiozero import LED, Button
from signal import pause

led = LED(17)
button = Button(2)

button.when_pressed = led.toggle

print("System active. Press button to toggle light.")
pause()
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which modern, Pythonic library is recommended by the Raspberry Pi Foundation for interacting with GPIO pins?