Pyroelectric Infrared Pir Motion Sensor Detector Python Script – Raspberry Pi

PIR infrared sensor module is based on infrared technology, automatic control products. High sensitivity, high reliability, low power consumption, low voltage operation mode. Widely used in various auto-sensing electrical equipment, especially for battery-powered automatic control products.

Using PIR we can identify the motion and this sensor will transmitĀ a signal for 3 sec so we need to do a program and detect the motion and as per your requirement you can activate or deactivate any functions like switching on camera when motion is detected.

I am going to use Raspberry Pi 2 For this small Project . In this Project i am designing and program to detect a motion and on basis of that alarm will be played for 1 minute.

Requirement :

1.Raspberry Pi

2.Pyroelectric Infrared Pir Motion Sensor Detector Module

3.Computer With Putty Installed


Step 1.

Install any raspberry based Operating system with GPIO Package installed and as well as Python Installed. I am using OSMC.

Step 2.

Connect the PIR VCC,OUT,GND to Raspberry pi 5v,GPIO4,GND


VCC – > 5v
OUT -> GPIO4 (Pin 7)


Step 3

Connect to raspberry pi using SSH (Putty For Windows)


Create a python program and copy bellow code .And after saving run the script with sudo permission

import RPi.GPIO as GPIO
import time
import os
#GPIO Pin number where the sensor out is connected
while True:
    if sensor_input == 1 :
		#Timer in seconds for activation
        timer = 60
    if timer > 0 :
        timer = timer - 1
        print "De-activating in :",timer,"secs"
        if switch_on!=1 :
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT) 
            print "--- Switch Activated ---"
        if switch_on!=0 :
            print "Switch Deactivated"
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT)