Blinking an LED: Your First Raspberry PI Project
This year at PiShop, we decided to bring a more personal touch to our blog by creating beginner tutorials and sharing some of our personal projects that we’ve integrated Raspberry Pi into, so welcome to the very first in our series of beginner-friendly and project-focused articles! To kick things off, we’re diving into a classic Raspberry Pi project: blinking an LED. This straightforward tutorial is perfect for beginners, offering a fun and hands-on way to explore the basics of electronics and programming.
What you’ll need:
- Raspberry Pi: Raspberry Pi 3 or newer.
- Breadboard: For easily connecting components.
- Jumper wires: To connect the components.
- LED: Any color will work.
- Resistor: 220 ohms is a common value for LEDs.
- GPIO pins: We’ll be using some of the GPIO pins on your Raspberry Pi.
Or
- Project Box 1 for Raspberry Pi (Raspberry Pi not Included)
Let’s get started!
1. Set up your Raspberry Pi:
- If you haven’t already, install the Raspberry Pi OS on an SD card.
- Boot your Raspberry Pi and connect to it by using a monitor and keyboard.
2. Install the necessary libraries:
- Open the terminal and install the gpiozero library:
sudo apt update
pip install gpiozero
3. Create the Python script:
- Create a new file named
blink.py
using a text editor:
nano blink.py
- Paste the following code into the file:
Python
from gpiozero import LED
from time import sleep
# Define the GPIO pin connected to the LED
led = LED(17)
# Turn the LED on and off
while True:
led.on()
sleep(1)
led.off()
sleep(1)
- Save the file by pressing Ctrl+X, then Y, and then Enter.
4. Wire the circuit:
- Connect one end of the resistor to the positive (longer) leg of the LED.
- Connect the other end of the resistor to one of the GPIO pins on your Raspberry Pi (in this example, GPIO 18).
- Connect the negative (shorter) leg of the LED to one of the ground pins on your Raspberry Pi.



5. Run the script:
- In the terminal, run the script:
python3 blink.py
Command Explanations:
- led.on(): Turns the LED on
- led.of():Turns the LED off
time.sleep(1)
: This line pauses the program for 1 second.
This simple project demonstrates the basic principles of interacting with hardware using the Raspberry Pi and provides a solid foundation for more complex projects.
What more to do:
- Adjust the blinking speed: You can change the
time.sleep()
values to make the LED blink faster or slower. - Use multiple LEDs: Try to connect multiple LEDs to different GPIO pins and create different blinking patterns.
- Explore other GPIO pin functions: Experiment with other GPIO pin capabilities, such as reading sensor data. (Something we’ll cover soon)
To keep exploring the exciting possibilities of Raspberry Pi, check out more of our beginner-friendly tutorials and project ideas on our blog! Whether you’re just starting out or looking for your next challenge, we’ve got plenty of projects to inspire your creativity. What projects are you most interested in? Are there any topics you’d love to see us cover next? Let us know in the comments—we’d love to hear from you!