I have a cheap PIR sensor, which I bought from ebay. It has three pins. It uses 9v battery. I am able to detect motion with it, as i am able to light up a LED on output line or can check output with ameter. See the diagram: enter image description here When I connect out line with my PI it never detect the output for reason. I connected the out wire from sensor into pin 17 and ran the following program:

from time import sleep
import RPi.GPIO as GPIO
GPIO.setup(17, GPIO.IN)

while True:
    if ( GPIO.input(17) == True ):
        print "Warning - MOTION has been detected!"
        print "All is QUIET in RPiLand..."
  • 2
    Did you connect the ground of the sensor to the ground of the Raspberry PI?
    – Tom77
    Mar 6, 2013 at 12:59
  • @Tom77: no, i am only using one line VOUT from sensor
    – leo
    Mar 6, 2013 at 17:34
  • 1
    Make sure you really only have 3.3 Volts on that line into the GPIO.
    – Craig
    Apr 5, 2013 at 20:20
  • can someone help me and state to me a script to trigger the raspberry pi using a PIR Module ?
    – user7100
    Apr 25, 2013 at 10:08

4 Answers 4


I use a PIR module setup in the following way and its working quite well.It is even much easier to setup than your connection.

They can be powered from 5V and output 3V so can be connected directly to pins on the Pi’s GPIO header without any other components.

Most PIR sensors can take input from anywhere between 5v to 9v so I think you should be good without the battery too.

Taken from www.raspberrypi-spy.co.uk

Change the GPIO number in your script or in the wiring.

Hope it helps.


I have several motion sensors and all are 5V, so they are powered right from the Pi. It does require that you to connect the ground to the Pi.

  • I know it works with pi's power. Can it pir trigger pi when connected with pi
    – leo
    Mar 7, 2013 at 7:56

Here is the script I am using. It is a Python script.

#!/usr/bin/env python

# Import required Python libraries
import RPi.GPIO as GPIO
import time
import subprocess

# Use BCM GPIO references
# instead of physical pin numbers

# Define GPIO to use on Pi

print "PIR Module Test (CTRL-C to exit)"

# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo

Current_State  = 0
Previous_State = 0


  print "Waiting for PIR to settle ..."

  # Loop until PIR output is 0
  while GPIO.input(GPIO_PIR)==1:
    Current_State  = 0

  print "  Ready"

  # Loop until users quits with CTRL-C
  while True :

    # Read PIR state
    Current_State = GPIO.input(GPIO_PIR)

    if Current_State==1 and Previous_State==0:
      # PIR is triggered
      print "  Motion detected!"
      #subprocess.call('bash script here', shell=True)
      #subprocess.call('bash script here ', shell=True)
      #subprocess.call('bash script here ', shell=True)
      # Record previous state
    elif Current_State==0 and Previous_State==1:
      # PIR has returned to ready state
      print "  Ready"

    # Wait for 10 milliseconds
    #print "  Sleep 30 seconds"

except KeyboardInterrupt:
  print "  Quit"
  # Reset GPIO settings

The input needs to be a circuit, so it needs to be grounded. The GND pin on the sensor grounds both the power source and the input, so it needs to be powered by the RPi. The wiring should go as follows:

  • GND on the sensor - Any GND pin on the RPi
  • OUT on the sensor - Pin 17 on the RPi
  • 5V+ input on the sensor - 5V Pin on the RPi

The code can stay the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.