1

So I bought three HC-SR501 PIR and all of them keep trigging (high) every single 60 second on the dot. I don't know what I am doing wrong. The PIR does detect motion when a person is moving but it will also still trigger on the same second, every 60 second. I am using raspberry pi 4 with Raspbian 32 Bullseye OS. The only hardware I am using are the PIR sensor HC-SR501, raspberry pi 4 (with a case), 24 AWG jumper cable (that connects the PIR to the PI), and power to the PI. The things I have tried so far to fix this issue, but with no avail are:

  1. Fixing my python code
  2. Using different GPIO pins
  3. Using the other 5V pin
  4. Changing the delay settings on the PIR
  5. Changing the sensitivity settings PIR
  6. Changing the single trigger mode/repeatable trigger mode on the PIR(I am wanting to use the single trigger mode)
  7. Shorten the 24 AWG jumper cable from 12 inches to ~6 inches
  8. Changing to different house outlet for the power to raspberry pi
  9. Changing the power cord of the raspberry pi
  10. sudo apt-get update and also upgrade

This is my code:

import RPi.GPIO as GPIO
import time
from datetime import date
PIR = 21

GPIO.setwarnings(False)  
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR, GPIO.IN)

count = 1 
try:

    while True:
        if GPIO.input(PIR) == 1:
            today = date.today()
            print("Motion Detected event #: ", count)
            count = count + 1
            print("Today's date: ", today)
            timeday = time.strftime("%H:%M:%S")
            print("Time: ", timeday)
            print("----------------------------------------------")
            time.sleep(1)
        else:
            #print("No motion detected")
            time.sleep(1)

        
except KeyboardInterrupt:
    GPIO.cleanup()

This is my output being trigger every 60 second without motion at all (note even if there is motion, it'll still trigger every 60 second, in this case the 38th second on the dot):

enter image description here

How do I get this to stop triggering every single 60 second when there is no motion at all. I only want it to trigger when there is motion being detected.

6
  • I am unsure of the cause of your problem , but this it is very poor code using a tight loop. I suggest you look at gpiozero.readthedocs.io/en/v1.6.2/… This also allows threshold settings.
    – Milliways
    Jun 19, 2022 at 7:35
  • PS DON"T use apt-get - just use apt
    – Milliways
    Jun 19, 2022 at 7:36
  • Try turning off WiFi and Bluetooth forums.raspberrypi.com/viewtopic.php?t=92748
    – CoderMike
    Jun 19, 2022 at 8:42
  • Your looping code seems to print the trig result every second, Using interrupt instead of looping might solve the problem.
    – tlfong01
    Jun 20, 2022 at 2:00
  • Does it trigger without the motion detector attached? You may need to ground pin 21.
    – BobT
    Nov 17, 2022 at 17:45

2 Answers 2

1

I realize this is an old question but I had the exact problem and I have just accidentally solved it...

I had the script making a request to my server every time the PIR was triggered (also using hc-sr501). I left it overnight and checked the next day... 900+ triggers, all at 51 seconds past every minute.

I have actually managed to solve this by placing a diode after the 5v power supply from the pi. I haven't done anything with the ground or output from the sensor, just a diode ('1n4007' to be exact) between the 5V and the sensor and it has fixed it.

I couldn't tell you why but it worked for me so I thought I'd share...

1
  • This diode approach worked for me, although my PIR was triggering every 60 seconds. (Actually measured over a long time it was about 59.75 seconds). I also ran it with just an LED as the output (to be sure the Pi wasn't mis-reading the input). Also odd- the first component on the V-in pin on the board is a diode.
    – Andy Korth
    Sep 28 at 3:12
0

You need to look at your environment to find the cause of the regular pulse.

I suggest you leave monitor.py running for 5 minutes. Perhaps lots of GPIO are affected.

This requires the pigpio daemon to be running (sudo pigpiod).

I also suggest you run piscope.

.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.