#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID   "TMPL6jEr8VlQS"
#define BLYNK_TEMPLATE_NAME "buang"
#define BLYNK_AUTH_TOKEN    "gCNOaICiz5DfYya0mc2qUyLPPTRPM-SI"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;

#include <NewPing.h>
#define TRIGGER_PIN  17  
#define ECHO_PIN     16  
#define MAX_DISTANCE 200 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int relayS=2,relayP=15,buzzer=22,ledLock=12;
int locked=0;

BLYNK_WRITE(V0)
{ int sejuk = param.asInt();
  if(locked==0)
    if(sejuk==1) 
      digitalWrite(relayS,HIGH);
  if(locked==1)
  { beep(2,50);
    Blynk.virtualWrite(V0,LOW);
  }
}
BLYNK_WRITE(V1)
{ int panas = param.asInt();
  if(locked==0)
    if(panas==1) 
      digitalWrite(relayP,HIGH);
  if(locked==1)
  { beep(2,50);
    Blynk.virtualWrite(V1,LOW);
  }
}
BLYNK_WRITE(V2)
{ int suam = param.asInt();
  if(locked==0)
    if(suam==1) 
    { digitalWrite(relayS,HIGH);
      digitalWrite(relayP,HIGH);
    }
  if(locked==1)
  { beep(2,50);
    Blynk.virtualWrite(V2,LOW);
  }
}
BLYNK_WRITE(V4)
{ int lock = param.asInt();
  if(lock==1) { locked=1; digitalWrite(ledLock,HIGH); }
  if(lock==0) { locked=0; digitalWrite(ledLock,LOW);  }
}
void beep(int kali, int masa)
{ for(int i=0;i<kali;i++)
  { digitalWrite(buzzer,HIGH); delay(masa);
    digitalWrite(buzzer,LOW);  delay(masa);
  }
}

void cekUltrasonic()
{ Blynk.virtualWrite(V3,sonar.ping_cm());
  if(sonar.ping_cm()<10) 
  { digitalWrite(relayS,LOW); 
    digitalWrite(relayP,LOW); 
    Blynk.virtualWrite(V0,LOW);
    Blynk.virtualWrite(V1,LOW);
    Blynk.virtualWrite(V2,LOW);
  }
}

void setup()
{ pinMode(relayS,OUTPUT);
  pinMode(relayP,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(ledLock,OUTPUT);
  
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(10,cekUltrasonic);
}

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

NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module