SlideShare a Scribd company logo
1 of 37
LED BLINKING
Raspberry Pi
GPIO
 A powerful feature of the Raspberry Pi is the row
of GPIO (general-purpose input/output) pins
along the top edge of the board. A 40-pin GPIO
header is found on all current Raspberry Pi
boards (unpopulated on Pi Zero and Pi Zero W).
Prior to the Pi 1 Model B+ (2014), boards
comprised a shorter 26-pin header.
There are two kinds of Input and Output pin
numbering for the Raspberry pi. One is the BCM and
the other is BOARD. Basically these pin numberings
are useful for writing python script for the Raspberry
Pi.
GPIO BOARD
This type of pin numbering refers to the number
of the pin in the plug, i.e, the numbers printed on
the board, for example, P1. The advantage of this
type of numbering is, it will not change even
though the version of board changes.
GPIO BCM
 The BCM option refers to the pin by “Broadcom
SOC Channel. They signify the Broadcom SOC
channel designation. The BCM channel changes
as the version number changes.
 Note: It is very important to wire the GPIO pins
with limited resistors to avoid serious damage to
the Raspberry Pi. LEDs must have resistors to
limit the current passing through them. The
motors should not be connected to the GPIO pins
directl
What is the difference between BOARD and BCM for GPIO
pin numbering?
 The GPIO.BOARD option specifies that you are referring to the pins by
the number of the pin the the plug - i.e the numbers printed on the board
(e.g. P1) and in the middle of the diagrams below.
 The GPIO.BCM option means that you are referring to the pins by the
"Broadcom SOC channel" number, these are the numbers after "GPIO"
in the green rectangles around the outside of the below diagrams:
Identification of the pin numberings via
Linux command
 There is a Linux command to find out which name is
for which GPIO pin. So in that case, we do not have
to worry about a tutorial to have by our side to check
out the pin numberings of the Raspberry Pi all the
time.
 Type the following command in the terminal,
pinout
How to use the GPIO pin numbers in
Python?
 simple LED blink python program with Raspberry
Pi. The number 11 is the pin for LED and
considered as an output.
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode (GPIO.BOARD)
GPIO.setup (11,GPIO.OUT)
while True:
GPIO.output(11,True)
time.sleep(2)
GPIO.output(11,False)
time.sleep(2)
How to make an LED blink with
Raspberry Pi?
Things you need
 Breadboard
 Light Emitting Diode
 Resistor > 68 ohms
 Raspberry Pi
 wires
Circuit Diagram
Procedure
 Insert an LED into a breadboard.
 Connect the resistor which is more than 68 ohms
across the longer end of the LED.
 Connect the GPIO pin 11 to the shorter end of the
LED.
 Connect the GPIO pin 6 (ground) to the other end
of the resistor.
import RPi.GPIO as GPIO
from time import sleep
 The two lines above from the code explains,
importing the libraries you will need RPi.GPIO to
control the GPIO pins. Importing time to control
how long the pin will be ON or OFF.
GPIO.setmode (GPIO.BOARD)
GPIO.setup (11,GPIO.OUT)
 GPIO.BOARD indicates the numbering scheme
you are using. The line (11,GPIO.OUT) means
you are using GPIO pin 11 as output pin.
while True:
GPIO.output(11,True)
time.sleep(2)
GPIO.output(11,False)
time.sleep(2)
 while is used to continue as long as the program
runs.
GPIO.output(11,True) sets the output to high and
remain that way for 2 seconds ( sleep(2)). The same
is set to low and remain that way for 2 seconds. If
you need time-lapse for 5 seconds, you can change
that in time.sleep(5).
LED BLINK with switch
 import RPi.GPIO as GPIO
 #GPIO.setwarnings(False)
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(4,GPIO.OUT)
 GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD
_UP)
 while True:
 i=GPIO.input(3)
 if i==True:
 GPIO.output(4,True)
 else:
 GPIO.output(4,False)

Build a simple app that interacts with
Raspberry Pi GPIO. using three LEDs, which
are attached to the Raspberry Pi board.
Furthermore, turn the LEDs on/off
sequentially.
The following hardware components are needed:
 Raspberry Pi
 Three LEDs of any color
 Three resistors (330 Ω or 220 Ω)
 LED 1 is connected to Pi GPIO18
LED 2 is connected to Pi GPIO23
LED 3 is connected to Pi GPIO24
We can write a program using WiringPi with Python.
The following is the complete Python code for blinking
LEDs:
import wiringpi2 as wiringpi
import time
# initialize
wiringpi.wiringPiSetup()
# define GPIO mode
GPIO18 = 1
GPIO23 = 4
GPIO24 = 5
LOW = 0
HIGH = 1
OUTPUT = 1
wiringpi.pinMode(GPIO18,
OUTPUT)
wiringpi.pinMode(GPIO23,
OUTPUT)
wiringpi.pinMode(GPIO24,
OUTPUT)
# make all LEDs off
def clear_all():
wiringpi.digitalWrite(GPIO18, LOW)
wiringpi.digitalWrite(GPIO23, LOW)
wiringpi.digitalWrite(GPIO24, LOW)
try:
while 1:
clear_all()
print("turn on LED 1")
wiringpi.digitalWrite(GPIO18, HIGH)
time.sleep(2)
clear_all()
print("turn on LED 2")
wiringpi.digitalWrite(GPIO23,
HIGH)
time.sleep(2)
clear_all()
print("turn on LED 3")
wiringpi.digitalWrite(GPIO24,
HIGH)
time.sleep(2)
except KeyboardInterrupt:
clear_all()
print("done")
three LED operation with single
switch
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD_UP)
x=0
y=0
while True:
i=GPIO.input(3)
print("i=",i)
if i==True:
x=x+1
print("x=",x)
if x==1:
y=y+1
print("y=",y)
if y==4:
y=1
if y==1:
GPIO.output(4,True)
GPIO.output(17,False)
GPIO.output(27,False)
elif y==2:
GPIO.output(4,False)
GPIO.output(17,True)
GPIO.output(27,False)
elif y==3:
GPIO.output(4,False)
GPIO.output(17,False)
GPIO.output(27,True)
else:
x=0
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(19,GPIO.OUT)
while True:
GPIO.output(19,GPIO.HIGH)
time.sleep(1)
GPIO.output(19,GPIO.LOW)
time.sleep(1)
 https://create.withcode.uk/python/A3
DHT11 Temperature and Humidity Sensor and the
Raspberry Pi
 DHT11 is a low-cost temperature and humidity
sensor. It isn’t the fastest sensor around but its cheap
price makes it useful for experimenting or projects
where you don’t require new readings multiple times a
second. The device only requires three connections to
the Pi. +3.3v, ground and one GPIO pin.
DHT11 Specifications
 The device itself has four pins but one of these is
not used. You can buy the 4-pin device on its own
or as part of a 3-pin module.

The modules have three pins and are easy to connect directly to the Pi’s
GPIO header.
Humidity : 20-80% (5% accuracy)
Temperature : 0-50°C (±2°C accuracy)
The manufacturers do not recommended that you read data from this
device more than once per 2 seconds. If you do you may get incorrect
Hardware Setup
 The 4-pin device will require a resistor (4.7K-10K) to be placed
between Pin 1 (3.3V) and Pin 2 (Data).
 The 3-pin modules will usually have this resistor included which
makes the wiring a bit easier. For this reason I got hold of the
module which I could then attach to the Pi with a piece of 3-way
cable.
 Different suppliers may wire the module pins differently so check
the PCB markings to identify Vcc (+), data and Ground (-).
 The 3 pins should be connected to the Pi as shown in the table
below :DHT Pin Signal Pi Pin
1 3.3V 1
2 Data/Out 11 (GPIO17)
3 not used –
4 Ground 6 or 9
Your data pin can be attached to any GPIO pin you prefer. In my example I
am using physical pin 11 which is GPIO 17. Here is a 4-pin sensor
connected to the Pi’s GPIO header. It has a 10K resistor between pin 1
(3.3V) and 2 (Data/Out).
Python Library
 The DHT11 requires a specific protocol to be
applied to the data pin. In order to save time
trying to implement this yourself it’s far easier to
use the Adafruit DHT library.
 The library deals with the data that needs to be
