I have a little problem, i followed everything from here, but it doesnt seem to be working, it prints Motion detected infinite number of times without even detecting anything, the code is here.

from gpiozero import MotionSensor

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

Would highly appreciate any help

  • Which value did you set the detection time potentiometer of PIR? Try it by setting to min value which makes PIR give high output for 5 seconds.
    – vaha
    Commented Oct 15, 2016 at 6:54
  • A photo of your connections would help.
    – joan
    Commented Oct 15, 2016 at 8:48

2 Answers 2


Looking at the documentation motion_detected says

motion_detected Returns True if the device is currently active and False otherwise.

which probably not what you are looking for.

there is an example on that page that goes like

from gpiozero import MotionSensor

pir = MotionSensor(4)
print("Motion detected!")

which make more sense

My guess is the sensor is too sensitive, picking up noise as indicated in the page you linked

On the PIR module you should see two orange components with sockets that fit a Phillips screwdriver (see above). These are called potentiometers: they allow you to adjust the sensitivity of the sensor and the detection time. You should begin by setting the sensitivity to max and the time to min, but you can vary this later if you wish.

  • I tried what you said, but it desnt work neither, i prints once that it has been detected and thats it, i need to see if has been detected over a long period
    – Lee Mia
    Commented Oct 15, 2016 at 5:03
  • @StasVB according to the documentation I had linked, the constructor accepts a queue_len which defaults to 1 (effectively disabling it) like so class gpiozero.MotionSensor(pin, queue_len=1, sample_rate=10, threshold=0.5, partial=False). try increasing it 30/50/100 which would make it keep more samples (3/5/10 seconds at 10 samples/sec) and detect motion based on that Commented Oct 15, 2016 at 5:09

I've had this problem before. You might be confusing GND and VCC pins. Try pulling the lens off (carefully!) and looking at the white writing.

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.