#define BLYNK_TEMPLATE_ID "TMPL5xMhgHtgU"
#define BLYNK_TEMPLATE_NAME "IOT"
#define BLYNK_AUTH_TOKEN "kEKQIgDx4uSwbcfYbEgOd4_zrEgjAFaT"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#define FIRE_SENSOR_PIN 34 // Assuming analog pin for the fire sensor
#define RED_LED_PIN 14
#define BUZZER_PIN 13
WidgetLED led(V1);
void setup() {
Serial.begin(9600);
pinMode(FIRE_SENSOR_PIN, INPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, mySensor);
}
void loop() {
Blynk.run();
timer.run();
}
void mySensor() {
int fireVal = analogRead(FIRE_SENSOR_PIN);
float voltage = (fireVal / 3950.0) * 3.3; // Convert analog value to voltage
float temperatureC = (voltage - 0.5) * 100.0; // Assuming LM35-like sensor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
Blynk.virtualWrite(V1, temperatureC); // Send temperature to Blynk temperature component (V2)
if (temperatureC > 50.0) { // Assuming 50°C as the fire threshold
Serial.println("Fire in the House");
Blynk.logEvent("fire_notification", "High Fire Level Detected");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
led.on();
Serial.println("High Fire Level Detected");
} else {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
led.off();
}
}