Programming Raspberry Pi to PIR Sensor
Programming Raspberry Pi to PIR Sensor
OBJECTIVES:
a. To understand the basics of the GPIO Pins of Raspberry Pi.
b. To study the basic of PIR sensor.
c. To write a python program to detect any human motion using PIR Sensor.
Note: Either Buzzer or LED can be interfaced to GPIO 20 pin. Both cannot be connected simultaneously.
1|Page
GPIO Pin Connection for PIR, Buzzer and LED:
Procedure:
Note: The Raspbian operating system comes with Python already installed in it.
a. Start Raspberry Pi in desktop mode, open the Applications Menu in the top left of
your screen, and navigate to Programming > Python 3 (IDLE) /. This will open the
Python shell.
2|Page
b. Write a program for PIR sensor and Buzzer interfacing with raspberry pi and save as
with pir.py
GPIO.setup(PIR_input, GPIO.IN)
GPIO.setup(BUZZ, GPIO.OUT)
GPIO.output(BUZZ, GPIO.LOW)
while True:
#when motion detected turn on BUZZ
if(GPIO.input(PIR_input)):
GPIO.output(BUZZ, GPIO.HIGH)
else:
GPIO.output(BUZZ, GPIO.LOW)
3|Page