Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #define WIFI_SSID "iPhone 2023"
- #define WIFI_PASSWORD "123456789"
- #define BOT_TOKEN "6085931323:AAF1MSIq-oPGF7Mth59GI8NMQCDQTt0h6sE"
- String chat_id = "-979798140";
- #define gasSensorPin 34
- #define ledPin 15
- #define motorPin 18
- WiFiClientSecure secured_client;
- UniversalTelegramBot bot(BOT_TOKEN, secured_client);
- void setup() {
- Serial.begin(9600);
- pinMode(gasSensorPin, INPUT);
- pinMode(ledPin, OUTPUT);
- pinMode(motorPin,OUTPUT);
- digitalWrite(ledPin, 0);
- digitalWrite(motorPin, 0);
- connectToWiFi();
- bot.sendMessage(chat_id, "Device is Ready");
- delay(1000);
- }
- void loop() {
- int gasSensor = analogRead(34);
- Serial.println(gasSensor);
- if (gasSensor > 2000) {
- digitalWrite(ledPin, 1);
- digitalWrite(motorPin, 1);
- bot.sendMessage(chat_id, "Alert Gas Detected!!");
- delay(1000);
- }
- else {
- digitalWrite(ledPin, 0);
- digitalWrite(motorPin, 0);
- }
- delay(1000);
- }
- void connectToWiFi() {
- Serial.print("Connecting to Wifi SSID ");
- Serial.print(WIFI_SSID);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.print("\n");
- Serial.print("WiFi connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.print("Retrieving time: ");
- configTime(0, 0, "pool.ntp.org");
- time_t now = time(nullptr);
- while (now < 24 * 3600)
- {
- Serial.print(".");
- delay(100);
- now = time(nullptr);
- }
- Serial.println(now);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement