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?

  • 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
    Commented Jan 5, 2017 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
    Commented Jan 6, 2017 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.
    – user46953
    Commented Jan 7, 2017 at 5:53
  • Is this one solved?
    – MaNyYaCk
    Commented Jul 19, 2018 at 5:09

1 Answer 1



import RPi.GPIO as GPIO
import time


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

    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 and acknowledge you have read our privacy policy.