Sensor Report
Sensor Report
By
Guide:
Prof. Snehal Gholap
Assistant Professor
1 Introduction 3
2 Theory 3
3 Block Diagram 4
4 Flowchart 5
5 Code 6
6 Application 7
7 Conclusion 8
Introduction
This project focuses on detecting smoke and temperature in real-time using the MQ-2 gas
sensor and the DHT11 temperature sensor. When critical levels of smoke or temperature
are detected, it triggers an LED alert, providing an early warning to prevent potential fire
hazards, making it a crucial part of safety systems.
Theory
The MQ-2 sensor is highly sensitive to smoke and gases like LPG, methane, and carbon monoxide, while
the DHT11 sensor measures ambient temperature and humidity. By monitoring both parameters
simultaneously, the system ensures that any irregularities, such as excessive smoke or heat, are flagged
instantly, allowing for rapid intervention. The LED serves as a visual alarm for the user
Block Diagram
Algorithm
Code
#include <DHT.h>
// Define pins
#define MQ2_PIN A0 // Analog pin for
MQ-2
#define DHTPIN 2 // Digital pin for
DHT11
#define LED_PIN 8 // Digital pin for
LED
#define DHTTYPE DHT11 // DHT 11 sensor
// Thresholds
const int smokeThreshold = 300; // MQ-
2 threshold (tune if needed)
const float tempThreshold = 45.0; //
Temperature threshold
unsigned long previousMillis = 0; //
Timer for simulation blinking
bool simulateBlinkState = false;
void setup() {
pinMode(MQ2_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
dht.begin();
}
void loop() {
bool simulateMode = false;
int smokeValue = analogRead(MQ2_PIN);
float temperature = dht.readTemperature();
if (!simulateMode) {
// Real detection
if (smokeValue > smokeThreshold ||
temperature > tempThreshold) {
digitalWrite(LED_PIN, HIGH);
Serial.println("Warning! Smoke or High
Temp Detected!");
} else {
digitalWrite(LED_PIN, LOW);
}
} else {
// Simulation: Blink every 30 sec, stay on
for 5 sec
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >=
30000 || simulateBlinkState) {
if (!simulateBlinkState) {
digitalWrite(LED_PIN, HIGH);
simulateBlinkState = true;
previousMillis = currentMillis;
Serial.println("Simulated LED ON");
} else if (currentMillis -
previousMillis >= 5000) {
digitalWrite(LED_PIN, LOW);
simulateBlinkState = false;
Serial.println("Simulated LED OFF");
previousMillis = currentMillis;
}
}
}
Application
Home Safety: Detects smoke or gas leaks in kitchens and living areas, preventing fire
hazards.
Offices & Server Rooms: Helps monitor temperature surges to avoid overheating and damage to electronic
equipment.
Warehouses & Factories: Early smoke detection can prevent large-scale industrial fires.
Educational Projects: Great for learning IoT, sensors, and automation basics in engineering and science
fields.
Smart IoT Integration: Can be combined with smart home systems for real-time alerts and automatic
responses.
Conclusion
The smart detection system provides real-time monitoring of environmental conditions with a focus on
early detection of smoke and temperature variations. By triggering timely alerts via a simple LED, it
empowers users to take immediate action, significantly improving safety in various settings while
utilizing cost-effective, reliable hardware.
10