Chapter no.1 …..
Introduction
Introduction:
Smoke detection is critical in fire safety, providing early alerts to prevent potential hazards. Traditional
smoke detectors are effective but often lack advanced connectivity and real-time monitoring features. This
project introduces an IoT-based smoke detector using the ESP32 microcontroller, which combines smoke
detection with smart connectivity to enhance safety.
A smoke detector using ESP32 is an innovative and affordable approach to building a smart smoke
detection system that leverages IoT capabilities. Traditional smoke detectors are standalone devices
limited to sounding an alarm when smoke is detected. By integrating the ESP32 microcontroller, which has
built-in Wi-Fi and Bluetooth capabilities, this smoke detector can be transformed into a connected device
that not only detects smoke but also provides real-time alerts to a user’s smartphone, allowing for remote
monitoring and control.
The project uses a smoke sensor, such as the MQ-2 or MQ-135, to detect smoke, combustible gases,
or changes in air quality. When smoke levels reach a predefined threshold, the ESP32 sends a signal
to trigger an alarm or send notifications through platforms like Blynk or IFTTT. This smart detector is
highly adaptable, supporting various features like data logging, remote notifications, and even integration
with smart home systems for automated responses.
In addition to enhancing home safety, this project demonstrates a practical application of IoT for real-world
problem-solving. By creating a smart smoke detector, developers and hobbyists gain hands-on experience
with sensor interfacing, wireless communication, data handling, and basic automation.
Purpose of the project:
A smoke detector project using an ESP32 microcontroller serves the purpose of creating an IoT-based fire
and smoke detection system. By combining the ESP32 with a smoke sensor, such as the MQ-2 or MQ-135,
you can build a reliable and responsive smoke detector with smart capabilities like real-time alerts, mobile
notifications, and data logging. Here are some primary purposes for building this project:
1. Early Fire Detection: Detecting smoke early can prevent fires from escalating, minimizing
2. damage and protecting lives. This project will monitor air quality and detect unusual smoke or gas levels.
3. Remote Monitoring: Using ESP32's Wi-Fi capabilities, the system can send alerts to smartphones or
4. other devices, allowing remote monitoring through a mobile app or web interface.
5. Automation and Control: When combined with other smart devices, the ESP32-based smoke detector
6. could trigger automated responses (e.g., activating sprinklers, sounding an alarm, or notifying security).
                                                                                                           1
7. Data Collection and Logging: The ESP32 can track environmental data over time, storing it in the
     cloud for analysis.
8.    This can help identify patterns, such as areas with higher smoke or pollution levels.
9. Educational Application: This project is excellent for learning IoT, sensor interfacing, and
     data communication, offering hands-on experience with ESP32 and IoT concepts.
10. Would you like more specific details, such as circuit design, programming, or features?
                                                                                                      2
                     Chapter no. 2…..System Modelling
          System modeling for a smoke detector using an ESP32 involves designing a structure that
outlines the components, their interactions, and how data flows through the system. The system can be
modeled in several layers: sensor input, data processing, user interface, and connectivity.
Here’s a breakdown:
Materials Description and List:
1)ESP32 Development Board
   Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth, ideal for IoT
   applications.
   The ESP32 collects data from the smoke sensor and sends alerts or data wirelessly to a mobile app
   or
    web interface.
   Purpose: Acts as the main control unit, receiving data from the smoke sensor and processing it for
   display or wireless transmission.
2)Smoke Sensor (MQ-2 or MQ-135)
   Description: These sensors detect smoke, methane, LPG, and other gases. The MQ-2 is suitable
   for
   general smoke and gas detection, while the MQ-135 detects a broader range of gases, including
                                                                                                  3
   carbon dioxide.
   Purpose: Detects smoke or gas particles and sends an analog signal to the ESP32 for processing.
3)Buzzer
   Description: An electronic sound device that emits an audible alarm when activated.
   Purpose: Sounds an alarm when smoke is detected, providing immediate auditory feedback.
4)16x2 LCD Display (I2C Interface)
   Description: A 16x2 character LCD with an I2C module that simplifies wiring by using only two
   pins (SDA and SCL) for data transfer.
   Purpose: Displays real-time data, such as smoke levels, device status, or connection information,
    providing a visual update on the detector's readings.
5)LED (Optional)
   Description: An indicator light that provides a visual alert when smoke is detected.
   Purpose: Lights up when smoke is detected, acting as an additional visual alert.
                                                                                                 4
6)Jumper Wires
   Description: Wires used to connect components in a breadboard or directly to the ESP32.
   Purpose: Facilitates electrical connections between the ESP32, sensor, buzzer, LED, and LCD.
7)Breadboard or PCB (Optional)
   Description: A solderless platform for prototyping circuit connections.
   Purpose: Holds the ESP32, smoke sensor, buzzer, LCD, and other components in place for easy
   testing and modification.
8)Power Supply (5V)
   Description: Provides power to the ESP32 and other components if not using USB power.
   Purpose: Keeps the circuit powered, especially if deploying the project in a location where USB
   power is inconvenient.
                                                                                                5
9)Micro-USB Cable
   Description: A cable used to program the ESP32 and provide power.
   Purpose: Connects the ESP32 to your computer for programming and debugging.
10)Resistors (as needed)
   Description: Passive components used to control current in the circuit, typically required for LEDs
   or other sensitive components.
   Purpose: Ensures proper current levels, especially for LEDs.
                                                                                                 6
                            Chapter no.3……Performance Analysis
3.1)Code:
#include <MQUnifiedsensor.h>
#include <LiquidCrystal.h>
/************************Hardware Related Macros************************************/
#define       Board                 ("ESP32")
#define       Pin               (13)        // GPIO 13 for analog input on ESP32
#define       LEDPin                 (12)      // GPIO 12 for LED
/***********************Software Related Macros************************************/
#define       Type                  ("MQ-2") // MQ2 sensor
#define       Voltage_Resolution            (3.3)     // ESP32 ADC operates at 3.3V
#define       ADC_Bit_Resolution             (12)       // ESP32 ADC has a 12-bit resolution
#define       RatioMQ2CleanAir               (9.83)     // RS / R0 = 9.83 ppm
#define       SmokeThreshold            (1.5)         // Define threshold value for smoke detection
(adjust based on testing)
/************************* LCD Pin Definitions ************************************/
// const int rs = 15;   // Register select pin
// const int en = 2;    // Enable pin
// const int d4 = 4;    // D4 pin
// const int d5 = 16;   // D5 pin
// const int d6 = 17;   // D6 pin
// const int d7 = 5;    // D7 pin
/*****************************Globals***********************************************/
MQUnifiedsensor MQ2(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
                                                                                                      7
void setup() {
 // Initialize the serial port
 Serial.begin(115200);
 // Set LED pin as output
 pinMode(LEDPin, OUTPUT);
 digitalWrite(LEDPin, LOW); // Turn off LED initially
 // Initialize the LCD
 lcd.begin(16, 2);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Smoke Detector");
 // Set the math model to calculate PPM concentration and the values of constants for smoke detection
 MQ2.setRegressionMethod(1); // _PPM = a*ratio^b
 MQ2.init();
 // Calibrate the sensor
 Serial.print("Calibrating, please wait.");
 lcd.setCursor(0, 1);
 lcd.print("Calibrating...");
 float calcR0 = 0;
 for(int i = 1; i <= 10; i++) {
     MQ2.update(); // Read the voltage from the analog pin
     calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
     Serial.print(".");
     delay(200);
 }
                                                                                                 8
    MQ2.setR0(calcR0 / 10);
    Serial.println(" done!");
    lcd.clear();
    if (isinf(calcR0)) {
  Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected). Please check wiring
and supply.");
        lcd.setCursor(0, 1);
        lcd.print("Check wiring!");
        while(1);
    }
    if (calcR0 == 0) {
        Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground).
Please check wiring and supply.");
        lcd.setCursor(0, 1);
        lcd.print("Check wiring!");
        while(1);
    }
    lcd.clear();
}
void loop() {
    MQ2.update(); // Update data, read voltage from the analog pin
    // Set regression constants for LPG to detect smoke
    MQ2.setA(574.25); MQ2.setB(-2.222); // Constants for LPG (suitable for smoke detection)
    float smokeLevel = MQ2.readSensor(); // Read smoke concentration in ppm
    // Check if smoke is detected
                                                                                                     9
    lcd.setCursor(0, 0); // Set LCD to first row
    lcd.print("Status:          "); // Clear previous message
    if (smokeLevel > SmokeThreshold) {
        Serial.println("No Smoke Detected");
        digitalWrite(LEDPin, LOW); // Turn off the LED
        lcd.setCursor(0, 1);     // Move to second row
        lcd.print("No Smoke       "); // Display message
    } else {
        Serial.println("Smoke Detected");
        digitalWrite(LEDPin, HIGH); // Turn on the LED
        lcd.setCursor(0, 1);      // Move to second row
        lcd.print("Smoke Detected"); // Display message
    }
    Serial.println("----------------------------");
    delay(1000); // Wait before the next reading
}
3.2) Block diagram:
                                                                10
3.3)Working model
                    11
                                 Chapter no 4…….Summary
4.1)Advantages
   1. Real-Time Monitoring and Alerts:
         o The ESP32’s Wi-Fi capability allows for immediate remote alerts, enabling users
             to monitor smoke levels on a mobile app or IoT platform.
   2. Cost-Effective and Compact:
         o ESP32-based smoke detectors are relatively affordable compared to commercial smart
            smoke detectors and are compact enough for various spaces.
   3. Multi-Functional:
         o In addition to detecting smoke, the system can integrate additional sensors (e.g.,
            temperature, humidity) to monitor overall air quality, providing valuable environmental
            data.
   4. Power Efficiency:
         o The ESP32 can be configured to operate in low-power modes, increasing battery life
         o if the detector is not plugged in directly.
   5. Customizable and Expandable:
         o The project is highly adaptable for educational purposes or further development. For
            instance, users can add more sensors, link it to other IoT devices, or develop custom alert
            settings.
4.2)Limitations
    1. Sensitivity to Environmental Conditions:
          o Some smoke sensors, such as the MQ-2 or MQ-135, can be influenced by humidity,
               temperature, or other gases, leading to potential false alarms or decreased accuracy.
    2. Wi-Fi Dependence:
          o The ESP32-based detector’s remote alert feature depends on Wi-Fi connectivity. In
               environments with poor Wi-Fi coverage, connectivity issues may prevent timely alerts.
    3. Limited Battery Life:
          o While power-efficient modes help, battery-powered ESP32 setups may still require
               frequent recharging or battery replacements, especially when Wi-Fi is in constant use.
    4. Complexity in Calibration:
          o Calibrating the sensor thresholds to distinguish between benign and harmful levels
               of smoke can be challenging, especially for varied environmental conditions.
    5. Lack of Certification:
          o DIY smoke detectors may not meet regulatory standards for residential or commercial
               safety systems, making them unsuitable as primary safety devices in many locations.
4.3)Applications
    1. Home and Office Safety:
          o Provides early smoke detection and alerts to prevent potential fire hazards in residential
                                                                                                   12
           or small office settings.
2.   Industrial and Laboratory Monitoring:
        o Used to monitor smoke and air quality in small-scale industrial environments, helping
           prevent the buildup of hazardous gases.
3.   Smart Home Integration:
        o Integrates with smart home systems to control devices like fans or sprinklers if smoke is
           detected, adding automation for improved safety.
4.   Educational Projects and IoT Learning:
        o Offers an excellent project for students and hobbyists to learn about IoT, sensor
           interfacing, and real-time data processing.
5.   Environmental Monitoring:
        o When combined with temperature and humidity sensors, it can be used to monitor air
           quality in real-time, suitable for applications like air purification systems or HVAC
           monitoring.
                                                                                               13
                         Chapter no.5……Conclusion & Future Scope
Future Scope
1. Machine Learning for Improved Detection:
       o Integrate machine learning algorithms to differentiate between smoke from harmful
            fires and other benign sources (like cooking smoke), reducing false alarms.
2. Battery Optimization and Energy Harvesting:
       o Improve power efficiency by incorporating energy-harvesting techniques (like solar
           panels) or by optimizing the ESP32’s power modes further, allowing for longer battery
           in off-grid scenarios.
3. Multi-Sensor Integration:
       o Add other air quality sensors to detect CO2, carbon monoxide, or volatile organic
       o    compounds (VOCs) for a comprehensive environmental monitoring system.
4. Cloud Data Analytics:
       o Utilize IoT platforms for cloud storage and data analytics, allowing users to track
       o    long-term smoke and air quality trends, receive predictive alerts, and visualize
       o data on dashboards.
5. Integration with Smart Home Systems:
       o Enable interoperability with smart home devices (e.g., Google Home, Alexa) and
            link to systems like sprinklers or exhaust fans to provide automated responses in the
            event of smoke detection.
6. Mobile App Customization:
       o Develop a dedicated mobile app for real-time monitoring, customization of threshold levels,
            and enhanced notification settings.
7. Certification for Broader Use:
       o Explore options for regulatory compliance, making the system suitable as a certified
       o fire safety device in residential or commercial applications.
                                                                                                14