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
- Raspberry Pi Board
- LED -1
- Bread Board
- Hook up wires
- Resistor.
Raspberry Pi
Figure 1 - Raspberry Pi
- 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.
- 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
- A light-emitting diode (LED) is a two-lead semiconductor light source.
- It is a p–n junction diode which emits light when activated.
- When a suitable voltage is applied to the leads, it blinks.
Bread Board
Figure 3 - BreadBoard
- An electronic breadboard (as opposed to the type on which sandwiches are made) is actually referring to a solder-less breadboard.
- These are great units for making temporary circuits and prototyping, and they require absolutely no soldering.
Resistor
Figure 4 - Resistor
- A resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element.
- In electronic circuits, resistors are used to reduce the current flow.
- Adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines, among other uses.
Connection For Raspberry Pi
- Connect LED to Raspberry Pi in the Anode side to the input pin.
- Connect the Negative on the LED that is cathode of the Gnd pin.
- And connect the Resistor of Positive side to the LED.
Programming
- import GPIO.RPi as GPIO ##import GPIO library
- import time
- GPIO.setmode(GPIO.BOARD) ##use board pin numbering
- GPIO.setup(11,GPIO.OUT) ##set 11th pin as output pin
- while 1:
- GPIO.output(11,1) ## Turn on led
- time.sleep(1) ## 1 second delay
- GPIO.output(11,0) ## Turn off led
- 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.
- import GPIO.RPi as GPIO ##import GPIO library
- 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.
- GPIO.output(11,1) ## Turn on led
- time.sleep(1) ## 1 second delay
- GPIO.output(11,0) ## Turn off led
Output
Figure 5 - Output