Smoke Detector System Based on 51 Microcontroller

In fire prevention, smoke detectors are the first line of defense for protecting life and property. This article introduces a smoke detection and alarm system based on the 51 microcontroller, which can not only monitor the smoke concentration in real-time but also issue audible and visual alarms when the concentration exceeds the threshold, ensuring timely action can be taken. Next, we will delve into the hardware design, software programming, and implementation principles of this system.

Hardware Design
1. Core Controller: Utilizes the classic 51 series microcontroller (such as STC89C51), responsible for processing sensor data, controlling the alarm device, and the display module.
2. Smoke Sensor: Uses the MQ-2 sensor, which has high sensitivity to smoke and can monitor the smoke concentration in the environment in real-time.
3. Display Module: Selects the LCD1602 liquid crystal display to show the current smoke concentration value and alarm status.
4. Alarm Device: Includes a buzzer and an LED indicator, which trigger audible and visual alarms when the smoke concentration exceeds the preset threshold.
5. Key Module: Sets up three buttons for adjusting the smoke concentration threshold (increase, decrease) and confirming the settings.

Software Programming
The main program flow is as follows:
1. Initialize the system, including LCD display, timer, and interrupt settings.
2. Read the analog signal from the MQ-2 sensor and convert it to a digital signal using ADC0809.
3. Process the data, converting the digital signal into the actual smoke concentration value.
4. Compare the current concentration value with the preset threshold; if it exceeds the threshold, trigger the alarm.
5. Update the LCD display in real-time, including the current concentration value and alarm status.
6. Scan key inputs to adjust the threshold settings.

Here is a key code example from the main program:

#include <reg51.h>// Define pins<br/>sbit LCD_RS = P2^0;<br/>sbit LCD_RW = P2^1;<br/>sbit LCD_EN = P2^2;<br/>sbit Buzzer = P1^0;<br/>sbit LED = P1^1;// Other variable definitions...<br/>int smoke_value; // Store smoke concentration value<br/>int threshold = 100; // Preset smoke concentration threshold<br/>void main() {    // Initialization code...    initLCD();    initADC();    while(1) {        // Read smoke sensor value        smoke_value = readADC();                // Display current concentration value        displayLCD(smoke_value);                // Check if it exceeds the threshold        if (smoke_value > threshold) {            // Trigger alarm            Buzzer = 0; // Turn on buzzer            LED = 0; // Light up LED        } else {            // Turn off alarm            Buzzer = 1;            LED = 1;        }        // Handle key input        handleKeys();    }}

The smoke detection and alarm system based on the 51 microcontroller, with its low cost, high reliability, and ease of implementation, has become an indispensable safety device in both home and industrial environments. Through the study and practice of this project, readers can not only master the basic skills of microcontroller applications but also gain a deeper understanding of sensor technology and the principles of alarm system implementation. I hope this article can provide valuable references for students’ learning and research. If you have any questions or suggestions, please feel free to message me. Thank you!

Leave a Comment