#define BLYNK_TEMPLATE_ID "TMPL3FDXU5V-v"
#define BLYNK_TEMPLATE_NAME "Hello LED 4"
#define BLYNK_AUTH_TOKEN "KLLxpNcKpvyvqcJGK1buH_yjPArWWWlI"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define MQPIN 34
#define MQSEN V0
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
int gasThresh = 50;
bool gasAlertSent = false;
void setup()
{
Serial.begin(115200);
pinMode(MQPIN, INPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
int mqvalue=analogRead(34);
int mapvalue=map(mqvalue,0,4095,0,100);
Blynk.virtualWrite(MQSEN, mapvalue);
if (mapvalue> gasThresh && !gasAlertSent)
{
Serial.println("High Gas");
Serial.print(mapvalue);
Blynk.logEvent("gas_Alert", "High level of Gas");
gasAlertSent = true;
}
else if (mapvalue < gasThresh)
{
gasAlertSent = false;
}
Serial.print("MQ Value: ");
Serial.println(mapvalue);
}