Let's think about it this way for a moment
gpiozero is a beginner-friendly library for controlling the Raspberry Pi's GPIO from Python (its syntax is simpler than RPi.GPIO) — it comes preinstalled on Pi boards. Import the LED class, pass it a pin number (BCM), and you get an LED object — just call methods like .on(), .off(), and .blink() to control the physical LED.
Let's connect this to a real-world scenario
Import with from gpiozero import LED, then led = LED(17) declares BCM pin 17 as GPIO 17 — call led.on() and the LED lights up, led.off() and it turns off, and led.blink() and it blinks continuously (you can adjust the speed with the interval parameter).
Let's look at an example together
from gpiozero import LED
from time import sleep
led = LED(17) # BCM pin 17
# Simple on/off
led.on()
sleep(1)
led.off()
# Built-in blink (0.5s on, 0.5s off, repeating)
led.blink()
# Keep the script running so blink() continues
from signal import pause
pause()You'll see the physical LED turn on for 1 second, turn off, and then blink continuously.5-Minute Try-It
If your LED is already wired up (from the previous lesson), write your own gpiozero script and run through on/off/blink.
A quick word of caution
When you stop a script with Ctrl+C, the GPIO state (if the LED was on) can remain stuck — gpiozero handles cleanup automatically, but if you're using the RPi.GPIO library, you'll need to call GPIO.cleanup() manually.