Introduction: Blink a Series of LEDs Using Python Programming Language and Raspberry Pi

About: Systems Administrator and Software Programmer.
Overview of Steps

In the first phase, I will install only one LED. Next, I download the LED class python module that represent one hardware LED. I will run the LED class python module to blink that LED. The first phase serves as a "Proof of Concept".

In the second phase, I will install another 4 LEDs. Finally, I run the python main module to create a series of five sequentially blinking LEDs as depicted in the video above

Step 1: Materials

Gather the following materials:

1 Raspberry Pi device running on standard Raspbian Linux installation
5 LEDs rated at 2.4V

5 Resistor (can be between 185 Ohms to 270 Ohms)

1 breadboard

6 Female to Male Jumper Wire

5 single-core wire (also called solid wires, solid-core or single-strand wire, consists of one piece of metal wire. Solid wire is useful for wiring breadboards. I stripped an unused telephone wire to get the single-core wire. There are 4 thin insulated single-core wire in a telephone cable. Choose any one and strip the insulator off just enough to expose bare metal at the two ends.)

Step 2: Installing the First LED


Be careful when installing the LED with the Raspberry Pi as it may short-circuit and damage Raspberry Pi device. Do this at your own risk. Remove all power supply source from your Raspberry Pi device.


The following materials are required:

1 X Raspberry Pi
1 x LED

1 X 165 Ohm Resistor

2 X Male-Female Jumper Wire

1 X 5cm single core wire 1 X Breadboard

  1. Read to the GPIO diagram to locate the pins.
  2. Connect female end of jumper wire to the GPIO Pin 11. (This pin will be programmed to supply 3.3 Volts)
  3. Connect male end of jumber wire to the breadboard as shown in video.
  4. Connect resistor to breadboard as show in video.
  5. Connect LED to breadboard as shown in video.
  6. Connect the single-core wire as shown in video
  7. Connect female end of another jumper wire to GPIO Pin 6 (This pis is at 0 Volts.)

Step 3: Start Up Raspberry Pi

  1. Boot up the Raspberry Pi by pluggin in the power supply micro usb
  2. Log in using pi account

Step 4: Use a Python Class Module to Flash an LED

  1. Load the LXTerminal.
  2. Install or update the Rpi.GPIO software by typing the following bold commands. The command might ask you for your input:

    pi@raspberrypi ~ $ sudo apt-get update

    pi@raspberrypi ~ $ sudo apt-get install python-rpi.gpio

  3. Download the attached file called and saved it as in Raspberry Pi directory: /home/pi/python_proj/gpio
  4. Load the IDLE by typing the following:

    pi@raspberrypi ~ $ sudo idle

  5. On the IDLE's Python Shell Window: Click File -> Open -> Choose that you saved in #1 of this step
  6. Read the documentation and source codes of
  7. In IDLE's Python Shell Window, type the following

    >>>import sys

  8. Then press ENTER
  9. Type the following:


  10. Then press ENTER
  11. Type the following:

    >>>import led

  12. Then press ENTER
  13. Type the following to setup the LED connected to Pin 11:

    >>>led11 = led.Led(11)

  14. Then press ENTER
  15. Type the following to blink the LED connected to Pin 11:


  16. Then press ENTER key
  17. Observe that the LED blinks continuously.
  18. Press Ctlr+C to exit program

  19. Type the following:


  20. You have successfully completed the "Proof of Concept" phase if the LED blinks continuously.


Step 5: Install and Test the Next 4 LEDs


You need the following:

4 x LED

4 X 165 Ohm Resistor

4 X Male-Female Jumper Wire

4 X 5cm single core wire

  1. Shut down Rasbian OS
  2. Unplug the power cable off Raspberry Pi
  3. Follow the same instruction described in Step 2.
  4. Use the following GPIO Pin:
    Pin 12
    Pin 15
    Pin 16
    Pin 18

  5. Play the attached video for detail to see the layout of the components in the breadboard and Raspberry Pi
  6. Load the IDLE (Python Editor) by typing the following:

    pi@raspberrypi ~ $ sudo idle
  7. On the IDLE's Python Shell Window: Click File -> Open -> Choose
  8. In IDLE's Python Shell Window, type the following:

    >>>import sys
  9. Then press ENTER
  10. Type the following:

  11. Then press ENTER
  12. Type the following:

    >>>import led
  13. Then press ENTER
  14. Type the following:

    >>>led12 = led.Led(12)
  15. Then press ENTER
  16. Type the following:

  17. Then press ENTER key
  18. Observe the LED blinks continuously.
  19. Press Ctlr+C to exit program
  20. Type the following:

  21. Repeat instructions No 11-15 for the rest of the LEDs. Remember to change the Pin number for each LED:

    led15 = led.Led(15)

    led16 = led.Led(16)

    led18 = led.Led(18)

Step 6: Blink the Series of LEDs

  1. Download and and save the 2 files as its original name in /home/pi/python_proj/gpio
  2. In IDLE's Python Shell window, click Menu -> Open -> Choose
  3. Read the source codes
  4. In IDLE's Python Shell window, click Menu -> Open -> Choose

  5. Read the source codes

  6. In the window that displays, click on Run -> Run Module
  7. Observe all 5 LEDs blinking in sequential order