0
0
Raspberry Piprogramming~30 mins

First GPIO program (LED blink) in Raspberry Pi - Mini Project: Build & Apply

Choose your learning style9 modes available
First GPIO program (LED blink)
📖 Scenario: You have a Raspberry Pi connected to an LED on GPIO pin 17. You want to make the LED blink on and off repeatedly.
🎯 Goal: Write a simple Python program to blink an LED connected to GPIO pin 17 on your Raspberry Pi.
📋 What You'll Learn
Use the RPi.GPIO library to control GPIO pins
Set up GPIO pin 17 as an output
Turn the LED on and off with a delay
Use a loop to blink the LED 5 times
Print a message when blinking is done
💡 Why This Matters
🌍 Real World
Controlling LEDs and other devices with Raspberry Pi GPIO pins is common in home automation, robotics, and electronics projects.
💼 Career
Understanding GPIO programming is useful for jobs in embedded systems, IoT development, and hardware prototyping.
Progress0 / 4 steps
1
Set up GPIO and LED pin
Import the RPi.GPIO library as GPIO and the time module. Then set the GPIO mode to GPIO.BCM and create a variable called led_pin with the value 17.
Raspberry Pi
Need a hint?

Use import RPi.GPIO as GPIO and import time. Then call GPIO.setmode(GPIO.BCM) and assign 17 to led_pin.

2
Configure LED pin as output
Use GPIO.setup to set led_pin as an output pin.
Raspberry Pi
Need a hint?

Call GPIO.setup(led_pin, GPIO.OUT) to make the pin an output.

3
Blink the LED 5 times
Write a for loop that runs 5 times. Inside the loop, turn the LED on with GPIO.output(led_pin, GPIO.HIGH), wait 0.5 seconds using time.sleep(0.5), turn the LED off with GPIO.output(led_pin, GPIO.LOW), and wait another 0.5 seconds.
Raspberry Pi
Need a hint?

Use for i in range(5): and inside it turn the LED on and off with 0.5 second pauses.

4
Clean up and print done message
After the loop, call GPIO.cleanup() to reset the GPIO pins. Then print "Blinking done!" to the screen.
Raspberry Pi
Need a hint?

Call GPIO.cleanup() after the loop and then print "Blinking done!".