Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
RAJVARDHAN DEEPAK SHENDE
Created December 11, 2023

IoT-Based Fire Detection Tool Using the Blynk App

Fire detection,smoke detector etc ..alarm using blynk app

IntermediateProtip15 hours3
IoT-Based Fire Detection Tool Using the Blynk App

Things used in this project

Story

Read more

Schematics

img_20231203_181528_png_0wjrcmfzux_GNBGfK99h2.jpg

IoT-Based Fire Detection Tool Using the Blynk App

Code

IoT-Based Fire Detection Tool Using the Blynk App

C/C++
IoT-Based Fire Detection Tool Using the Blynk App
/*Fill-in information from Blynk Device Info here*/
#define BLYNK_TEMPLATE_ID "TMPL61hMUXeUk"
#define BLYNK_TEMPLATE_NAME "Deteksi Kebakaran DHT11"
#define BLYNK_AUTH_TOKEN "P5nX9v5hZo21w4TfAqSrT8btIxviwsDq"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

//Replace with your network credentials
char ssid[] = "realme"; 
char pass[] = "bebaswes";

#define DHTPIN 32
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

int value1 = 0;
int value2 = 0;
bool autoMode = false;
int temperatureThreshold = 90; // Initial temperature threshold
int ledPin = 27; // Pin connected to the LED
int buzzer = 25; // Pin connected to the buzzer
int hold = 0;

BLYNK_WRITE(V0) {
  int value = param.asInt();
  Blynk.virtualWrite(V1, value);
  Serial.println(value);
  if (!autoMode) {
    // In manual mode, use the button (V0) to control the LED
   digitalWrite(ledPin, value == 1);
    digitalWrite(buzzer, value == 1);
    value1 = 0;
    value2 = 0;
    Blynk.virtualWrite(V6, value2);
        Blynk.virtualWrite(V7, value1);
        
  }
}

BLYNK_WRITE(V2) {
  int value = param.asInt();
  Blynk.virtualWrite(V3, value);
  Serial.println(value);
  autoMode = (value == 1);
  if (autoMode) {
    // In auto mode, update the LED state based on the temperature threshold
    updateLEDState();
  }
}


BLYNK_CONNECTED() {
  Blynk.setProperty(V8, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V8, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V8, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
void myTimerEvent() {
  Blynk.virtualWrite(V9, millis() / 1000);
  sendSensor();
  if (autoMode) {
    // Update the LED state based on the temperature threshold in auto mode
    updateLEDState();
  }
}
void sendSensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V4, t);
}

void updateLEDState() {
  if (autoMode) {
    // Check and update the LED state based on the temperature threshold
    float t = dht.readTemperature();
    if (!isnan(t)) {
      if (t>= 33){
       digitalWrite(ledPin, LOW);
       digitalWrite(buzzer, HIGH); 
      }
     else if (t>=31) {
      digitalWrite(ledPin, HIGH);
      digitalWrite(buzzer, LOW); 
    }
     else  {
      digitalWrite(ledPin, LOW);
      digitalWrite(buzzer, LOW);
    }
  }
}
}
void BlynkNotify(){
  Serial.println("BlynkNotify");
  if(autoMode){
    float t = dht.readTemperature();
    Serial.print("Temperature: ");
    Serial.println(t);

    if (!isnan(t)){
      if(t>=33){
        value1 = 1;
        value2 = 0;
        Serial.println("Turning on LED for V7");
        Blynk.virtualWrite(V7, value1); 
        Blynk.virtualWrite(V6, value2);  
      }
      else if (t >= 31) {
        value1 = 0;
        value2 = 1;
        Serial.println("Turning on LED for V6");
        Blynk.virtualWrite(V6, value2);
        Blynk.virtualWrite(V7, value1); 
      }
      else{
        value1 = 0;
        value2 = 0;
        Blynk.virtualWrite(V7, value1);
        Blynk.virtualWrite(V6, value1);

      }
    }
  }
}


void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT); // Pin connected to the LED
  pinMode(buzzer, OUTPUT); // Pin connected to the buzzer
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  dht.begin();
  autoMode = false;
}

void loop() {
  Blynk.run();
  timer.run();
  BlynkNotify();
  updateLEDState();
  delay(3000);
}

Credits

RAJVARDHAN DEEPAK SHENDE
1 project • 0 followers

Comments