exchanged with the sensor but it is sensitive to
timing issues. The Pi’s operating system may get
in the way while performing other tasks so to
compensate for this the library requests a number
of readings from the device until it gets one that is
valid.
Software Setup
To start with update your package lists and install a few
Python libraries :
sudo apt-get update
sudo apt-get install build-essential python-dev
Then clone the Adafruit library from their repository :
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
Then install the library for Python 3 :
sudo python3 setup.py install
Adafruit Example Python Script
Adafruit provide an example script that you can use to
check your sensor is operating correctly.
cd ~
cd Adafruit_Python_DHT
cd exemples
Then :
python AdafruitDHT.py 11 17
The example script takes two parameters. The first is the sensor type so is
set to “11” to represent the DHT11. The second is the GPIO number so
for example using “17” for GPIO17. You can change this if you are using
a different GPIO pin for your data/out wire.
You should see an output similar to this :
Temp=22.0* Humidity=68.0%
Using the Library In Other Python Scripts
import Adafruit_DHT
# Set sensor type : Options are DHT11,DHT22 or AM2302
sensor=Adafruit_DHT.DHT11
# Set GPIO sensor is connected to
gpio=17
# Use read_retry method. This will retry up to 15 times to
# get a sensor reading (waiting 2 seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
# Reading the DHT11 is very sensitive to timings and occasionally
# the Pi might fail to get a valid reading. So check if readings are valid.
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')

More Related Content

What's hot

Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingICS
 
IoT Programming on the Raspberry Pi
IoT Programming on the Raspberry PiIoT Programming on the Raspberry Pi
IoT Programming on the Raspberry PiDamien Magoni
 
3.pillars of embedded io t and physical devices
3.pillars of embedded io t and physical devices3.pillars of embedded io t and physical devices
3.pillars of embedded io t and physical devicesRaghavendra Maggavi
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Mandeesh Singh
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry PiLentin Joseph
 
Simple Presentation On Raspberry pi
Simple Presentation On Raspberry piSimple Presentation On Raspberry pi
Simple Presentation On Raspberry piSakkar Chowdhury
 
Wsn Wireless Hart Architecture,Mechanism,Components
Wsn Wireless Hart Architecture,Mechanism,ComponentsWsn Wireless Hart Architecture,Mechanism,Components
Wsn Wireless Hart Architecture,Mechanism,Componentsaroosa khan
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration AKHIL MADANKAR
 
PM8056 Chip SAS Expander from PMC Sierra
PM8056 Chip SAS Expander from PMC Sierra PM8056 Chip SAS Expander from PMC Sierra
PM8056 Chip SAS Expander from PMC Sierra Devanshu Shrivastava
 
Basics of peripheral devices and Working
Basics of peripheral devices and WorkingBasics of peripheral devices and Working
Basics of peripheral devices and WorkingDr.YNM
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiAhmad Hafeezi
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfGVNSK Sravya
 

What's hot (20)

Raspberry pi
Raspberry piRaspberry pi
Raspberry pi
 
Ins and Outs of GPIO Programming
Ins and Outs of GPIO ProgrammingIns and Outs of GPIO Programming
Ins and Outs of GPIO Programming
 
IoT Programming on the Raspberry Pi
IoT Programming on the Raspberry PiIoT Programming on the Raspberry Pi
IoT Programming on the Raspberry Pi
 
3.pillars of embedded io t and physical devices
3.pillars of embedded io t and physical devices3.pillars of embedded io t and physical devices
3.pillars of embedded io t and physical devices
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)
 
Arduino
ArduinoArduino
Arduino
 
Esp8266 basics
Esp8266 basicsEsp8266 basics
Esp8266 basics
 
ATmega 16
ATmega 16ATmega 16
ATmega 16
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry Pi
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Simple Presentation On Raspberry pi
Simple Presentation On Raspberry piSimple Presentation On Raspberry pi
Simple Presentation On Raspberry pi
 
Wsn Wireless Hart Architecture,Mechanism,Components
Wsn Wireless Hart Architecture,Mechanism,ComponentsWsn Wireless Hart Architecture,Mechanism,Components
Wsn Wireless Hart Architecture,Mechanism,Components
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration
 
PM8056 Chip SAS Expander from PMC Sierra
PM8056 Chip SAS Expander from PMC Sierra PM8056 Chip SAS Expander from PMC Sierra
PM8056 Chip SAS Expander from PMC Sierra
 
Raspberry pi
Raspberry piRaspberry pi
Raspberry pi
 
Basics of peripheral devices and Working
Basics of peripheral devices and WorkingBasics of peripheral devices and Working
Basics of peripheral devices and Working
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry Pi
 
IoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdfIoT Physical Devices and End Points.pdf
IoT Physical Devices and End Points.pdf
 
Raspberry pi complete setup
Raspberry pi complete setupRaspberry pi complete setup
Raspberry pi complete setup
 
Raspberry pi ppt
Raspberry pi pptRaspberry pi ppt
Raspberry pi ppt
 

Similar to Raspberry pi led blink

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Dnyanesh Patil
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218CAVEDU Education
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using PythonSeggy Segaran
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxTuynLCh
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Tom Paulus
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRICELEEIO
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi Tomomi Imura
 
Temperature sensor with raspberry pi
Temperature sensor with raspberry piTemperature sensor with raspberry pi
Temperature sensor with raspberry piSantosh Kumar Kar
 
Interacting with Intel Edison
Interacting with Intel EdisonInteracting with Intel Edison
Interacting with Intel EdisonFITC
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiNeil Broers
 
Raspberry-Pi GPIO
Raspberry-Pi GPIORaspberry-Pi GPIO
Raspberry-Pi GPIOSajib Sen
 
Raspberry pi technical documentation
Raspberry pi technical documentationRaspberry pi technical documentation
Raspberry pi technical documentationGR Techno Solutions
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
Using raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidityUsing raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidityIRJET Journal
 
Linux Format - Get Into Linux Today
Linux Format - Get Into Linux TodayLinux Format - Get Into Linux Today
Linux Format - Get Into Linux TodayHeart Disk
 

Similar to Raspberry pi led blink (20)

Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3Interfacing two wire adc0831 to raspberry pi2 / Pi3
Interfacing two wire adc0831 to raspberry pi2 / Pi3
 
4. GPIO Access
4. GPIO Access4. GPIO Access
4. GPIO Access
 
Atomic pi Mini PC
Atomic pi Mini PCAtomic pi Mini PC
Atomic pi Mini PC
 
Atomic PI apug
Atomic PI apugAtomic PI apug
Atomic PI apug
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Raspberry pi
Raspberry pi Raspberry pi
Raspberry pi
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
 
Python-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptxPython-in-Embedded-systems.pptx
Python-in-Embedded-systems.pptx
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
 
Temperature sensor with raspberry pi
Temperature sensor with raspberry piTemperature sensor with raspberry pi
Temperature sensor with raspberry pi
 
Interacting with Intel Edison
Interacting with Intel EdisonInteracting with Intel Edison
Interacting with Intel Edison
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
 
Raspberry-Pi GPIO
Raspberry-Pi GPIORaspberry-Pi GPIO
Raspberry-Pi GPIO
 
Raspberry pi technical documentation
Raspberry pi technical documentationRaspberry pi technical documentation
Raspberry pi technical documentation
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
Using raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidityUsing raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidity
 
Linux Format - Get Into Linux Today
Linux Format - Get Into Linux TodayLinux Format - Get Into Linux Today
Linux Format - Get Into Linux Today
 
Day4
Day4Day4
Day4
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

Raspberry pi led blink

  • 2.
  • 3. GPIO  A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins along the top edge of the board. A 40-pin GPIO header is found on all current Raspberry Pi boards (unpopulated on Pi Zero and Pi Zero W). Prior to the Pi 1 Model B+ (2014), boards comprised a shorter 26-pin header.
  • 4.
  • 5. There are two kinds of Input and Output pin numbering for the Raspberry pi. One is the BCM and the other is BOARD. Basically these pin numberings are useful for writing python script for the Raspberry Pi.
  • 6. GPIO BOARD This type of pin numbering refers to the number of the pin in the plug, i.e, the numbers printed on the board, for example, P1. The advantage of this type of numbering is, it will not change even though the version of board changes.
  • 7. GPIO BCM  The BCM option refers to the pin by “Broadcom SOC Channel. They signify the Broadcom SOC channel designation. The BCM channel changes as the version number changes.  Note: It is very important to wire the GPIO pins with limited resistors to avoid serious damage to the Raspberry Pi. LEDs must have resistors to limit the current passing through them. The motors should not be connected to the GPIO pins directl
  • 8. What is the difference between BOARD and BCM for GPIO pin numbering?  The GPIO.BOARD option specifies that you are referring to the pins by the number of the pin the the plug - i.e the numbers printed on the board (e.g. P1) and in the middle of the diagrams below.  The GPIO.BCM option means that you are referring to the pins by the "Broadcom SOC channel" number, these are the numbers after "GPIO" in the green rectangles around the outside of the below diagrams:
  • 9. Identification of the pin numberings via Linux command  There is a Linux command to find out which name is for which GPIO pin. So in that case, we do not have to worry about a tutorial to have by our side to check out the pin numberings of the Raspberry Pi all the time.  Type the following command in the terminal, pinout
  • 10. How to use the GPIO pin numbers in Python?  simple LED blink python program with Raspberry Pi. The number 11 is the pin for LED and considered as an output. import RPi.GPIO as GPIO from time import sleep GPIO.setmode (GPIO.BOARD) GPIO.setup (11,GPIO.OUT) while True: GPIO.output(11,True) time.sleep(2) GPIO.output(11,False) time.sleep(2)
  • 11. How to make an LED blink with Raspberry Pi? Things you need  Breadboard  Light Emitting Diode  Resistor > 68 ohms  Raspberry Pi  wires
  • 13. Procedure  Insert an LED into a breadboard.  Connect the resistor which is more than 68 ohms across the longer end of the LED.  Connect the GPIO pin 11 to the shorter end of the LED.  Connect the GPIO pin 6 (ground) to the other end of the resistor.
  • 14. import RPi.GPIO as GPIO from time import sleep  The two lines above from the code explains, importing the libraries you will need RPi.GPIO to control the GPIO pins. Importing time to control how long the pin will be ON or OFF.
  • 15. GPIO.setmode (GPIO.BOARD) GPIO.setup (11,GPIO.OUT)  GPIO.BOARD indicates the numbering scheme you are using. The line (11,GPIO.OUT) means you are using GPIO pin 11 as output pin.
  • 16. while True: GPIO.output(11,True) time.sleep(2) GPIO.output(11,False) time.sleep(2)  while is used to continue as long as the program runs. GPIO.output(11,True) sets the output to high and remain that way for 2 seconds ( sleep(2)). The same is set to low and remain that way for 2 seconds. If you need time-lapse for 5 seconds, you can change that in time.sleep(5).
  • 17.
  • 18.
  • 19. LED BLINK with switch
  • 20.  import RPi.GPIO as GPIO  #GPIO.setwarnings(False)  GPIO.setmode(GPIO.BCM)  GPIO.setup(4,GPIO.OUT)  GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD _UP)  while True:  i=GPIO.input(3)  if i==True:  GPIO.output(4,True)  else:  GPIO.output(4,False) 
  • 21. Build a simple app that interacts with Raspberry Pi GPIO. using three LEDs, which are attached to the Raspberry Pi board. Furthermore, turn the LEDs on/off sequentially. The following hardware components are needed:  Raspberry Pi  Three LEDs of any color  Three resistors (330 Ω or 220 Ω)
  • 22.  LED 1 is connected to Pi GPIO18 LED 2 is connected to Pi GPIO23 LED 3 is connected to Pi GPIO24
  • 23. We can write a program using WiringPi with Python. The following is the complete Python code for blinking LEDs: import wiringpi2 as wiringpi import time # initialize wiringpi.wiringPiSetup() # define GPIO mode GPIO18 = 1 GPIO23 = 4 GPIO24 = 5
  • 24. LOW = 0 HIGH = 1 OUTPUT = 1 wiringpi.pinMode(GPIO18, OUTPUT) wiringpi.pinMode(GPIO23, OUTPUT) wiringpi.pinMode(GPIO24, OUTPUT) # make all LEDs off def clear_all(): wiringpi.digitalWrite(GPIO18, LOW) wiringpi.digitalWrite(GPIO23, LOW) wiringpi.digitalWrite(GPIO24, LOW) try: while 1: clear_all() print("turn on LED 1") wiringpi.digitalWrite(GPIO18, HIGH) time.sleep(2) clear_all() print("turn on LED 2") wiringpi.digitalWrite(GPIO23, HIGH) time.sleep(2) clear_all() print("turn on LED 3") wiringpi.digitalWrite(GPIO24, HIGH) time.sleep(2) except KeyboardInterrupt: clear_all() print("done")
  • 25. three LED operation with single switch
  • 26. import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(4,GPIO.OUT) GPIO.setup(17,GPIO.OUT) GPIO.setup(27,GPIO.OUT) GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD_UP) x=0 y=0 while True: i=GPIO.input(3) print("i=",i) if i==True: x=x+1
  • 27. print("x=",x) if x==1: y=y+1 print("y=",y) if y==4: y=1 if y==1: GPIO.output(4,True) GPIO.output(17,False) GPIO.output(27,False) elif y==2: GPIO.output(4,False) GPIO.output(17,True) GPIO.output(27,False) elif y==3: GPIO.output(4,False) GPIO.output(17,False) GPIO.output(27,True) else: x=0
  • 28. import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(19,GPIO.OUT) while True: GPIO.output(19,GPIO.HIGH) time.sleep(1) GPIO.output(19,GPIO.LOW) time.sleep(1)
  • 30. DHT11 Temperature and Humidity Sensor and the Raspberry Pi  DHT11 is a low-cost temperature and humidity sensor. It isn’t the fastest sensor around but its cheap price makes it useful for experimenting or projects where you don’t require new readings multiple times a second. The device only requires three connections to the Pi. +3.3v, ground and one GPIO pin.
  • 31. DHT11 Specifications  The device itself has four pins but one of these is not used. You can buy the 4-pin device on its own or as part of a 3-pin module.  The modules have three pins and are easy to connect directly to the Pi’s GPIO header. Humidity : 20-80% (5% accuracy) Temperature : 0-50°C (±2°C accuracy) The manufacturers do not recommended that you read data from this device more than once per 2 seconds. If you do you may get incorrect
  • 32. Hardware Setup  The 4-pin device will require a resistor (4.7K-10K) to be placed between Pin 1 (3.3V) and Pin 2 (Data).  The 3-pin modules will usually have this resistor included which makes the wiring a bit easier. For this reason I got hold of the module which I could then attach to the Pi with a piece of 3-way cable.  Different suppliers may wire the module pins differently so check the PCB markings to identify Vcc (+), data and Ground (-).  The 3 pins should be connected to the Pi as shown in the table below :DHT Pin Signal Pi Pin 1 3.3V 1 2 Data/Out 11 (GPIO17) 3 not used – 4 Ground 6 or 9
  • 33. Your data pin can be attached to any GPIO pin you prefer. In my example I am using physical pin 11 which is GPIO 17. Here is a 4-pin sensor connected to the Pi’s GPIO header. It has a 10K resistor between pin 1 (3.3V) and 2 (Data/Out).
  • 34. Python Library  The DHT11 requires a specific protocol to be applied to the data pin. In order to save time trying to implement this yourself it’s far easier to use the Adafruit DHT library.  The library deals with the data that needs to be exchanged with the sensor but it is sensitive to timing issues. The Pi’s operating system may get in the way while performing other tasks so to compensate for this the library requests a number of readings from the device until it gets one that is valid.
  • 35. Software Setup To start with update your package lists and install a few Python libraries : sudo apt-get update sudo apt-get install build-essential python-dev Then clone the Adafruit library from their repository : git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT Then install the library for Python 3 : sudo python3 setup.py install
  • 36. Adafruit Example Python Script Adafruit provide an example script that you can use to check your sensor is operating correctly. cd ~ cd Adafruit_Python_DHT cd exemples Then : python AdafruitDHT.py 11 17 The example script takes two parameters. The first is the sensor type so is set to “11” to represent the DHT11. The second is the GPIO number so for example using “17” for GPIO17. You can change this if you are using a different GPIO pin for your data/out wire. You should see an output similar to this : Temp=22.0* Humidity=68.0%
  • 37. Using the Library In Other Python Scripts import Adafruit_DHT # Set sensor type : Options are DHT11,DHT22 or AM2302 sensor=Adafruit_DHT.DHT11 # Set GPIO sensor is connected to gpio=17 # Use read_retry method. This will retry up to 15 times to # get a sensor reading (waiting 2 seconds between each retry). humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio) # Reading the DHT11 is very sensitive to timings and occasionally # the Pi might fail to get a valid reading. So check if readings are valid. if humidity is not None and temperature is not None: print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) else: print('Failed to get reading. Try again!')