#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
#define BOTtoken "6837850470:AAGnL1bzelc4irLcpoAJTKffwWmE_LLGJ80"
#define CHAT_ID "-1002085135800"
#define RL 20
#define Ro 2.11
#define RL2 20
#define Ro2 2.11
float GasValue;
float GasValue2;
float VRL;
float VRL2;
float Rs;
float Rs2;
float Ratio;
float Ratio2;
float ppm;
float ppm2;
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
int GASPIN = 34;
int GASPIN2 = 35;
int FIREPIN = 32;
int FIREPIN2 = 33;
void setup() {
Serial.begin(115200);
pinMode (GASPIN, INPUT);
pinMode (GASPIN2, INPUT);
pinMode (FIREPIN, INPUT);
pinMode (FIREPIN2, INPUT);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
#ifdef ESP32
client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
#endif
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println(WiFi.localIP());
}
void loop() {
MQ6();
MQ62();
if(ppm>200){
String NotifGas1 = "Peringatan! Terdeteksi Kebocoran Gas LPG di Area A\n";
NotifGas1 += "Kadar Gas = ";
NotifGas1 += ppm;
NotifGas1 += " PPM\n";
bot.sendMessage(CHAT_ID, NotifGas1, "");
delay(2000);
}
else {
}
}
void MQ6(){
GasValue = analogRead(GASPIN);
VRL = GasValue*(3.3/4095.0);
Rs = ((3.3/VRL)-1)*RL;
Ratio = Rs/Ro;
ppm = pow(10,((log10(Ratio)-log10(17.1484))/(-0.4114)));
Serial.println(GasValue);
delay(1000);
}
void MQ62(){
GasValue2 = analogRead(GASPIN2);
VRL2 = GasValue2*(3.3/4095.0);
Rs2 = ((3.3/VRL2)-1)*RL2;
Ratio2 = Rs2/Ro2;
ppm2 = pow(10,((log10(Ratio2)-log10(17.1484))/(-0.4114)));
delay(1000);
}