GPIO LED Output
Goal: Make an LED blink from Python so you understand GPIO output, resistor safety, and the difference between physical pin numbers and GPIO numbers.
What should happen: The LED turns on for one second, turns off for one second, and repeats.
Parts Needed
- Raspberry Pi with Raspberry Pi OS
- Breadboard
- 1 LED
- 220ฮฉ or 330ฮฉ resistor
- 2 jumper wires
Helpful Starter Parts
A basic Raspberry Pi electronics kit with LEDs, resistors, jumper wires, and a breadboard will cover this first lesson and several lessons after it.
View Starter Parts โWiring Steps
- Connect GPIO17, physical pin 11, to one side of the resistor.
- Connect the other side of the resistor to the long LED leg.
- Connect the short LED leg to GND, physical pin 6.
- Do not skip the resistor. That is how LEDs get burned out.
Easy Build Steps
- Shut the Pi down before wiring.
- Build the circuit on the breadboard.
- Boot the Pi and open Terminal.
- Create
led_blink.py. - Paste the code and run
python3 led_blink.py.
Mistakes to Avoid
- Using physical pin 17 instead of GPIO17.
- Putting the LED in backward.
- Forgetting the resistor.
- Loose jumper wires that look connected but are not.
Starter Code
from gpiozero import LED
from time import sleep
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
Suggested instruction image: close-up view of GPIO17 wire, resistor, LED legs, and ground wire.
Quick Test
Run the code. If the LED blinks, the wiring and Python setup are good. If it stays dark, flip the LED first. If that fails, move the jumper wire back to GPIO17 and check the ground pin.
Upgrade: Add two more LEDs and make a simple traffic light.