#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL3XvWT_aYr"
#define BLYNK_TEMPLATE_NAME "poject3"
#define BLYNK_AUTH_TOKEN "H7snXVXB3F60Rbts2f70OBtf0vrSloV9"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";

BlynkTimer timer;

#define relay1 32 
#define relay2 33 
#define relay3 25
#define relay4 26
#define relay5 27

DHTesp dhtSensor;
const int DHT_PIN = 15;

#define Trig 18
#define Echo 19
float jarak = 0;
float ketinggian_air = 0;


BLYNK_WRITE (V0)
{
  if(param.asInt()==1){
    digitalWrite(relay1, HIGH);
  }else{
    digitalWrite(relay1, LOW);
  }
}

BLYNK_WRITE (V1)
{
  if(param.asInt()==1){
    digitalWrite(relay2, HIGH);
  }else{
    digitalWrite(relay2, LOW);
  }
}


void baca_jarak()
{
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);

  int duration = pulseIn(Echo, HIGH);
  jarak = duration * 0.034 / 2;
  ketinggian_air = jarak;
}

void setup()
{
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);

  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT);
  
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  Blynk.begin(auth, ssid, pass, "iot.serangkota.go.id", 8080);
}

void loop()
{
  TempAndHumidity  data = dhtSensor.getTempAndHumidity();
  baca_jarak();
  Blynk.virtualWrite(V10, data.temperature);
  Blynk.virtualWrite(V11, data.humidity);
  Blynk.virtualWrite(V12, ketinggian_air);
  Blynk.run();
  timer.run();
}
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module