Reading a Button Press with GPIO.input on Raspberry Pi
📖 Scenario: You have a Raspberry Pi connected to a push button. When you press the button, the Raspberry Pi should detect it and tell you if the button is pressed or not.
🎯 Goal: Build a simple program that reads the button state using GPIO.input and prints whether the button is pressed or released.
📋 What You'll Learn
Use the RPi.GPIO library to access GPIO pins
Set up GPIO pin 18 as an input with a pull-down resistor
Read the button state using
GPIO.input(18)Print 'Button Pressed' when the button is pressed
Print 'Button Released' when the button is not pressed
💡 Why This Matters
🌍 Real World
Buttons and switches are common inputs in electronics projects. Reading their state lets your Raspberry Pi respond to user actions.
💼 Career
Understanding GPIO input is essential for embedded systems, IoT devices, and hardware interfacing roles.
Progress0 / 4 steps