BLYNK - PIR Sensor code not showing any output

So in this project, I’m trying to connect my PIR sensor switch on Blynk to switch on/off through my phone.
Although this code compiles just fine, I’m not getting any output from the PIR sensor or LED. I connect it through an ESP8266-01 with my Arduino board. I can control the LED on/off with GPIO pin on my ESP8266-01 with Blynk, but I can’t do the same with digital pins
So now I’m confused with either my code has an error or just my PIR sensor is not working. Please help. Thank you guys in advance.

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

int led = 9;
int sensor =2;
int state = LOW;    //default, no motion detected
int val = 0;       //variable to store sensor data status

char auth[] = "*******************";
char ssid[] = "***********";
char pass[] = "**********";

void setup(){
  Serial.begin(115200); //getting ready to communicate
  Blynk.begin(auth, ssid, pass);
  pinMode(led,OUTPUT);    //define led as the output
  pinMode(sensor, INPUT);   //define sensor as the input
 }


void pirSensor(){
  val = digitalRead(sensor);    //read sensor input
  if(val == HIGH){    
    digitalWrite(led,HIGH);     //if value is high, led light up
    delay(500);

    if(state == LOW){     //if pir state is low
      Serial.println("Motion Detected!");   //print this line
      state = HIGH;   //????
    }
  }
  else if(state == HIGH) {
          digitalWrite(led, LOW);   // if not led turn off
          delay(500);
          Serial.println("Motion Stopped!");    // print this line
          state = LOW; 
          }
  
}

  BLYNK_WRITE(V0){
    int led = param.asInt(); //led is connected to virtual pin 0
     }
     
void loop(){
  Blynk.run();
  
}

edit and hide your authS

Read this:

Pete.

Hi sorry I’m a newbie so bear with me thanks.

So just to clarify, I’m currently uploading my code to ESP instead of Arduino. So I need to code AT commands in order to let my ESP to work as a WIFI modem. Am I right?

No, you need to re-flash the ESP-01 with suitable AT firmware (this can’t be done via the Arduino IDE, you need a special software tool) then upload a sketch to the Arduino that uses the <BlynkSimpleShieldEsp8266.h> library to handle AT communications in the background.

Or, you could save yourself a lot of pain and dump the Arduino and ESP-01 in the appropriate receptacle and use a NodeMCU or ESP32 board instead…

Pete.

Why dont you straight away use a NODEMCU or ESP32 ? These are much simpler n more powerful !! ESP01 as modem is at times hard to get them working. Trust me its was annoying to play with them!!!

This is because, these are the components that I’m suppose to work with. I know NodeMCU and ESP32 is way better, how I wish I can use that for my project.