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

Secure Simple Remote Access for Camera Viewing
Easy
  • 2,685
  • 11

Full instructions

Turn your RPi into a full featured camera with remote access, end2end encryption, and easy user enrollment.

Smartphone Connected Home Door Lock
Easy
  • 309
  • 3

Full instructions

An internet-connected, servo-driven deadbolt actuator that can be operated remotely using a smartphone.

Cortana Skills and Bot Framework on Raspberry Pi
Easy
  • 289
  • 2

Protip

Using Bot Framework on Raspberry Pi, using Cortana Skills to Echo sent message.

PiCorder
Easy
  • 4,582
  • 14

Full instructions

A simple Pi-based camcorder using the very nice HyperPixel touchscreen from Pimoroni.

Setting Up Your Pi Cap on the Raspberry Pi 1, 2, or 3
Easy
  • 151
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi 1 A+/B+, Raspberry Pi 2, or Raspberry Pi 3.

Setting Up Your Pi Cap on the Raspberry Pi Zero
Easy
  • 159
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi Zero.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login