This page provides a complete, beginner-friendly guide to creating your first Raspberry Pi hardware project: blinking an LED using GPIO pins and Python.
1. Overview
The LED blinking project is the “Hello World” of Raspberry Pi hardware. It teaches you how GPIO pins work, how to wire a simple circuit safely, and how to control hardware using Python.

2. Components Required
- Raspberry Pi (any model)
- LED (any color)
- 220Ω or 330Ω resistor
- Breadboard
- Jumper wires
- USB cable to power Raspberry Pi
3. Understanding the Circuit
A Raspberry Pi GPIO pin outputs 3.3V, which powers the LED. The resistor protects the LED from too much current. The circuit must form a complete loop:
GPIO 17 → LED → Resistor → GND
Pin Mapping
- GPIO 17 = Physical Pin 11
- GND = Physical Pin 6
4. Wiring Instructions
Follow these steps to wire the LED safely:
- Insert the LED into the breadboard.
- Connect the long leg (positive) of the LED to GPIO 17 (Pin 11) using a jumper wire.
- Connect the short leg (negative) of the LED to one side of the 220Ω resistor.
- Connect the other side of the resistor to GND (Pin 6).
- Ensure all connections are firm and the Raspberry Pi is powered via USB.
5. Install GPIO Library
Run the following commands inside Raspberry Pi OS:
sudo apt update
sudo apt install python3-rpi.gpio
Test installation:
python3 -c "import RPi.GPIO"
If no error appears, the library is installed.
6. Create the LED Blink Python Script
Create a new Python file:
nano led.py
Paste the following code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) # Use BCM pin numbering
LED_PIN = 17
GPIO.setup(LED_PIN, GPIO.OUT) # Set LED pin as output
# Turn LED on
while True:
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
# Turn LED off
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
GPIO.cleanup()
Save and exit:
- Press CTRL + O, then ENTER
- Press CTRL + X
7. Run the Program
Execute the script:
python3 led.py
The LED should blink on and off every second.
Stop the program:
CTRL + C
Clean up GPIO:
GPIO.cleanup()
Short Note: What the LED Blinking Code Does
The Python script controls the LED by using the Raspberry Pi’s GPIO pins:
- It loads the RPi.GPIO library to access the GPIO pins and time for delays.
- It sets the pin numbering mode to BCM, so GPIO numbers (like 17) are used.
- It configures GPIO 17 as an output pin.
- Inside an infinite loop, it turns the LED ON, waits 1 second, turns it OFF, waits 1 second, and repeats.
8. Troubleshooting
- Ensure the LED is oriented correctly (long leg = positive).
- Verify the resistor is connected between the LED and GND.
- Check that you are running the script inside Raspberry Pi, not on your laptop.
- Confirm the file name is correct using
ls.