False alarms with PIR sensor

Hi,

This is my first post on this forum. I am trying to set up a PIR sensor (HC-SR501) on a Photon, but in addition to it responding correctly to movement I keep getting false alarms exactly every 2 minutes. I have connected the bottom pin of the group of three pins at the top of the PIR to the photon’s 3.3v and removed the jumper. I have tried powering from a battery pack too, but the false alarms are still there.

I tried connecting a second PIR so that both had to be activated, but this made no difference. Here’s my code:

STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));

void setup() {
    pinMode(D2, INPUT);
    pinMode(D3, INPUT);
    pinMode(D7, OUTPUT);
}

void loop() {
    digitalWrite(D7,LOW);
        if (digitalRead(D2) == HIGH && digitalRead(D3) == HIGH) {
        digitalWrite(D7,HIGH);
        Particle.publish("PIR", "MOVEMENT DETECTED PIR", 60, PRIVATE);
        while (digitalRead(D2) == HIGH);
    }
}

I would appreciate any input.
Thanks,
Ben

Do you have a meter, logic probe, or oscilloscope that you can make sure that the PIR is falsely triggering?
If not maybe you can connect a led through current limit resistor to the PIR’s output to see when its triggering.

The HC-SR501 requires a supply voltage of 5-20 VDC. The 3V3 output isn’t a high enough voltage to make the sensor work properly, and you’ll get unreliable operation. If you’re powering by USB you can use VIN as an voltage output of approximately 4.8V, which is still below 5V but close enough that the HC-SR501 usually works.

If you’re powering by a LiPo battery you’ll probably need a step-up converter to reliably use that sensor.

4 Likes