PIR Sensors discussion notes

Viewed 10 times

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:


import RPi.GPIO as GPIO
import time
import datetime

PIR_PIN1 = 7
PIR_PIN2 = 4

        print("Motion detected on gpio {}!".format(str(PIR_PIN)))

print("PIR Module Test (CTRL+C to exit)")

        GPIO.add_event_detect(PIR_PIN1, GPIO.RISING, callback=MOTION)
        GPIO.add_event_detect(PIR_PIN2, GPIO.RISING, callback=MOTION)
        while 1:
except KeyboardInterrupt:

Some output:

PIR Module Test (CTRL+C to exit)
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 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.

 New contributor
  • 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 52 mins ago
  • 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 36 mins ago   
  • @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. – jaimepapier 33 mins ago
  • @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. – jaimepapier 25 mins ago
  • 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 13 mins ago   
  • The physics theory part and implementation details is very well explained. However, the design is first generation, and so surprised by later generations which learnt from the forerunners. Actually I was rather impressed by the first group of engineering scientists who were innovative enough to manufactured such a good educational toy. But sadly, I cannot recommend it, if there is a better choice. I was trained as an engineer. – tlfong01 6 mins ago   
  • I always remember one subject I learned “Engineer in Society” (UK CEI Exam Part II Subject) which is like mdic guys’ “Ethics in Medi” which tell us future engineers that “Thous shalt not over sell any product, taking advantage that you know more than others, for any reason, …” – tlfong01 6 mins ago   
  • PS – I had two version of the hype sensitive devices, all together about 6, or 7. Then I bought two more lots, of two or three newer versions. In ohter words, my junk box has over 20 different PIR devices. A little secret: I was an ex-refugee. As a child, I worked as a child labourer in so called sweat shops, always jealous that other rich children needed not to work and could buy toys, So I am now rich, and can afford to buy toys and play “for” them and suggest what bad toys not tow waste money for. Just reflecting my childhood life aloud, sorry for the typos. – tlfong01 54 secs ago   Edit

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: