Pradeep Singh | 9th Sep 2017
It’s going to be a very simple ‘Hello World’ kind of articles for the beginners who have just started working with Raspberry Pi.
1. What Do You Need?
Before you begin make sure you have the following components –
- Raspberry Pi (Model 0, 1, 2, or 3) with Rasbian OS
- 330 Ohm Register
- Breadboard and couple of male to female jumper wires
2. Prepare the Circuit:
Connect your Raspberry Pi’s Pin# 6 with negative pin (smaller leg) of your LED and Pin# 8 with positive pin (longer leg) through the resistor as shown in the following picture –
If you know what you are doing, feel free to change the GPIO pin connections and change the python script (used in this article) accordingly.
3. Install the Python GPIO Library:
Update all the packages and libraries on your Raspberry Pi using the following command. Please note, this process may take some time depending upon how many packages need to be upgraded.
sudo apt-get update && sudo apt-get upgrade
Install Python packages python–dev and Rpi.GPIO using the following command –
sudo apt-get install python-dev python-rpi.gpio
4. Create Python Script:
Crete following file in your Raspberry Pi home directory with the name as “led_blinker.py” –
import RPi.GPIO as GPIO import time # Configure the PIN # 8 GPIO.setmode(GPIO.BOARD) GPIO.setup(8, GPIO.OUT) GPIO.setwarnings(False) # Blink Parameters blink_interval = .5 #Time interval in Seconds blink_Count = 10 # Blinker Loop for i in range(0,blink_Count): GPIO.output(8, True) time.sleep(blink_interval) GPIO.output(8, False) time.sleep(blink_interval) # Release Resources GPIO.cleanup()
5. Execute the Python Script to Blink the LED:
Execute the following command from the shell to blink the LED (make sure your Python script is in the directory from where you are executing this command) –
sudo python led_blinker.py