Built-in project · Raspberry Pi 4 Model B

Blink an LED with gpiozero on a Raspberry Pi 4

The first program on a Raspberry Pi 4: an LED on GPIO17 blinks once a second, in Python with gpiozero, and print() shows each change. The whole build, a Raspberry Pi 4 and 2 more parts, runs here in your browser on the Python below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

The parts retail for about $58. On Mokxi they're free.

Blink an LED with gpiozero · Raspberry Pi 4 Model Blive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The Python exactly as the editor opens it. Change a line there and press Run: the board runs main.py in a Python engine in the page, with gpiozero and RPi.GPIO, and nothing to compile.

main.py · Raspberry Pi 4 Model B
# Blink an LED with gpiozero on a Raspberry Pi 4.
# The LED's long leg goes to GPIO17 (header pin 11) through a 330 ohm resistor,
# its short leg to ground (pin 9).
from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    print("on")
    sleep(1)
    led.off()
    print("off")
    sleep(1)

Parts list

4 parts, plus the jumper wires. They retail for about $58; on Mokxi they're free.

How it is wired

3 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Raspberry Pi 4 Model B pin GND; LED, red pin C
  • Raspberry Pi 4 Model B pin GPIO17; Resistor, 330 Ω pin 1
  • Resistor, 330 Ω pin 2; LED, red pin A

Change it and keep it

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