Trying to make a bidirectional counter

Hey, im just trying to make a couter whit 2 ir sensor.
the V5 pin dont get updated and even the serial monitor works.
im usin a nodemcu board.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char ssid[] = "";
char pass[] = "";
char auth[] = "";

int irPin1=5;
int irPin2=4;
int count=0;
boolean state1 = true;
boolean state2 = true;
boolean insideState = false;
boolean outsideIr=false;
boolean isPeopleExiting=false;
int i=1;

BLYNK_WRITE(V0)
{
  
  if (!digitalRead(irPin1) && i==1 && state1){
     outsideIr=true;
     delay(100);
     i++;
     state1 = false;
  }

   if (!digitalRead(irPin2) && i==2 &&   state2){
     Serial.println("Entering into room");
     outsideIr=true;
     delay(100);
     i = 1 ;
     count++;
     Serial.print("No of persons inside the room: ");
     Serial.println(count);
     Blynk.virtualWrite(V5, count);
     state2 = false;
  }

   if (!digitalRead(irPin2) && i==1 && state2 ){
     outsideIr=true;
     delay(100);
     i = 2 ;
     state2 = false;
  }

  if (!digitalRead(irPin1) && i==2 && state1 ){
     Serial.println("Exiting from room");
     outsideIr=true;
     delay(100);
       Serial.print("No of persons inside the room: ");
       Serial.println(count);
       Blynk.virtualWrite(V5, count);
     i = 1;
     state1 = false;
  }  

    if (digitalRead(irPin1)){
     state1 = true;
    }

     if (digitalRead(irPin2)){
     state2 = true;
    }
 }

void setup()
{
// Debug console
Serial.begin(9600);
pinMode(irPin1, INPUT);
pinMode(irPin2, INPUT);

Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}

Why are you trying to read your sensors within the BLYNK_WRITE(V0) callback function?

BLYNK_WRITE(vPin) is a special function which is called once, whenever thee value of the widget attached to the vPin changes in the app. This is used to let you know that, let’s say, a button within the app has been pressed.

You need to change your code structure and do one of two things…

  1. Attach interrupts to your PIT pins so that a specified function, known as an interrupt handler, will execute each time the PIR detects movement

or

  1. Use a BlynkTimer to poll the PIR sensors on a regular basis (every 100ms?) to see if they have been activated.

Pete.

Hi @PeteKnight In fact, I’m trying to adapt a code I found on the internet to work with blynk.
I’m new to coding, so I thought it was the right way