Advertisement
safwan092

Untitled

May 16th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <UniversalTelegramBot.h>
  4.  
  5. #define WIFI_SSID "iPhone 2023"
  6. #define WIFI_PASSWORD "123456789"
  7. #define BOT_TOKEN "6085931323:AAF1MSIq-oPGF7Mth59GI8NMQCDQTt0h6sE"
  8. String chat_id = "-979798140";
  9.  
  10. #define gasSensorPin 34
  11. #define ledPin 15
  12. #define motorPin 18
  13. WiFiClientSecure secured_client;
  14. UniversalTelegramBot bot(BOT_TOKEN, secured_client);
  15.  
  16.  
  17. void setup() {
  18. Serial.begin(9600);
  19. pinMode(gasSensorPin, INPUT);
  20. pinMode(ledPin, OUTPUT);
  21. pinMode(motorPin,OUTPUT);
  22. digitalWrite(ledPin, 0);
  23. digitalWrite(motorPin, 0);
  24. connectToWiFi();
  25. bot.sendMessage(chat_id, "Device is Ready");
  26. delay(1000);
  27. }
  28.  
  29. void loop() {
  30. int gasSensor = analogRead(34);
  31. Serial.println(gasSensor);
  32. if (gasSensor > 2000) {
  33. digitalWrite(ledPin, 1);
  34. digitalWrite(motorPin, 1);
  35. bot.sendMessage(chat_id, "Alert Gas Detected!!");
  36. delay(1000);
  37. }
  38. else {
  39. digitalWrite(ledPin, 0);
  40. digitalWrite(motorPin, 0);
  41. }
  42. delay(1000);
  43. }
  44.  
  45.  
  46. void connectToWiFi() {
  47. Serial.print("Connecting to Wifi SSID ");
  48. Serial.print(WIFI_SSID);
  49. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  50. secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
  51. while (WiFi.status() != WL_CONNECTED)
  52. {
  53. Serial.print(".");
  54. delay(500);
  55. }
  56. Serial.print("\n");
  57. Serial.print("WiFi connected. IP address: ");
  58. Serial.println(WiFi.localIP());
  59.  
  60.  
  61. Serial.print("Retrieving time: ");
  62. configTime(0, 0, "pool.ntp.org");
  63. time_t now = time(nullptr);
  64. while (now < 24 * 3600)
  65. {
  66. Serial.print(".");
  67. delay(100);
  68. now = time(nullptr);
  69. }
  70. Serial.println(now);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement