3

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.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)

while True:
    if ( GPIO.input(17) == True ):
        print "Warning - MOTION has been detected!"
    else:
        print "All is QUIET in RPiLand..."
    sleep(1);
  • 2
    Did you connect the ground of the sensor to the ground of the Raspberry PI? – Tom77 Mar 6 '13 at 12:59
  • @Tom77: no, i am only using one line VOUT from sensor – leo Mar 6 '13 at 17:34
  • 1
    Make sure you really only have 3.3 Volts on that line into the GPIO. – Craig Apr 5 '13 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 '13 at 10:08
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.

1

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 '13 at 7:56
0

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
GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_PIR = 7

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

try:

  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
      Previous_State=1
    elif Current_State==0 and Previous_State==1:
      # PIR has returned to ready state
      print "  Ready"
      Previous_State=0

    # Wait for 10 milliseconds
    time.sleep(0.01)
    #print "  Sleep 30 seconds"

except KeyboardInterrupt:
  print "  Quit"
  # Reset GPIO settings
  GPIO.cleanup()
0

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, privacy policy and cookie policy

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