//จำลองesp32 wifi x Blynk บนWokwi
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6w8yzlI9x"
#define BLYNK_TEMPLATE_NAME "test"
#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).
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
char auth[] = "cftVWY8FFfRX34Ss6MnB190PCdCgAdw1"; // ใส่ Auth Token ของ Blynk ที่ได้รับจากแอปพลิเคชัน Blynk
#define mq4 34
#define GREEN 16
#define RED 17
int sensorValue = 2;
boolean state = false;
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(mq4, INPUT);
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
timer.setInterval(1000L, sendUptime);
}
void sendUptime()
{
sensorValue = analogRead(mq4);
Blynk.virtualWrite(V1, sensorValue);
Serial.print ("mq6 = "); Serial.print(sensorValue);
Serial.println ("-");
if (sensorValue > 600)
{
//Blynk.notify("Gas Detected!");
digitalWrite(GREEN, LOW);
digitalWrite(RED, HIGH);
}
else
{
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
}
}
void loop()
{
Blynk.run();
timer.run();
}