2

I have a PIR sensor which I use to detect the motion and turn ON and OFF the lights on the basis of it.

I have PIR connected with NodeMCU (ESP8266) based board. I find that sometimes it trigger false positive value. Even when there is no motion. As per my understanding I think any of the following reasons can be there:

  1. I have NodeMCU close to it. So may be because NodeMCU heatness triggers it.
  2. Some hot air blow near it. But I don't know. It trigger the false positive even in mid-night.
  3. It can be trigger by mosquitoes.
  4. I have my other electric wires going from near by.

I am considering these scenarios correct? If yes then how can I prevent from them?

I tried to put it in a box and make it tightly pack. but still its false trigger. I checked even with multiple sensors and have same problem.

Any suggestions to protect this? I also check people put capacitor to smooth it. And put some resistance on Vin.

My Vin of PIR is connected to 5v and OUTPUT pin to D2.

For reference I am having this code for checking.

#define SIGNAL_PIN D2

void setup()
{
  Serial.begin(115200);
  pinMode(SIGNAL_PIN, INPUT_PULLUP);
//  digitalWrite (SIGNAL_PIN, LOW);
}


void loop() {

    static uint32_t lastSeenHigh = millis();
    static bool pirState = false;
    Serial.println(digitalRead(SIGNAL_PIN));

    // If it's active then record that fact along with the time
    if (digitalRead(SIGNAL_PIN) == HIGH) {
        lastSeenHigh = millis();
        pirState = true;
    } else {
        if ((millis() - lastSeenHigh) > 10000) {
            pirState = false;
        }
    }

    if (pirState == true) {
        Serial.println("Pir Is active");
    }
//
    if (pirState == false) {
      Serial.println("PIR sensor inactive");
    }
    delay(1000);
}
6
  • Basic PIR sensor (HC-SR501) contain sensitivity adjustment that will adjust the sensitivity range. Here the link that will help you with adjustment PIR
    – Vaibhav
    May 4, 2019 at 9:08
  • i tried doing adjustments. And it didnt work the way i wanted it. May 4, 2019 at 9:12
  • can you share your code and schematic?
    – Vaibhav
    May 4, 2019 at 9:16
  • Change INPUT_PULLUP to INPUT_PULLDOWN as you are looking for HIGH event.
    – Vaibhav
    May 4, 2019 at 9:46
  • 2
    LOL. Those sensors and boards are so cheap I built two motion sensors. Lights come on only when both agree there is movement in the room. I'm using Home Assistant to coordinate the automation, but maybe something ingenious could be done for them to communicate directly.
    – azoe
    Aug 8, 2021 at 7:12

4 Answers 4

1

I had the same issue. PIRs have very sensitive circuitry and can be triggered by the WiFi signal from the ESP8266. The answer is to move them apart and with some decoupling of the power supply lines you should see much better performance. My PIR and ESP are now a couple of metres apart and I use shielded cable to connect them together.

1

I had the same issue. I tried various solutions on the net. Finally i solved my issue like this.

  • Supplied the PIR sensor 3.3 v (from the NodeMcu board) instead of 5v (my main PS is 5V)
  • Connected VCC (3.3v) cable to "HIGH PIN" of trigger pins instead of main (+) pin.
  • It's not generate false positive signals about 2 hours.

Actually, I'm applied that solution -> https://www.youtube.com/watch?v=2HbbQIqJHoE

1

I was also going through the same issue. But finally, the issue got resolved.

The issue is the PIR sensor that comes with ESP8266 can work with 3.3V as well as 5V. By default, the wiring is connected to the 5V which may work fine for the Arduino device but not for ESP8266.

I just removed the red cable (power cable) from the connector and connected to the other side where you can see H. That side also there are 3 pins. Remove the jumper completely and connect to the first PIN from top.

Just make sure you leave the GND and OUTPUT as it is, but only the RED wire will be connected to the first pin on the other side of the PIR sensorplease see the attached image.

1

I glued some aluminum foil onto a piece of a cereal box and folded it around the PIR sensor. Works like a charm!

1
  • Nice Hack, is it reliable can you share a image how it looks like in the end ? Nov 3, 2022 at 7:23

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.