1

I'm having some false positives on a PIR sensor (HC-SR501), but with a slightly different set up to the previous questions on the topic I have found.

I already had one PIR sensor attached to my raspberry pi and it was working fine. I had some issues with regular false positives, which I put down to the wi-fi or bluetooth. Fortunately, I didn't need either, so they are disabled.

Having added a second PIR sensor, things seemed to work fine for a while. Checking the logs in the morning, I would have no false positives for the entire night.

However, recently I've started getting regular false positives on the newer PIR sensor. The strange thing is that it doesn't happen to the first one. It also seems a bit weird that I didn't have problems for a few weeks and then they just started out of the blue.

To be more specific, I get two false positives within the same second, then a third one 17 seconds later. These three false positives repeat every 170 seconds.

I've checked the wiring to make sure nothing is loose and I've tried changing from GPIO 21 to GPIO 4 in case that made a difference. Again, the wifi and bluetooth are off and the first PIR sensor is unaffected. They are near each other (a foot or two apart) but pointing in different directions. Changing the sensitivity and time delay seems to make no difference. Any ideas what could be causing the issue?

For information, my code for testing:

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time
import datetime

GPIO.setmode(GPIO.BCM)
PIR_PIN1 = 7
PIR_PIN2 = 4
GPIO.setup(PIR_PIN1, GPIO.IN)
GPIO.setup(PIR_PIN2, GPIO.IN)

def MOTION(PIR_PIN):
        print("Motion detected on gpio {}!".format(str(PIR_PIN)))
        print(datetime.datetime.now())

print("PIR Module Test (CTRL+C to exit)")
time.sleep(2)
print("Ready")


try:
        GPIO.add_event_detect(PIR_PIN1, GPIO.RISING, callback=MOTION)
        GPIO.add_event_detect(PIR_PIN2, GPIO.RISING, callback=MOTION)
        while 1:
                time.sleep(100)
except KeyboardInterrupt:
        print("Quit")
        GPIO.cleanup()

Some output:

PIR Module Test (CTRL+C to exit)
Ready
Motion detected on gpio 7! < This is when I'm actually in the room
2020-02-16 09:42:21.120976
Motion detected on gpio 4!
2020-02-16 09:43:42.275443
Motion detected on gpio 4!
2020-02-16 09:43:42.275770
Motion detected on gpio 4!
2020-02-16 09:43:59.228590
Motion detected on gpio 4!
2020-02-16 09:46:49.429935
Motion detected on gpio 4!
2020-02-16 09:46:49.430270
Motion detected on gpio 4!
2020-02-16 09:47:06.401903

UPDATE: Seems the delay can change between false positives. I think I must have done this when fiddling with the time delay. It remains consistently two false positives in the same second, followed by another shortly after, with a longer pause before the next set of three.

9
  • GPIO 4 is suspicious as it is used by the 1-wire bus. Double check that there are no active 1-wire entries in /boot/config.txt.
    – joan
    Feb 16 '20 at 9:50
  • Ah, let me see. A couple of months ago I browsed HC-SR501 titled forum discussions, especially on the hypersensivity or false positive problems and frustrated users' complaints. I also studied how Lady Ada commented on this too sensitive and hard to setup device. Then I myself evaluated it, along with a couple of other vendor's models. In case you are interested how I look at this problem, and my "solution" or workaround, you might check out my evaluation report and recommendation: raspberrypi.stackexchange.com/questions/98371/…. Cheers.
    – tlfong01
    Feb 16 '20 at 10:07
  • @joan Thanks for your comment. I checked this and checked the setting on raspi-config for good measure. Still no change. Also had the same issue when on GPIO 21. Feb 16 '20 at 10:10
  • @tflong01 Thanks for your recommendation! I've had quite a few issues with these PIR sensors (I have five spread across my three pis), but this is the first time I've not managed to sort it out by myself. Seems kind of wasteful to have to replace them all, but then it might be preferably to bashing my head against the keyboard. Feb 16 '20 at 10:18
  • Well, it is an engineering trade off or business cost benefit analysis. Actually I spend about three hours studying and trying out this device. I dug deep because I found Lady Ada's evaluation report a bit "harsh", which is unusual. I was curious to studied to see if Lady Ada's comment is fair. I do learn a lot about the theory, particularly the physics part, which is very interesting, because it related to the light topic, and Franel lens etc, which I learn in middle school physics, but never had a chance thoroughly understand it.
    – tlfong01
    Feb 16 '20 at 10:30

Your Answer

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

Browse other questions tagged or ask your own question.