led_blink.py

Raspberry Pi Model B Revision 2 (2012) — Board Sheet · File : led_blink.py · Language : Python · Use case : Faire clignoter une LED pour tester une sortie GPIO et l'environnement gpiozero

The classic first GPIO build: an LED with a 330-ohm resistor blinks once per second via gpiozero. The script imports LED, targets GPIO17 (pin 11) and toggles it in a loop. Ideal to check the power supply (révision 2 : alimentation micro-USB/OTG soignée, connecteur 26 broches (pas de 40 broches)) before a bigger project.

Hardware

A Raspberry Pi Model B revision 2 (BCM2835, 26-pin GPIO header, Ethernet/USB ports moved to the board edge). One red LED, a 330-ohm resistor, dupont wires (26-pin header).

Wiring

LED anode (long leg) to GPIO17 through the resistor, cathode to any GND pin of the P1 connector.

How it works

gpiozero sets the pin as output; led.on/off drive it to 3.3 V or 0 V. KeyboardInterrupt cleans up on exit.

Running it

Copy the script to the board (scp or USB stick), then run it with python3 (or bash). On Raspbian, install gpiozero with sudo apt install python3-gpiozero. The full 26-pin pinout is in the official Raspberry Pi schematic.

Variants

Use led.blink(0.2, 0.8) for an asymmetric pattern; chain several LEDs for a scroller. Revision 2: a clean 5 V supply is required; brown-outs distort sensor readings.

led_blink.py

# led_blink.py — fait clignoter une LED via gpiozero.
# Deps: sudo apt install python3-gpiozero
# Montage : LED + resistance 330 ohms sur GPIO17 (broche 11), GND sur GND.
from gpiozero import LED
from time import sleep

LED_PIN = 17   # numero GPIO, pas numero de broche
ON_TIME = 0.5
OFF_TIME = 0.5

led = LED(LED_PIN)
print(f"Clignotement GPIO{LED_PIN}, Ctrl+C pour terminer")
try:
    while True:
        led.on()
        sleep(ON_TIME)
        led.off()
        sleep(OFF_TIME)
except KeyboardInterrupt:
    print("Arret propre")
    led.off()

← Back to the board