A basic Raspberry Pi project to control two LEDs (red and green) using GPIO pins.
This project demonstrates how to control two LEDs connected to GPIO pins on a Raspberry Pi. The LEDs (red and green) alternate between being turned on and off in a continuous loop.
- Raspberry Pi (any model with GPIO pins, I have used Raspberry Pi Model B with 512 MB memory)
- Breadboard
- Two LEDs (red and green)
- Two Resistors (appropriate values for the LEDs, > 200 ohms should provide a safe current for the LED)
- Jumper wires
- Raspbian OS installed on your Raspberry Pi
- Python installed on your Raspberry Pi
- Basic knowledge of Raspberry Pi GPIO and Python
-
Identifying GPIO's on your RPi:
a. The first step in identifying GPIO pins is to refer to the pinout diagram of your specific Raspberry Pi model. Pinout diagrams provide a visual representation of the Raspberry Pi's GPIO pins, their numbers, and their corresponding functions. You can find official pinout diagrams on the Raspberry Pi website
b. More info at pinout.xyz
-
Connect LEDs to GPIO pins:
a. Connect the anode (longer leg) of the green LED to GPIO pin 17.
b. Connect the cathode (shorter leg) of the green LED to a resistor (e.g., 220 ohms).
c. Connect the other end of the resistor to the ground (GND) pin on the Raspberry Pi.
d. Connect the anode of the red LED to GPIO pin 27.
e. Connect the cathode of the green LED to a resistor (e.g., 220 ohms).
f. Connect the other end of the resistor to the ground (GND) pin on the Raspberry Pi.
-
Ensure proper connections:
- Double-check your wiring to ensure all connections are secure.
- Confirm that the GPIO pins match the ones specified in the code.
-
Move to a folder where you want to copy the project folder on Raspberry Pi.
Clone the repository to your Raspberry Pi:git clone https://github.com/nithishravella10/simple-rpi-led-project.git
-
Navigate to the project directory:
cd simple-rpi-led-project
-
Run the project:
python simple-rpi-led-project-rev1.py
This simple Raspberry Pi LED project demonstrates the basics of controlling LEDs using GPIO pins. Through the hardware setup and code implementation, you've gained hands-on experience with Raspberry Pi GPIO and Python programming. Next step is to try something more advanced, like controlling these LEDs remotely. Keep exploring and use ChatGPT for more fun!