webwinkelkeur logo

4.7 avg.

5101+ reviews
webwinkelkeur logoView all

5101+ reviews

5101+ reviews

Order by 16:00 for same day shipping

14 days return

GB

EN

Individual

Business

GPIO Project 2 - Led Blink

Beginner
30 Minuten
114,90

In this project you will learn how to blink an LED using the GPIO pins of the Raspberry Pi. For this project we use Python and the Thonny IDE, which is available by default in the Raspberry Pi OS.

Connection diagram

  1. Connect the red LED:
    • Place the LED on the breadboard. The long leg (anode, positive) is connected to one side of the 220Ω resistor.
    • The short leg (cathode, negative) is connected to the GND pin  (pin 6) of the Raspberry Pi.
  2. Connect the resistor:
    • Connect the other side of the resistor to GPIO 17 (pin 11) of the Raspberry Pi.

Pinout Reference:

  • GPIO 17 = Pin 7
  • GND = Pin 6

Setting up the workplace

  1. Connect the Raspberry Pi to the monitor with an HDMI cable.
  2. Connect the keyboard and mouse via the USB ports of the Raspberry Pi.
  3. Start the Raspberry Pi and log in to Raspberry Pi OS.
  4. Open the Thonny Python IDE (pre-installed in Raspberry Pi OS).

Python code in Thonny

  1. Start Thonny: Click on the Raspberry Pi menu > Programming > Thonny Python IDE.
  2. Write your code: Create a new file in Thonny and enter the following code:
from gpiozero import LED
from time import sleep

# LED aangesloten op GPIO 17
led = LED(17)

# Start een oneindige loop
while True:
    led.on()   # Zet LED aan
    sleep(1)   # Wacht 1 seconde
    led.off()  # Zet LED uit
    sleep(1)   # Wacht 1 seconde

3. Save the file: Click FileSave As and name the file led_blink.py.

4. Run the script: Click on the greenRun button (▶) at the top of the Thonny interface

How does it work?

  • while True: : Keeps the program running until you manually stop it.
  • led.on()en led.off()
  • sleep(1): Pauses the program for one second between actions.

Result

If everything is connected correctly and the script has been executed correctly, the LED will be on for one second, then off for one second, and repeat this pattern.

Experiment

  • Adjust speed: Change the value of drag(1) to examplesleep(0.5) for faster blinking.
  • Multiple LEDs: Add additional LEDs and use different GPIO pins. For example:
led2 = LED(27)  # Nieuwe LED op GPIO 27

With this adjustment, the program is easy to use and will only stop when you indicate so. Have fun with your flashing LED!