IoT Bytes

Bits and Bytes of IoT

Blink an LED with Raspberry Pi

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
  • LED
  • 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 pythondev 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 “” –

import RPi.GPIO as GPIO
import time

# Configure the PIN # 8
GPIO.setup(8, GPIO.OUT)

# 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)
  GPIO.output(8, False)

# Release Resources

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 



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: