Python on Raspberry Pi: Controlling an LED
📖 Scenario: You have a Raspberry Pi with an LED connected to GPIO pin 17. You want to write a Python program to turn the LED on and off.
🎯 Goal: Build a Python program that sets up the GPIO pin, turns the LED on, waits, then turns it off.
📋 What You'll Learn
Create a variable called
led_pin and set it to 17Create a variable called
delay_time and set it to 2Use
GPIO.setup(led_pin, GPIO.OUT) to set the pin as outputUse
GPIO.output(led_pin, GPIO.HIGH) to turn the LED onUse
GPIO.output(led_pin, GPIO.LOW) to turn the LED offPrint
"LED is ON" when the LED turns onPrint
"LED is OFF" when the LED turns off💡 Why This Matters
🌍 Real World
Controlling hardware like LEDs, motors, and sensors with Python on a Raspberry Pi is common in home automation and robotics projects.
💼 Career
Understanding GPIO control with Python is useful for roles in embedded systems, IoT development, and hardware prototyping.
Progress0 / 4 steps