Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #define sensor 4
- #define buzzer 18
- int sensorValue = 0;
- #define WIFI_SSID "Yo"
- #define WIFI_PASSWORD "yoooyooo1421"
- // Telegram BOT Token (Get from Botfather)
- #define BOT_TOKEN "5679528950:AAElTI1Gn0HFfiO8LvRb4Jg8Diq5dBMHgaM"
- const unsigned long BOT_MTBS = 1000;
- WiFiClientSecure secured_client;
- UniversalTelegramBot bot(BOT_TOKEN, secured_client);
- unsigned long bot_lasttime;
- bool Start = false;
- String text;
- String chat_id;
- String chat_id_1 = "-837596439";
- void setup()
- {
- Serial.begin(9600);
- pinMode(sensor, INPUT);
- pinMode(buzzer, OUTPUT);
- digitalWrite(buzzer,LOW);
- initWiFi_and_Time_For_Telegram();
- bot.sendMessage(chat_id_1, "Project ONLINE");
- }
- void loop() {
- sensorValue = digitalRead(sensor);//=0
- Serial.println(sensorValue);
- if(!sensorValue){
- bot.sendMessage(chat_id_1, "Fire Detected Alarm!!!!");
- Serial.println("Fire Detected Alarm!!!!");
- digitalWrite(buzzer,HIGH);
- delay(5000);
- }
- else{
- digitalWrite(buzzer,LOW);
- }
- delay(100);
- }
- void initWiFi_and_Time_For_Telegram() {
- Serial.println();
- Serial.print("Connecting to Wifi SSID ");
- Serial.print(WIFI_SSID);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.print("\nWiFi connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.print("Retrieving time: ");
- configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
- 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