#define BLYNK_TEMPLATE_ID "TMPL6Ygimrq19"
#define BLYNK_TEMPLATE_NAME "gas leakage monitoring"
#define BLYNK_AUTH_TOKEN "kHzIAm6qKv-G4qZ60UwrptqOmMmn9trr"

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

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

#define DHTPIN 5
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

#define RELAY1_PIN 23
#define RELAY2_PIN 22
#define RELAY3_PIN 19
#define FLAME_PIN 33
#define ALERT_PIN 27

BlynkTimer timer;

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  dht.begin();

  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);
  pinMode(RELAY3_PIN, OUTPUT);  
  
  timer.setInterval(2500L, sendSensor);
  pinMode(FLAME_PIN, INPUT);
 
   Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, sendSensor);
}

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

void sendSensor() {
  
  
  int flame_state=analogRead(FLAME_PIN);
  
  Serial.println("Flame: ");
  Serial.println(flame_state);
  delay(1000);
  Blynk.virtualWrite(V0, flame_state);
  if (flame_state < 2000) {
    Blynk.virtualWrite(V0, 1);
    Blynk.logEvent("fire_alert", "There is a flame");
  }
  else
  {
    Blynk.virtualWrite(V0, 0);
  }  
  delay(500);
  
 
  float t = dht.readTemperature();

  int temperature_0_100 = map(t, -40, 80, 0, 100);

  Blynk.virtualWrite(V3, temperature_0_100);
  Serial.print("Temperature: ");
  Serial.print(temperature_0_100);
  

  if (t > 50) {
    Blynk.logEvent("temp_alert", "Temp above 30 degrees");
  }
}

BLYNK_WRITE(V1) {
  int relay1_state = param.asInt();
  digitalWrite(RELAY1_PIN, relay1_state);
}

BLYNK_WRITE(V2) {
  int relay2_state = param.asInt();
  digitalWrite(RELAY2_PIN, relay2_state);
}

BLYNK_WRITE(V4) { 
  int relay3_state = param.asInt();
  digitalWrite(RELAY3_PIN, relay3_state);
}
$abcdeabcde151015202530fghijfghij
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module