electroSome

Led Blinking using Raspberry Pi – Python

Led blinking is one of the beginner circuits which helps one to get acquainted with GPIO pins of Raspberry Pi. Here we use Python language to write the code for blinking Led at one second intervals.

Components required

Raspberry Pi GPIO Specifications

For controlling a Led using Raspberry Pi, both python and the GPIO library is needed.

Installing Python GPIO Library

Note: Python and GPIO library are preinstalled if you are using Raspbian.

        wget http://raspberry-gpio-python.googlecode.com/files/RPi.GPIO-0.4.1a.tar.gz
        tar zxvf RPi.GPIO-0.4.1a.tar.gz
        cd RPi.GPIO-0.4.1a
        sudo python setup.py install

Raspberry Pi GPIO Pin Out

Raspberry Pi has 17 GPIO pins out of 26 pins

Raspberry Pi GPIO layout

Circuit Diagram

Connecting LED to Raspberry Pi

Python Programming

sudo idle
RaspberryPi terminal

This launches IDLE with superuser privileges which is necessary execute scripts for controlling the GPIO pins

RaspberryPi idle
RaspberryPi idle new window
import time
import RPi.GPIO as GPIO       ## Import GPIO library
GPIO.setmode(GPIO.BOARD)      ## Use board pin numbering
GPIO.setup(11, GPIO.OUT)      ## Setup GPIO Pin 11 to OUT
while True:
	GPIO.output(11,True)  ## Turn on Led
	time.sleep(1)         ## Wait for one second
	GPIO.output(11,False) ## Turn off Led
	time.sleep(1)         ## Wait for one second
RaspberryPi idle code
RaspberryPi idle save
RaspberryPi idle run

Video