0

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 Oct 15 '16 at 6:54
  • A photo of your connections would help. – joan Oct 15 '16 at 8:48
1

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)
pir.wait_for_motion()
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.

|improve this answer|||||
  • 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 Oct 15 '16 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 – Shreyas Murali Oct 15 '16 at 5:09
0

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.

|improve this answer|||||

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.