Raspberry Pi Led Control Python GPIO Library Tutorial


 This is a tutorial that shows how to control LEDs with Raspberry Pi using Python GPIO library

  Here is a review I made about the Raspberry Pi 3. Go to 1:30 to see LED control in action.

 The Things You Will Need:

-Raspberry Pi 1,2 or 3 


-Female to Male Jumper Cables 

-5mm LEDs 

-220 Ohm Resistors 

Setting Up Your Raspberry Pi GPIO Library

Make sure Raspbian is installed on your Pi. If not go here  Installing Raspbian

Open the Terminal on your Raspberry Pi

Type the following command to download the GPIO library as a tarball:

wget http://raspberry-gpio-python.googlecode.com/files/RPi.GPIO-0.4.1a.tar.gz

Unzip the tarball:

tar zxvf RPi.GPIO-0.4.1a.tar.gz

Change to the directory where tarball was inflated:

 cd RPi.GPIO-0.4.1a
 Install the GPIO library in Python:
sudo python setup.py install


Now you can control Raspberry Pi’s pins with Python programming language

Set your LED like the scheme down below:


Coding – Raspberry Pi Led Control Python

Open Terminal on your Raspberry Pi again and write the following commands down below:

sudo apt-get install vim | vim ledcontrol.py

Here you installed a command line text editor named ‘vim’ , and opened a new file named ‘ledcontrol.py’

Press ‘i’ to enter insert mode and write the following codes on vim:

import RPi.GPIO as GPIO
import time

GPIO.setup(7, GPIO.OUT)

print "LED Control by Codeinstein"
print "1 = on the led"
print "0 = off the led"
print "exit = exit the program"

while True:

 led = raw_input(">>")

 if led == "1":
 elif led == "0":
 elif led == "exit":
  print "please type '1' '0' or 'exit'"

Press ESC , write :w and press enter to save the file then write :q to quit vim.

Now write the following command to execute the Python codes we wrote:

python ledcontrol.py

Enjoy and don’t forget to subscribe on Youtube:



A self-taught teacher of hack, public speaker and inspirer. Educating the future underground, no matter how beginner they are. Currently working on articles and YouTube videos/Hacking shows on Codeinstein YouTube Channel.

Leave a Reply

Your email address will not be published. Required fields are marked *