What if you could control your Raspberry Pi's hardware with just a few lines of code?
Why RPi.GPIO library setup in Raspberry Pi? - Purpose & Use Cases
Imagine you want to control an LED light on your Raspberry Pi by turning it on and off manually by connecting and disconnecting wires every time.
This manual way is slow and tiring. You have to physically change connections each time, which can cause mistakes or even damage the hardware.
The RPi.GPIO library lets you control the pins on your Raspberry Pi with simple code commands, so you can turn devices on or off without touching the wires.
Connect wire to pin 18 to turn LED on
Disconnect wire to turn LED offimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.HIGH) # LED on GPIO.output(18, GPIO.LOW) # LED off GPIO.cleanup()
You can automate hardware control easily and safely using simple Python code.
Turning on a fan automatically when the temperature rises, without needing to plug or unplug wires manually.
Manual hardware control is slow and risky.
RPi.GPIO library lets you control pins with code.
This makes hardware projects easier and safer.