safwan092

Untitled

Feb 12th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <UniversalTelegramBot.h>
  4.  
  5. #define sensor 4
  6. #define buzzer 18
  7.  
  8. int sensorValue = 0;
  9.  
  10. #define WIFI_SSID "Yo"
  11. #define WIFI_PASSWORD "yoooyooo1421"
  12. // Telegram BOT Token (Get from Botfather)
  13. #define BOT_TOKEN "5679528950:AAElTI1Gn0HFfiO8LvRb4Jg8Diq5dBMHgaM"
  14. const unsigned long BOT_MTBS = 1000;
  15. WiFiClientSecure secured_client;
  16. UniversalTelegramBot bot(BOT_TOKEN, secured_client);
  17. unsigned long bot_lasttime;
  18. bool Start = false;
  19.  
  20. String text;
  21. String chat_id;
  22. String chat_id_1 = "-837596439";
  23.  
  24.  
  25. void setup()
  26. {
  27. Serial.begin(9600);
  28. pinMode(sensor, INPUT);
  29. pinMode(buzzer, OUTPUT);
  30. digitalWrite(buzzer,LOW);
  31. initWiFi_and_Time_For_Telegram();
  32. bot.sendMessage(chat_id_1, "Project ONLINE");
  33. }
  34.  
  35. void loop() {
  36. sensorValue = digitalRead(sensor);//=0
  37. Serial.println(sensorValue);
  38. if(!sensorValue){
  39. bot.sendMessage(chat_id_1, "Fire Detected Alarm!!!!");
  40. Serial.println("Fire Detected Alarm!!!!");
  41. digitalWrite(buzzer,HIGH);
  42. delay(5000);
  43. }
  44. else{
  45. digitalWrite(buzzer,LOW);
  46. }
  47. delay(100);
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. void initWiFi_and_Time_For_Telegram() {
  55. Serial.println();
  56. Serial.print("Connecting to Wifi SSID ");
  57. Serial.print(WIFI_SSID);
  58. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  59. secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
  60. while (WiFi.status() != WL_CONNECTED)
  61. {
  62. Serial.print(".");
  63. delay(500);
  64. }
  65. Serial.print("\nWiFi connected. IP address: ");
  66. Serial.println(WiFi.localIP());
  67.  
  68. Serial.print("Retrieving time: ");
  69. configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
  70. time_t now = time(nullptr);
  71. while (now < 24 * 3600)
  72. {
  73. Serial.print(".");
  74. delay(100);
  75. now = time(nullptr);
  76. }
  77. Serial.println(now);
  78.  
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment