#define BLYNK_TEMPLATE_ID "TMPL6fDckRLHQ"
#define BLYNK_TEMPLATE_NAME "Home sicurity"
#define BLYNK_AUTH_TOKEN "ScejWBRzhsWAYZG-6dWSSzHW-14DYNPW"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "ScejWBRzhsWAYZG-6dWSSzHW-14DYNPW";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define MQ2 34
#define FIRE_SENSOR_PIN 15 // Example pin for the fire sensor, change it according to your setup
#define GREEN 16
#define RED 17
int sensorValue = 0;
boolean state = false;
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(MQ2, INPUT);
pinMode(FIRE_SENSOR_PIN, INPUT_PULLUP); // Assuming fire sensor is normally HIGH when not triggered
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
timer.setInterval(1000L, sendUptime);
}
void sendUptime()
{
sensorValue = analogRead(MQ2);
Blynk.virtualWrite(V1, sensorValue);
Serial.println(sensorValue);
if (sensorValue > 600)
{
Blynk.notify("Gas Detected!");
digitalWrite(GREEN, LOW);
digitalWrite(RED, HIGH);
}
else
{
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
}
// Read the state of the fire sensor
boolean fireDetected = digitalRead(FIRE_SENSOR_PIN) == LOW; // Assuming sensor is active LOW
if (fireDetected)
{
Blynk.notify("Fire Detected!");
// You can add more actions here if fire is detected
}
}
void loop()
{
Blynk.run();
timer.run();
}