0
0
Raspberry Piprogramming~15 mins

Digital output (GPIO.output) in Raspberry Pi - Mini Project: Build & Apply

Choose your learning style9 modes available
Control an LED with Raspberry Pi GPIO Output
📖 Scenario: You have a Raspberry Pi connected to a small LED light. You want to turn the LED on and off using your program. This is like flipping a switch to control a light bulb in your room.
🎯 Goal: Write a program that sets up the Raspberry Pi GPIO pin connected to the LED and turns the LED on.
📋 What You'll Learn
Use the RPi.GPIO library to control GPIO pins
Set up GPIO pin 18 as an output pin
Turn the LED on by setting GPIO pin 18 to HIGH
Print a message confirming the LED is on
💡 Why This Matters
🌍 Real World
Controlling lights, motors, or other devices connected to a Raspberry Pi in home automation or robotics.
💼 Career
Understanding GPIO output is essential for hardware programming roles involving embedded systems or IoT devices.
Progress0 / 4 steps
1
Set up GPIO and define the LED pin
Import the RPi.GPIO library as GPIO and set the GPIO mode to GPIO.BCM. Then create a variable called led_pin and set it to 18.
Raspberry Pi
Need a hint?

Use import RPi.GPIO as GPIO to import the library. Use GPIO.setmode(GPIO.BCM) to set the pin numbering mode. Assign 18 to led_pin.

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

Use GPIO.setup(led_pin, GPIO.OUT) to tell the Raspberry Pi that this pin will send out signals.

3
Turn the LED on
Use GPIO.output to set led_pin to GPIO.HIGH, which turns the LED on.
Raspberry Pi
Need a hint?

Use GPIO.output(led_pin, GPIO.HIGH) to send power to the LED and turn it on.

4
Print confirmation message
Write a print statement that outputs the text "LED is now ON".
Raspberry Pi
Need a hint?

Use print("LED is now ON") to show the message on the screen.