In this tutorial, we will learn how to create a fire alert system using the Blink platform and ESP32 microcontroller. This system will monitor the status of a fire sensor and send a notification to your mobile device when a fire is detected. Additionally, it will activate a buzzer to provide an audible alert.
Hardware Required:
- ESP32 Development Board
- Fire Sensor Module
- Buzzer
- Jumper Wires
Software Required:
- Arduino IDE
- Blynk App (Available for Android and iOS)
Step 1: Setting up Blynk Dashboard:
Step 2: Wiring the Components:
- Connect the fire sensor module to pin D2 (FIRE_PIN) of the ESP32.
- Connect the buzzer to pin D4 (BUZZER_PIN) of the ESP32.
Step 3: Writing the Arduino Code:
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "Fire Alert"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "YOUR_WIFI_SSID"; // Your WiFi SSID
char pass[] = "YOUR_WIFI_PASSWORD"; // Your WiFi password
#define FIRE_PIN 2 // Pin connected to fire sensor
#define BUZZER_PIN 4
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(FIRE_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
Blynk.run();
int fireStatus = digitalRead(FIRE_PIN);
if (fireStatus == LOW) {
digitalWrite(4, HIGH);
Serial.println("Fire detected! Sending notification...");
Blynk.logEvent("fire", "Fire detected!!!"); // Send notification to Blynk app
delay(3000); // Wait for 3 seconds to avoid multiple notifications
} else {
digitalWrite(4, LOW);
}
delay(1000); // Check fire status every 1 second
}
Replace "YOUR_TEMPLATE_ID"
, "YOUR_AUTH_TOKEN"
, "YOUR_WIFI_SSID"
, and "YOUR_WIFI_PASSWORD"
with your Blynk template ID, authentication token, WiFi SSID, and WiFi password, respectively.
Step 4: Uploading the Code:
- Connect your ESP32 board to your computer using a USB cable.
- Open the Arduino IDE and select the correct board and port from the Tools menu.
- Copy the modified code into the Arduino IDE.
- Click the “Upload” button to compile and upload the code to your ESP32 board.
Step 5: Testing the System:
- Open the Blynk app on your mobile device and start the project you created earlier.
- Verify that you receive a notification on your mobile device and the buzzer activates when the fire sensor detects a fire.
Congratulations! You have successfully built a fire alert system using Blink and ESP32. You can now customize and expand upon this project to suit your needs, such as adding more sensors or integrating with other IoT devices.