Blink an LED using GPIO port on Raspberry Pi

One┬áthing that separates the Pi from other the rest of Single Board Computer is its ability to use the GPIO (General Purpose Input/Output) pins which can be switched as HIGH or LOW to control any external devices. All you will need is a GPIO breakout board and a few jumper cable to begin with. Here I’ve used a female-to-male connector to complete the job.

GPIO of raspberry piIn this tutorial I have used pin 9 for GND and pin 11 for GPIO17. The light emitting diode was linked using a 470 ohm register in series with pin 9 and 11 to restrict the current.

Software Implementation

The quickest way to get started is to make use of python which comes pre-installed in all the OS images. Obtain the RPi.GPIO library and copy the gz tar ball to your SD card. Open the terminal and browse to the extracted directory containing the RPi.GPIO library.

Then type: $ sudo python install to install the library.

Note: As the OS is multitasking and not Real-time unlike Arduino there may possibly be jitters depending on CPU load.

Based on the library I have written a easy code to turn ON and turn OFF the light emitting diode after a delay of 1 sec (1000ms) each. The diode blinks 50 times.



You can use nano text editor to write the code on the console or copy paste the code and save it as a file and upload the file to your raspberry pi


import RPi.GPIO as GPIO
import time
# blinking function
def blink(pin):
# to use Raspberry Pi board pin numbers
# set up GPIO output channel
GPIO.setup(11, GPIO.OUT)
# blink GPIO17 50 times
for i in range(0,50):


One you have the file saved just run the python code as follows

sudo python

blinking LED on raspberry pi

Leave a Reply