Built-in project · Raspberry Pi Zero 2 W

Blink an LED with RPi.GPIO on a Raspberry Pi Zero 2 W

RPi.GPIO on a Raspberry Pi Zero 2 W: an LED on GPIO17 blinks twice a second, and the Serial Monitor counts every four blinks. The whole build, a Raspberry Pi Zero 2 W 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 $18.15. On Mokxi they're free.

Blink an LED with RPi.GPIO · Raspberry Pi Zero 2 Wlive0.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 Zero 2 W
# Blink an LED with RPi.GPIO on a Raspberry Pi Zero 2 W.
# The Zero's 40-pin header is a Pi 4's, pin for pin: the LED's long leg goes
# to GPIO17 (header pin 11) through a 330 ohm resistor, its short leg to
# ground (pin 9).
import RPi.GPIO as GPIO
import time

LED = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)

count = 0
try:
    while True:
        GPIO.output(LED, GPIO.HIGH)
        time.sleep(0.25)
        GPIO.output(LED, GPIO.LOW)
        time.sleep(0.25)
        count += 1
        if count % 4 == 0:
            print(count, "blinks")
except KeyboardInterrupt:
    GPIO.cleanup()

Parts list

4 parts, plus the jumper wires. They retail for about $18.15; 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 Zero 2 W pin GND; LED, green pin C
  • Raspberry Pi Zero 2 W pin GPIO17; Resistor, 330 Ω pin 1
  • Resistor, 330 Ω pin 2; LED, green 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.