Achmad Ridho AnsoriAidam Alief Ratrisna
Published

IoT-Based Fire Detection Tool Using the Blynk App

The fire detector is powered by the ESP32 nodeMCU which can be controlled remotely via an application using Blynk.

IntermediateFull instructions provided363
IoT-Based Fire Detection Tool Using the Blynk App

Things used in this project

Story

Read more

Schematics

Schematics

Block Diagram

Code

Untitled file

Arduino
/*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

Achmad Ridho Ansori

Achmad Ridho Ansori

1 project • 1 follower
Aidam Alief Ratrisna

Aidam Alief Ratrisna

1 project • 1 follower

Comments