TransWikia.com

PIR motion sensor (HC-SR501) false results with NodeMCU

Arduino Asked on January 2, 2022

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);
}

4 Answers

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

Answered by Arthur Smaal on January 2, 2022

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.

Answered by Minhaj Mohammad on January 2, 2022

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

Answered by Emrah AKBIYIK on January 2, 2022

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.

Answered by Bra1n on January 2, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP