Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Raspberry Pi
90 min
Share

Blinking led with raspberry pi 5!

The Raspberry Pi 5 board has GPIO ports that enable it to interact with the outside world. You can connect motors, screens, sensors, or LEDs to these ports.

Project Video

Overview

In this tutorial, we will connect an LED to the GPIO ports on the Raspberry Pi 5 board, and we will make the Raspberry Pi turn the LED on and off for 1 second.

Getting the Items

Raspberry Pi 5 Single Board Computer
Get Item
Clear 5mm LED (5 pack)
Get Item
Half-size Breadboard
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the LED and the Raspberry pi 5 as shown in the image below.

Connections from the Raspberry pi 5 to the breadboard:

 • Raspberry pi 5 GPIO GND pin → Breadboard ground line

 • Raspberry pi 5 GPIO 5V pin → Breadboard 5V line

Connections from the LED :

 • LED anode pin → 330 ohm resistor → Raspberry pi 5 GPIO pin 17

 • LED cathode pin → Breadboard ground line


Coding

Now on your Raspberry Pi, click on the menu, then choose programming, then open the Thonny ide program.

Now copy that code into it, The function of this code is to turn the LED light on and off for 1 second.

import gpiod

import time

LED_PIN = 17  # GPIO pin number where the LED is connected

# Open GPIO chip

chip = gpiod.Chip('gpiochip4')

# Get the GPIO line for the LED

led_line = chip.get_line(LED_PIN)

# Request exclusive access to the line and configure it as an output

led_line.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)

try:

   while True:

       led_line.set_value(1)  # Turn on the LED

       time.sleep(1)  # Wait for 1 second

       led_line.set_value(0)  # Turn off the LED

       time.sleep(1)  # Wait for 1 second

finally:

   # Release the GPIO line and clean up resources on program exit

   led_line.release()

   chip.close()

Testing it Out

Now run the code, you will find that the Raspberry Pi 5 board turns on and off the LED for 1 second.

Resources

No items found.