How to use Python to control the GPIO pins on your Raspberry Pi?
LED Blinker using GPIO and Python
This simple project teaches you how to use Python to control the GPIO pins on your Raspberry Pi—blinking an LED on and off.
What You Need:
-
Raspberry Pi (any model)
-
1x LED
-
1x 330Ω resistor
-
Breadboard and jumper wires
-
Python 3 (pre-installed)
-
GPIO library (
RPi.GPIO)
Wiring the Circuit:
-
Connect the long leg of the LED (anode) to GPIO pin 18 (physical pin 12).
-
Connect a 330Ω resistor from the LED's short leg (cathode) to GND (physical pin 6).
-
Use a breadboard for easy wiring.
Python Code:
Open the terminal and create the script:
Paste this code:
Save and exit (Ctrl+X, then Y, then Enter).
Run the Script:
You should see the LED blink every second.
What You Learn:
-
GPIO control in Python
-
Basic electronics with LEDs
-
Writing and executing Python scripts
.jpg)
评论
发表评论