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:
- I have NodeMCU close to it. So may be because NodeMCU heatness triggers it.
- Some hot air blow near it. But I don't know. It trigger the false positive even in mid-night.
- It can be trigger by mosquitoes.
- 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);
}