3

I have a PIR sensor which I'm using connected to a Raspberry Pi 3 Model B as part of a Magic Mirror project. I'm running this module for the sensor.

I've had the Motion Sensor working before, but now it's not, no idea what changed. So I need help.

I've tested the sensor itself with an LED and some batteries. It's working.

I've also tested the power pins on the RPI with an LED and can confirm that they are also working.

When I run this simple Python script

from gpiozero import MotionSensor

pir = MotionSensor(4)
while True:
    if pir.motion_detected:
        print("Motion detected!")

Nothing is printed to the console.

VCC = 2 (5.5v) GND = 6 Data = 7 (GPIO 4).

I think you can see it from here: I think you can see the setup here What other tests can I run to see why the RPI is not getting the readout from the PIR?

4
  • While it sounds like you know what you're about, it would be great if you could add a photo of the sensor connected to the Pi to the question. Either that or run a quick test of the GPIO pin with a switch just to make really sure everything's as it should be. It's way too easy to screw up a pin assignment.
    – goobering
    Jan 5 '17 at 22:52
  • Thanks for the comment. I've updated the issue with a picture that shows the wiring. I'd love for the issue to be a wiring problem!
    – user59476
    Jan 6 '17 at 22:47
  • 1
    I used a prototype board to duplicate your setup. I added an LED so that I could see when motion was detected. The LED helped me diagnose the fact that I used the wrong pin number. Jan 7 '17 at 5:53
  • Is this one solved?
    – MaNyYaCk
    Jul 19 '18 at 5:09
0

Code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(4, GPIO.IN) #PIR

try:
    time.sleep(2) # to stabilize sensor
    while True:
        if GPIO.input(4):
            print("Motion Detected...")
            time.sleep(5) #to avoid multiple detection

Hope this will solve your problem. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy