Advertisement
safwan092

Untitled

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