-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartGasSensor.ino
64 lines (50 loc) · 2.13 KB
/
SmartGasSensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
// WIFI
const char* ssid = "XXXXXXXXXX"; // paste SSID
const char* password = "XXXXXXXXXXXX"; // paste password
// telegram bot
#define BOTtoken "XXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your token
#define CHAT_ID "XXXXXXX" // telegram chat ID
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
const int gasSensor = A0; // gas sensor
bool gasDetected = false;
int count = 3; // message
const int drop = 150; // drop
void setup() {
Serial.begin(115200);
client.setInsecure();
pinMode(gasSensor, INPUT_PULLUP);
Serial.print("Connecting with Wifi: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
bot.sendMessage(CHAT_ID, "Bot <GAS> started", "");
}
void loop() {
int sensorValue = analogRead(gasSensor); // Read A0
if(gasDetected && count){
bot.sendMessage(CHAT_ID, "GAS Leak Detected!!!", "");
Serial.println("GAS Leak Detected");
count -= 1; // Уменьшаем счётчик на 1
delay(10000); // pause 10s
}
if (sensorValue > drop) {
gasDetected = true; // sensor
}
else {
gasDetected = false; // sensor status
count = 3; // Number of messages again 3
}
}