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

Chicken Coop Livestream
Easy
  • 2,740
  • 10

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

Test Your Internet Speed Using a Raspberry Pi + Ubidots
Easy
  • 392
  • 5

Protip

Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Dataplicity “Custom Actions" for controlling RPi GPIOs
Easy
  • 44
  • 1

Protip

With this example you will control GPIOs on your Raspberry Pi from the Dataplicity Mobile app using "Custom Actions" feature.

Raspberry Pi Shutdown / Restart Button
Easy
  • 5,342
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

DIY Raspberry Pi Indoor Outdoor Webcam
Easy
  • 1,609
  • 6

Full instructions

Ever want to monitor your home but don't want to buy a $100 1080p webcam? Well I did, and you can too!

How to interface Arduino with RaspberryPi
Easy
  • 82
  • 1

Protip

In this I have shown how to send data from temperature sensor which is connected to Arduino and send data to Rpi database.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog