Blinking An LED With Raspberry Pi

Introduction

In this article, I will explain how to blink an LED using Raspberry Pi. It is very simple to control the LED in Raspberry. 

Parts Of List
  1. Raspberry Pi Board
  2. LED -1
  3. Bread Board
  4. Hook up wires
  5. Resistor.
Raspberry Pi
Figure 1 - Raspberry Pi
  1. The Raspberry Pi 2 uses a Broadcom BCM2836 SoC with a 900 MHz 32-bit quad-core ARM Cortex-A7 processor (as do many current smartphones), with 256 KB shared L2 cache.
  2. The Raspberry Pi 3 uses a Broadcom BCM2837 SoC with a 1.2 GHz 64-bit quad-core ARM Cortex-A53 processor, with 512 KB shared L2 cache.
Led
Figure 2 - LED
  1. A light-emitting diode (LED) is a two-lead semiconductor light source.
  2. It is a p–n junction diode which emits light when activated.
  3. When a suitable voltage is applied to the leads, it blinks.
Bread Board

Figure 3 - BreadBoard
  1. An electronic breadboard (as opposed to the type on which sandwiches are made) is actually referring to a solder-less breadboard.
  2. These are great units for making temporary circuits and prototyping, and they require absolutely no soldering.
Resistor

Figure 4 - Resistor
  1. A resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element.
  2. In electronic circuits, resistors are used to reduce the current flow.
  3. Adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines, among other uses.
Connection For Raspberry Pi
  1. Connect  LED to Raspberry Pi in the Anode side to the input pin.
  2. Connect the Negative on the LED that is cathode of the Gnd pin.
  3. And connect the Resistor of Positive side to the LED.
Programming
  1. import GPIO.RPi as GPIO ##import GPIO library  
  2. import time  
  3. GPIO.setmode(GPIO.BOARD) ##use board pin numbering  
  4. GPIO.setup(11,GPIO.OUT) ##set 11th pin as output pin  
  5. while 1:  
  6. GPIO.output(11,1) ## Turn on led  
  7. time.sleep(1) ## 1 second delay  
  8. GPIO.output(11,0) ## Turn off led  
  9. time.sleep(1)   
Programming Explanation

First, we have to know the GPIO (General Purpose Input/Output). It can be controlled by the Run time user. At the start, we have to declare the Header file as in the below name, and add Library to the board as the GPIO.
  1. import GPIO.RPi as GPIO ##import GPIO library  
  2. import time  
Next, set the input pin and output pin as the GPIO.setmode. It is used to give the Output of the source.Then, fix the time for blinking the LED and finally, it will process according to the Timesleep of the second. Finally, it will activate at the given time sleep.
  1. GPIO.output(11,1) ## Turn on led  
  2. time.sleep(1) ## 1 second delay  
  3. GPIO.output(11,0) ## Turn off led  
 
Output


Figure 5 - Output

Up Next
    Ebook Download
    View all
    Learn
    View all