Things used in this project

Hardware components:
Raspberry Pi 2
×1
PIR Motion Sensor
×1
Buzzer (optional)
×1
Breadboard
×1
Jumper Wires
×1

Schematics

Schematic
Untitled sketch bb coksgn73yn

Code

PIR.pyPython
Create new python file PIR.py and enter the following code.
To run the code, open the terminal and go to the directory where your PIR.py is located. Then enter the command " sudo python PIR.py " and hit enter
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN) #PIR
GPIO.setup(24, GPIO.OUT) #BUzzer

try:
    time.sleep(2) # to stabilize sensor
    while True:
        if GPIO.input(23):
            GPIO.output(24, True)
            time.sleep(0.5) #Buzzer turns on for 0.5 sec
            GPIO.output(24, False)
            print("Motion Detected...")
            time.sleep(5) #to avoid multiple detection
        time.sleep(0.1) #loop delay, should be less than detection delay

except:
    GPIO.cleanup()

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

SMART HOME SECURITY SYSTEM
Easy
  • 1,604
  • 14

Full instructions

Detects intrusion and notifies house owner. The owner remotely watches the house and if any theft is suspected will turn on the buzzer.

Windows 10 IoT Core - Reading Heart Rate Pulses
Easy
  • 632
  • 7

Full instructions

In this short blog post, I will show you how to connect a Heart Rate Pulse Sensor to you Raspberry Pi running Windows 10 IoT Core.

Boost Your Google Home With Prota OS for RPi
Easy
  • 1,119
  • 6

Full instructions

Extend your Google Home features to smart light, smart speakers, smart cam and smart appliances with those DIY tricks based on Raspberry Pi.

AssistantPi
Easy
  • 3,677
  • 32

Full instructions

Bring both Google Assistant and Alexa to your Raspberry Pi.

Internet Streaming Radio with Google AIY
Easy
  • 2,276
  • 20

Protip

Make a voice-activated Internet streaming radio with your Raspberry Pi and Google AIY. Can also be used to play MP3s or other audio files.

A LoRaWAN "The Things Network" Gateway for Windows IoT Core
Easy
  • 1,894
  • 14

Full instructions

Build your own LoRaWAN "The Things Network" packet-forwarding gateway on Windows 10 IoT Core in native .NET code.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback