Lighting up LED’s using RaspberryPi and Python #2 RaspoElectro

Lighting up Led’s using RaspberryPi and Python

Once you’ve setup your Raspberry Pi according to my GPIO basics #1 RaspoElectro tutorial, you are ready for Led lighting project. Let’s light up an led using the Python programming language/script and the GPIO pins on your Raspberry Pi

RaspoElectro02

What you Will Learn:

  • Basic electrical circuit and attach it to your RPi GPIO pins
  • Simple Python program to control the circuit using IDLE IDE, hereafter GPIO cable

What you need:

  • Raspberry Pi configured with the GPIO library
  • small led’s, any color
  • 1 – 50 ohm resistor
  • small jumper wires
  • Breadboard

My wiring structure

  • GPIO 3 > 1st LED -ve
  • GPIO 7 > 2nd LED -ve
  • GPIO 11 > 3rd LED -ve
  • GPIO 6> Breadboard +ve
  • GPIO 1> Breadboard -ve

Python Code/Script

from time import sleep
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(3, GPIO.OUT) ## Set Pin 3 to OUT
GPIO.output(3,False)
GPIO.setup(7, GPIO.OUT) ## Set Pin 7 to OUT
GPIO.output(7,False)
GPIO.setup(11, GPIO.OUT) ## Set Pin 11 to OUT
GPIO.output(11,False)
while 1:
     GPIO.output(3,True)
     sleep(1)
     GPIO.output(3,False)
     sleep(1)

     GPIO.output(7,True)
     sleep(1)
     GPIO.output(7,False)
     sleep(1)

     GPIO.output(11,True)
     sleep(1)
     GPIO.output(11,False)
     sleep(1)

Code execution Demonstration

Leave a Reply

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