In this simple electronics project, you get to build a simple breadboard circuit that connects an LED to a Raspberry Pi via the GPIO port on pin 3 of the header. The figure shows the completed project.
In this project, you connect an external LED to a Raspberry Pi, and then use a simple sketch to turn the LED on and off at 0.5-second intervals.
Parts needed to build an LED flasher
- One Raspberry Pi 2 or 3 with Raspbian installed, connected to a monitor, keyboard, and power
- One small solderless breadboard (RadioShack 2760003)
- One 5mm red LED (RadioShack 2760209)
- One resistor (orange-orange-brown)
- Two jumper wires (M/F)

Steps for building an LED flasher
- Insert resistor R1.
R1 – 330 Ω: A3 to ground bus
- Insert LED1.Cathode (short lead): D5
Anode (long lead): D3
- Connect the ground bus to the Raspberry Pi header pin 2. Use a jumper to connect any hole in the ground bus on the breadboard.
- Connect pin 3 on the Raspberry Pi A5 on the breadboard.
- Open the Python 2 IDLE Editor with root privileges.
- Create and save the sketch shown here, using the filename LedBlink.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
while True:
GPIO.output(3, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(3, GPIO.LOW)
time.sleep(0.5)
- Run the LedBlink program by choosing Run → Run Module (or press F5). The LED on the breadboard will flash on and off at half-second intervals.