IR sensor E18-D80NK Blynk app counter

Hi.
I have do simple project use Esp8266 and IR sensor E18-D80NK. Objective of my project is count object.I have use Value Dispay Widget on my blynk app but its totally can,t work. Please guide and help me.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

 char auth[] = "jAp8gXO3Sr51tTorOFC1Xnzbw6po9y-E";
 char ssid[] = "realme7i";
 char pass[] = "12345678";

 int IR_Sensor = D0;
 int counter = 0;
 int hitObject = false;


 void setup()
 {
   Serial.begin(9600);
   pinMode(IR_Sensor,INPUT);
   Blynk.begin(auth, ssid, pass);
   Blynk.virtualWrite(V0,"counter = ");
 }
 void loop()
 {
    int val = digitalRead(IR_Sensor);

  if( (val == 0) && (hitObject == false) ){
       counter++;
       hitObject = true;
       Blynk.virtualWrite(V0,"counter = ");
  }else if( (val ==1) && (hitObject == true) ) {
       hitObject = false;
 }
 Blynk.run();
 } ```

@Vasan please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

I’m done Sir

My advice would be to attach an interrupt to the pin that has the IR sensor connected to it, and move all of your code, except for Blynk.run(); out of your void loop and perform the hitObject == false) test in your Interrupt Service Routine.

I’d also recommend getting the code working without Blynk first, and writing your results to the serial monitor instead. Once this is working then add the Blynk code back in.

Pete.

Hi sir, my code successfully can read the sensor without blynk, but when i send to blynk its can’t work.

So what changes have you made?

Pete.