Raspberry Pi Led Scheme

Raspberry Pi Led Control Python GPIO Library Tutorial

Facebooktwittergoogle_plusyoutubeinstagram

 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 http://bit.ly/buyraspberrypi3

-Breadboard http://amzn.to/1T8zscj

-Female to Male Jumper Cables http://amzn.to/1TRZiju

-5mm LEDs http://amzn.to/1XnB6ZB

-220 Ohm Resistors http://amzn.to/24OHniR


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

Scheme

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

Set your LED like the scheme down below:

ledcontrolraspberrypi


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.setmode(GPIO.BOARD)
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":
  GPIO.output(7,True)
 elif led == "0":
  GPIO.output(7,False)
 elif led == "exit":
  exit()
 else:
  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:

Facebooktwittergoogle_plusredditmail

Codeinstein

Creator of what you see.

Leave a Reply

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