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()
//  digitalWrite (SIGNAL_PIN, LOW);

void loop() {

    static uint32_t lastSeenHigh = millis();
    static bool pirState = false;

    // 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");
  • 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 '19 at 9:08
  • i tried doing adjustments. And it didnt work the way i wanted it. – user3201500 May 4 '19 at 9:12
  • can you share your code and schematic? – Vaibhav May 4 '19 at 9:16
  • Change INPUT_PULLUP to INPUT_PULLDOWN as you are looking for HIGH event. – Vaibhav May 4 '19 at 9:46

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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