Can anyone help me how do i automatically turning on/off the fan with pir sensor

#include <ThingerESP8266.h>

#define USERNAME “”
#define DEVICE_ID “MyNodeMCU”
#define DEVICE_CREDENTIAL “”

#define SSID “esp”
#define SSID_PASSWORD “esp12345”

#define LED D1
#define FAN D0

float PIR=0;
int FanThinger=0;
int PIRAuto=0;
float PIRStat=0;
String MyFan=“OFF”;

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(9600);
pinMode(FAN,OUTPUT);
pinMode(PIR,INPUT);
pinMode(LED, OUTPUT);

digitalWrite(LED,HIGH);
digitalWrite(FAN,HIGH);

thing.add_wifi(SSID, SSID_PASSWORD);

// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing[“led”] << digitalPin(LED);

// resource output example (i.e. reading a sensor value)
thing[“millis”] >> outputValue(millis());
thing[“MyPIR”] >> outputValue(PIRStat);
thing[“MyFan”] >> outputValue(MyFan);

}

void loop() {

PIR = analogRead(A0); //read the value from the sensor
PIR = (5.0 * PIR)/1024.0; //convert the analog data to digital
PIRStat=PIR;

if (digitalRead(LED)==0){

FanThinger=50;
 MyFan="ON MANUAL";

}
if (digitalRead(LED)==1){
FanThinger=0;
}
Serial.print(FanThinger);
Serial.print("\t");
if (FanThinger==0){
if (PIR>0){
Serial.print(“100”);
digitalWrite(FAN,LOW);
MyFan=“ON AUTO”;
}
if (PIR<=0){
Serial.print(“0”);
digitalWrite(FAN,HIGH);
MyFan=“OFF”;
}
}
Serial.println();
delay(500);
thing.handle();
}

I think you are asking in the wrong forum, I suggest you go to arduino forum (for example) and ask for help about how to control your particular process, here we can support you with issues related to communication with your device and the thinger platform.