Introduction
With the continuous increase in the number of vehicles, automotive exhaust emissions have become a significant source of urban air pollution. The components of automotive exhaust are complex and variable, containing various harmful substances such as methane, carbon monoxide, nitrogen oxides, and PM2.5, which not only pollute the environment but also pose a threat to human health. Especially in enclosed environments like mines, methane leaks and excessive dust levels severely threaten miners’ safety, and the automotive exhaust industry is facing severe challenges in safety production.
In this context, to achieve real-time detection of automotive exhaust parameters, prevent methane gas exceeding standards, and reduce the risks of manual inspections, developing a set of automotive exhaust detection systems based on the 51 microcontroller has significant practical significance.
Project Acquisition:Design of Automotive Exhaust Detection System Based on 51 Microcontroller and Proteus Simulation
System Design Overview
This system is based on the 51 microcontroller as the core control unit, integrating various sensor modules to monitor key parameters in automotive exhaust in real-time:
-
DHT11 Temperature and Humidity Sensor: Detects environmental temperature and humidity
-
PM2.5 Sensor: Detects the concentration of PM2.5 particles in the air
-
MQ-2 Methane Gas Sensor: Detects methane gas concentration
-
LCD1602 Display Module: Displays monitoring data in real-time
-
Buzzer Alarm Module: Issues an alarm when parameters exceed the standard
The system sets safety thresholds for various environmental parameters. When gas concentrations, PM2.5, or temperature and humidity values exceed the thresholds, the buzzer alarm is triggered, achieving real-time monitoring of automotive exhaust safety emissions.
Hardware Design
System Architecture
Edit
Core Components
-
STC89C52 Microcontroller: Acts as the main controller of the system
-
DHT11 Sensor: Digital temperature and humidity sensor
-
GP2Y1010AU0F Sensor: PM2.5 detection sensor
-
MQ-2 Sensor: Methane gas detection sensor
-
LCD1602 LCD Screen: 16×2 character LCD display
-
ADC0832 Analog-to-Digital Converter: Used for collecting analog sensor data
Circuit:
Edit
Software Design
Main Program Flow
void main()
{
System_Initialization();
while(1)
{
Key_Processing();
Data_Collection();
Data_Display();
Alarm_Judgment();
Delay(10ms);
}
}
Main Function Code:
#include "main.h"
#include "lcd1602.h"
#include "key.h"
#include "adc.h"
#include "dht11_proteus.h"
/**********************************
Variable Definitions
**********************************/
uchar key_num = 0; // Key scan flag variable
uchar flag_mode_display = 0; // Display mode flag variable
uchar flag_display = 0; // Display interface flag variable
uchar flag_beep_gas = 0; // Buzzer gas flag variable
uchar flag_beep_temp = 0; // Buzzer temperature flag variable
uchar flag_beep_humi = 0; // Buzzer humidity flag variable
uint co2_value = 0; // CO2 concentration value variable
uint ch2o_value = 0; // Formaldehyde concentration value variable
uint ch4_value = 0; // Methane concentration value variable
uint pm25_value = 0; // PM2.5 concentration value variable
uint temp_value = 0; // Temperature value variable
uint humi_value = 0; // Humidity value variable
uint co2_value_max = 700; // Maximum CO2 concentration value variable
uint ch2o_value_max = 80; // Maximum formaldehyde concentration value variable
uint ch4_value_max = 150; // Maximum methane concentration value variable
uint pm25_value_max = 200; // Maximum PM2.5 concentration value variable
uint temp_value_max = 35; // Maximum temperature value variable
uint temp_value_min = 20; // Minimum temperature value variable
uint humi_value_max = 60; // Maximum humidity value variable
uint humi_value_min = 30; // Minimum humidity value variable
uint time_jishi = 0; // 10ms timing variable
/**********************************
Function Declarations
**********************************/
void Delay_function(uint x); // Delay function (ms)
void Key_function(void); // Key function
void Monitor_function(void); // Monitoring function
void Display_function(void); // Display function
void Manage_function(void); // Processing function
/****
******* Main Function
*****/
void main()
{
Lcd1602_Init(); // LCD1602 initialization
Delay_function(50); // Delay 50ms
lcd1602_clean(); // Clear screen
Delay_function(50); // Delay 50ms
DHT11_Init(); // DHT11 initialization
Delay_function(50); // Delay 50ms
while(1)
{
Key_function(); // Key function
Monitor_function(); // Monitoring function
Display_function(); // Display function
Manage_function(); // Processing function
Delay_function(10); // Delay 10ms
time_jishi++; // Timing variable +1
if(time_jishi == 5000)
{
time_jishi = 0;
}
}
}
/****
******* Delay x ms function
*****/
void Delay_function(uint x)
{
uint m,n;
for(m=x; m>0; m--)
for(n=110; n>0; n--);
}
/****
******* Key Function
*****/
void Key_function(void)
{
key_num = Chiclet_Keyboard_Scan(); // Key scan
if(key_num != 0) // If a key is pressed
{
switch(key_num)
{
case 1: // Key 1
flag_mode_display++;
if(flag_mode_display == 9) // Total of 9 modes
flag_mode_display = 0;
lcd1602_clean(); // Clear screen
break;
case 2: // Key 2
if(flag_mode_display == 1) // Mode 1: CO2 max value +1
{
co2_value_max++;
if(co2_value_max > 999)
co2_value_max = 999;
}
if(flag_mode_display == 2) // Mode 2: Formaldehyde max value +1
{
ch2o_value_max++;
if(ch2o_value_max > 999)
ch2o_value_max = 999;
}
if(flag_mode_display == 3) // Mode 3: Methane max value +1
{
ch4_value_max++;
if(ch4_value_max > 999)
ch4_value_max = 999;
}
if(flag_mode_display == 4) // Mode 4: PM2.5 max value +1
{
pm25_value_max++;
if(pm25_value_max > 999)
pm25_value_max = 999;
}
if(flag_mode_display == 5) // Mode 5: Temperature max value +1
{
temp_value_max++;
if(temp_value_max > 99)
temp_value_max = 99;
}
if(flag_mode_display == 6) // Mode 6: Temperature min value +1
{
if(temp_value_max > (temp_value_min + 1))
temp_value_min++;
}
if(flag_mode_display == 7) // Mode 7: Humidity max value +1
{
humi_value_max++;
if(humi_value_max > 99)
humi_value_max = 99;
}
if(flag_mode_display == 8) // Mode 8: Humidity min value +1
{
if(humi_value_max > (humi_value_min + 1))
humi_value_min++;
}
break;
case 3: // Key 3
if(flag_mode_display == 0) // Mode 0: Display measurement value flag +1
{
flag_display++;
if(flag_display == 3) // Total of 3 modes
flag_display = 0;
lcd1602_clean(); // Clear screen
}
if(flag_mode_display == 1) // Mode 1: CO2 max value -1
{
if(co2_value_max > 0)
co2_value_max--;
}
if(flag_mode_display == 2) // Mode 2: Formaldehyde max value -1
{
if(ch2o_value_max > 0)
ch2o_value_max--;
}
if(flag_mode_display == 3) // Mode 3: Methane max value -1
{
if(ch4_value_max > 0)
ch4_value_max--;
}
if(flag_mode_display == 4) // Mode 4: PM2.5 max value -1
{
if(pm25_value_max > 0)
pm25_value_max--;
}
if(flag_mode_display == 5) // Mode 5: Temperature max value -1
{
if(temp_value_max > (temp_value_min + 1))
temp_value_max--;
}
if(flag_mode_display == 6) // Mode 6: Temperature min value -1
{
if(temp_value_min > 0)
temp_value_min--;
}
if(flag_mode_display == 7) // Mode 7: Humidity max value -1
{
if(humi_value_max > (humi_value_min + 1))
humi_value_max--;
}
if(flag_mode_display == 8) // Mode 8: Humidity min value -1
{
if(humi_value_min > 0)
humi_value_min--;
}
break;
default:
break;
}
}
}
/****
******* Monitoring Function
*****/
void Monitor_function(void)
{
if(time_jishi % 50 == 0) // Check every 500ms
{
co2_value = 400 * ((Adc0832_Get_Value(0) / 256.0) * 5) - 1000; // Get CO2 value
ch2o_value = 400 * ((Adc0832_Get_Value(1) / 256.0) * 5) - 1000; // Get formaldehyde value
ch4_value = 400 * ((Adc0832_Get_Value_1(0) / 256.0) * 5) - 1000; // Get methane value
pm25_value = 400 * ((Adc0832_Get_Value_1(1) / 256.0) * 5) - 1000; // Get PM2.5 value
Dht11_Get_Temp_Humi_Value(&temp_value, &humi_value); // Get temperature and humidity values
}
}
/****
******* Display Function
*****/
void Display_function(void)
{
switch(flag_mode_display) // Display different interfaces based on different display mode flags
{
case 0: // Mode 0: Display CO2, formaldehyde, methane, PM2.5, temperature, humidity
switch(flag_display)
{
case 0:
lcd1602_display_str(1, 0, "CO2="); // Display CO2
lcd1602_display_gas(1, 4, co2_value);
lcd1602_display_str(2, 0, "CH2O="); // Display formaldehyde
lcd1602_display_gas(2, 5, ch2o_value);
break;
case 1:
lcd1602_display_str(1, 0, "CH4="); // Display methane
lcd1602_display_gas(1, 4, ch4_value);
lcd1602_display_str(2, 0, "PM2.5="); // Display PM2.5
lcd1602_display_pm25(2, 6, pm25_value);
break;
case 2:
lcd1602_display_str(1, 0, "Temp="); // Display temperature
lcd1602_display_temp(1, 5, temp_value);
lcd1602_display_str(2, 0, "Humi="); // Display humidity
lcd1602_display_humi(2, 5, humi_value);
break;
}
break;
case 1: // Mode 1: Display setting CO2 max value
lcd1602_display_str(1, 0, "CO2_Max=");
lcd1602_display_str(2, 0, "CH2O_Max=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 8, co2_value_max);
lcd1602_display_num(2, 9, ch2o_value_max);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(1, 8, " ");
}
break;
case 2: // Mode 2: Display setting formaldehyde max value
lcd1602_display_str(1, 0, "CO2_Max=");
lcd1602_display_str(2, 0, "CH2O_Max=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 8, co2_value_max);
lcd1602_display_num(2, 9, ch2o_value_max);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(2, 9, " ");
}
break;
case 3: // Mode 3: Display setting methane max value
lcd1602_display_str(1, 0, "CH4_Max=");
lcd1602_display_str(2, 0, "PM2.5_Max=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 8, ch4_value_max);
lcd1602_display_num(2, 10, pm25_value_max);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(1, 8, " ");
}
break;
case 4: // Mode 4: Display setting PM2.5 max value
lcd1602_display_str(1, 0, "CH4_Max=");
lcd1602_display_str(2, 0, "PM2.5_Max=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 8, ch4_value_max);
lcd1602_display_num(2, 10, pm25_value_max);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(2, 10, " ");
}
break;
case 5: // Mode 5: Display setting temperature max value
lcd1602_display_str(1, 0, "Temp_Max=");
lcd1602_display_str(2, 0, "Temp_min=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 9, temp_value_max);
lcd1602_display_num(2, 9, temp_value_min);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(1, 9, " ");
}
break;
case 6: // Mode 6: Display setting temperature min value
lcd1602_display_str(1, 0, "Temp_Max=");
lcd1602_display_str(2, 0, "Temp_min=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 9, temp_value_max);
lcd1602_display_num(2, 9, temp_value_min);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(2, 9, " ");
}
break;
case 7: // Mode 7: Display setting humidity max value
lcd1602_display_str(1, 0, "Humi_Max=");
lcd1602_display_str(2, 0, "Humi_min=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 9, humi_value_max);
lcd1602_display_num(2, 9, humi_value_min);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(1, 9, " ");
}
break;
case 8: // Mode 8: Display setting humidity min value
lcd1602_display_str(1, 0, "Humi_Max=");
lcd1602_display_str(2, 0, "Humi_min=");
if(time_jishi % 20 == 0)
{
lcd1602_display_num(1, 9, humi_value_max);
lcd1602_display_num(2, 9, humi_value_min);
}
if(time_jishi % 40 == 0)
{
lcd1602_display_str(2, 9, " ");
}
break;
default:
break;
}
}
/****
******* Processing Function
*****/
void Manage_function(void)
{
if(flag_mode_display == 0) // When display mode is 0
{
if(co2_value > co2_value_max || ch2o_value > ch2o_value_max || ch4_value > ch4_value_max || pm25_value > pm25_value_max) // Gas concentration exceeds set concentration
{
RELAY_MOTOR = 0; // Fan relay pulled low to enable
RELAY_JINGHUA = 0; // Air purification relay pulled low to enable
flag_beep_gas = 1; // Buzzer gas flag set to 1
}
else // Gas concentration is below set concentration
{
RELAY_MOTOR = 1; // Fan relay pulled high to disable
RELAY_JINGHUA = 1; // Air purification relay pulled high to disable
flag_beep_gas = 0; // Buzzer gas flag set to 0
}
if(temp_value > temp_value_max * 10) // Temperature exceeds set maximum temperature
{
RELAY_TEMP_UP = 1; // Heating relay pulled high to disable
RELAY_TEMP_DOWN = 0; // Cooling relay pulled low to enable
flag_beep_temp = 1; // Buzzer temperature flag set to 1
}
else if(temp_value < temp_value_min * 10) // Temperature is below set minimum temperature
{
RELAY_TEMP_UP = 0; // Heating relay pulled low to enable
RELAY_TEMP_DOWN = 1; // Cooling relay pulled high to disable
flag_beep_temp = 1; // Buzzer temperature flag set to 1
}
else // Temperature is within threshold
{
RELAY_TEMP_UP = 1; // Heating relay pulled high to disable
RELAY_TEMP_DOWN = 1; // Cooling relay pulled high to disable
flag_beep_temp = 0; // Buzzer temperature flag set to 0
}
if(humi_value > humi_value_max * 10) // Humidity exceeds set maximum humidity
{
RELAY_HUMI_UP = 1; // Humidifier relay pulled high to disable
RELAY_HUMI_DOWN = 0; // Dehumidifier relay pulled low to enable
flag_beep_humi = 1; // Buzzer humidity flag set to 1
}
else if(humi_value < humi_value_min * 10)
{
RELAY_HUMI_UP = 0; // Humidifier relay pulled low to enable
RELAY_HUMI_DOWN = 1; // Dehumidifier relay pulled high to disable
flag_beep_humi = 1; // Buzzer humidity flag set to 1
}
else
{
RELAY_HUMI_UP = 1; // Humidifier relay pulled high to disable
RELAY_HUMI_DOWN = 1; // Dehumidifier relay pulled high to disable
flag_beep_humi = 0; // Buzzer humidity flag set to 0
}
if(flag_beep_gas == 1 || flag_beep_temp == 1 || flag_beep_humi == 1) // If buzzer gas flag is 1 or buzzer temperature flag is 1 or buzzer humidity flag is 1
{
if(time_jishi % 20 == 0) // Intermittent alarm
BEEP = 0;
if(time_jishi % 40 == 0)
BEEP = 1;
}
else
{
BEEP = 1; // No alarm
}
}
else
{
BEEP = 1; // No alarm
}
}
Key Function Descriptions
Data Collection Function
void Monitor_function(void)
{
if(time_reached_500ms)
{
co2_value = read_CO2_value();
ch2o_value = read_formaldehyde_value();
ch4_value = read_methane_value();
pm25_value = read_PM2.5_value();
Dht11_get_temp_humi_value(&temp_value, &humi_value);
}
}
Display Function
void Display_function(void)
{
switch(display_mode)
{
case 0: // Display monitoring values
switch(display_interface)
{
case 0: display_CO2_and_formaldehyde_values(); break;
case 1: display_methane_and_PM2.5_values(); break;
case 2: display_temp_and_humi_values(); break;
}
break;
case 1: // Display setting interface
// Display each parameter threshold setting interface
break;
}
}
Alarm Handling Function
void Manage_function(void)
{
if(display_mode_is_monitoring_mode)
{
if(any_parameter_exceeds_standard)
{
activate_corresponding_control_device();
trigger_alarm_flag();
}
if(alarm_flag_exists)
{
buzzer_intermittent_alarm();
}
}
}
Proteus Simulation Implementation
Simulation Circuit Design
Build the system simulation circuit in Proteus, including the following main components:
-
Microcontroller minimum system
-
Sensor simulation circuit
-
LCD display module
-
Key input circuit
-
Alarm output circuit
Edit
Simulation Results Analysis
The Proteus simulation can verify:
-
The system can correctly collect data from various sensors
-
The LCD display can normally display monitoring data
-
The alarm system can correctly trigger when parameters exceed the standard
-
The key setting function works normally
The system supports multi-parameter simultaneous alarm function. When both methane concentration and PM2.5 content exceed the standard, it can trigger a composite alarm mode, and the LCD1602 screen can display all detection parameters in real-time. Throughout the testing process, the system’s alarm response time was less than 1 second, with no false alarms or missed alarms.
After the system starts, each sensor begins to collect underground environmental data in real-time, processed by the STC microcontroller, and the data is displayed on the LCD module while being synchronized on the APP side. During debugging, various sensor alarm thresholds were set, including a temperature threshold of 35°C, a gas concentration threshold of 200ppm, and a PM2.5 concentration threshold of 220μg/m³. The system successfully triggered an alarm when the temperature reached 30°C, the gas concentration was 17ppm, and the PM2.5 concentration reached 238μg/m³, with the APP interface popping up “Attention, data anomaly!!!” The system responded promptly, and the prompt was clear, verifying the effectiveness of the threshold judgment and alarm mechanism.
During debugging, it was found that when the PM2.5 concentration exceeded the set threshold, the system prioritized triggering the corresponding alarm information and illuminated the buzzer module to indicate the excess, while users could click the “PM2.5 threshold” button on the interface to reset the threshold.
Edit
Figure 5.3 Experiment 1 Data Anomaly Debugging Results
Through the mobile APP interface, real-time visual monitoring of underground environmental parameters is conducted. The interface displays four key environmental indicators: humidity (41%rh), temperature (30°C), gas concentration (18ppm), and PM2.5 concentration (61μg/m³). The data layout is clear, and the unit labels are accurate, allowing users to easily grasp the current environmental status.
In addition, the bottom of the interface provides three parameter threshold setting entrances, corresponding to temperature, gas, and PM2.5, which can be adjusted in real-time by clicking the “Temperature Threshold”, “Gas Threshold”, and “PM2.5 Threshold” buttons on the right, enhancing the system’s interactivity and flexibility. The currently set thresholds are temperature 35°C, gas 200ppm, and PM2.5 concentration 200μg/m³. A comparison shows that the current temperature, gas concentration, and PM2.5 values are all within a safe range, and no alarms have been triggered.
Edit
Figure 5.4 Experiment 2 Data Normal Debugging Results
The current humidity is 43%rh, temperature is 29°C, gas concentration is 23ppm, and PM2.5 concentration is 110μg/m³. Compared to the previous screenshot, the current data is within a reasonable fluctuation range, but the PM2.5 value has significantly increased from the previous measurement (61μg/m³) to 110μg/m³, approaching the preset threshold upper limit of 200μg/m³.
Edit
Figure 5.3 Experiment 3 Data Normal Debugging Results
During the testing process, some optimization issues were also discovered: in environments with extremely high dust concentrations, the sensors require more frequent cleaning and maintenance; the long-term stability of the system in high-temperature and high-humidity environments needs further verification, and it may be considered to use industrial-grade components to enhance environmental adaptability in the future. In addition, to cope with the complex electromagnetic environment of automotive exhaust underground, it is planned to enhance the EMC protection design of the circuit in the next version.
On the other hand, during the experimental process, there were still some details and shortcomings, as the data collected by the sensors may have slight deviations due to external environmental factors such as temperature fluctuations and humidity changes. Moreover, during the entire system planning and debugging phase, some details were not fully considered, resulting in some minor errors during the experiment.
Project Acquisition:Design of Automotive Exhaust Detection System Based on 51 Microcontroller and Proteus Simulation