0% found this document useful (0 votes)
9 views6 pages

Exp 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Exp 10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB –10 Programming on PIR sensor

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.

Pin & Circuit Diagram:

Algorithm:

Initialize:

Import the necessary libraries: RPi.GPIO and time.


Set up the GPIO mode to BCM.
Define the GPIO pin to which the PIR sensor output is connected.\

Main Loop:

Enter an infinite loop.

Read PIR Sensor:


Read the state of the PIR sensor (HIGH for motion detected, LOW for no motion).

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 necessary libraries

import RPi.GPIO as GPIO

import time

# Set the GPIO mode to BCM

GPIO.setmode(GPIO.BCM)

# Set the PIR sensor pin

PIR_PIN = 17

# Setup the PIR sensor pin as input

GPIO.setup(PIR_PIN, GPIO.IN)

try:

print("Motion Detector Active...")

while True:

# Read the PIR sensor input

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")

# Pause for a short time to avoid excessive readings

time.sleep(0.1)

except KeyboardInterrupt:

# Clean up GPIO settings on keyboard interrupt

print("Motion Detector Stopped")

GPIO.cleanup()
Output:
Pre Lab Questions:
1. Define motion sensor.

2. Illustrate the characteristics of Adafruit PIR sensor.

Post Lab Questions:


1. What is retriggering?

2. How do PIR sensors work?


Result:

You might also like