Multiple PIR Sensors with Node MCU

Hi Guys,

I’m trying to get two PIR sensors to work off a single NodeMCU.

My script below keeps flooding blynk and the LED is constantly returning a HIGH value.

Any ideas would be greatly appreciated.


//#define BLYNK_DEBUG // Optional, this enables lots of prints
//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
char auth[] = "XXXXXX";

/* WiFi credentials */
char ssid[] = "XXXX";
char pass[] = "XXX";

#define ledPin D7 
#define pirPin1 D1 // Input from PIR 1
#define pirPin2 D2 // Input from PIR 2

int pirValue1; // Place to store read PIR 1 Value
int pirValue2; // Place to store read PIR 2 Value

int pirState = LOW;
int val;

void setup()
   Blynk.begin(auth, ssid, pass);
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin1, INPUT);
  pinMode(pirPin2, INPUT);


void loop()

void getPirValue(void)
  pirValue1 = digitalRead(pirPin1);
  pirValue2 = digitalRead(pirPin2);

  if (pirValue1 == HIGH || pirValue2 == HIGH) { 
   digitalWrite(ledPin, HIGH);
    Blynk.notify("T==> Motion detected");  
    if (pirState == LOW) {
     Serial.println("==> Motion detected");
     pirState = HIGH;
   } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
     //Blynk.notify("T==> Motion ended");
   if (pirState == HIGH){
      Serial.println("Motion ended!");
    pirState = LOW;

Putting this in your void loop() is exactly the same as having all those function commands in the loop itself, thus running thousands of times a second… use timed functions instead…