Anip Shah
Published © GPL3+

Getting Fire Alert Message on Telegram

Using Esp32 and Flame sensor (IR-sensor) we can get alerts and notification on our phone. Telegram messaging app works better.

IntermediateFull instructions provided1 hour1,133
Getting Fire Alert Message on Telegram

Things used in this project

Hardware components

NodeMCU ESP32 Development Module
×1
IR flame sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Telegram
Arduino IDE
Arduino IDE

Story

Read more

Schematics

screenshot_2022-09-11_071758_SPa9xPixxo.jpg

Code

Untitled file

C/C++
Fill up the credentials properly.
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>

// Replace with your network credentials
const char* ssid = "-------";
const char* password = "-------";

// Initialize Telegram BOT
#define BOTtoken "-------------------"  // your Bot Token (Get from Botfather)
#define CHAT_ID "---------"    // get from ID Bot

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

const int flamesensor = 27; 
bool flameDetected = false;

void IRAM_ATTR detectsFlame() {
  //Serial.println("Fire Alert!!!");
  flameDetected = true;
}

void setup() {
  Serial.begin(115200);

  pinMode(flamesensor, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(flamesensor), detectsFlame, RISING);

  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  client.setCACert(TELEGRAM_CERTIFICATE_ROOT); 
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  bot.sendMessage(CHAT_ID, "Device Activated and iniciating the process.", "");
}

void loop() {
  if(flameDetected){
    bot.sendMessage(CHAT_ID, "Fire Alert!!!", "");
    Serial.println("Fire Alert!!!");
    flameDetected = false;
  }
}

Credits

Anip Shah

Anip Shah

9 projects • 4 followers
Tech enthusiast and programmer who also happens to be a Biomedical Engineer.

Comments