Exp 10
Exp 10
Aim:
To detect the movement using Passive Infrared (PIR) sensor using Raspberry pi board
using Python.
Task:
Construct a “Motion Detector” using PIR sensor and Raspberry pi board using Python.
Algorithm:
Initialize:
Main Loop:
Motion Detection:
If motion is detected (PIR sensor output is HIGH):
Perform actions (e.g., print a message, send notifications, etc.).
Delay:
Pause for a short time (e.g., 0.1 seconds) to avoid rapid readings.
Cleanup:
Clean up GPIO settings before exiting the program.
Program:
import time
GPIO.setmode(GPIO.BCM)
PIR_PIN = 17
GPIO.setup(PIR_PIN, GPIO.IN)
try:
while True:
pir_state = GPIO.input(PIR_PIN)
if pir_state == GPIO.HIGH:
print("Motion Detected!")
# Do something when motion is detected (e.g., send an alert, turn on a light, etc.)
else:
print("No Motion")
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
Output:
Pre Lab Questions:
1. Define motion sensor.