[SCM Graduation Project] [hj-009] Natural gas, CO, formaldehyde, toluene, TVOC, CO2 gas detection | Air quality detection | Harmful gas detection

1. Basic introduction

Item name:
Design of natural gas, CO, formaldehyde, toluene, TVOC, CO2 gas detection system based on single-chip microcomputer
Design of air quality detection system based on microcontroller
Design of harmful gas detection system based on microcontroller

Project number: mcuclub-hj-009
Microcontroller type: STM32F103C8T6
Specific functions:
1. Detect the natural gas or coal gas value through MQ-5. If it exceeds the set maximum value, it will sound and light alarm, and turn on the fan and purifier.
2. Use MQ-7 to detect the CO value. If it exceeds the set maximum value, it will sound and light alarm, and turn on the fan and purifier.
3. Use MS1100 to detect the formaldehyde value. If it exceeds the set maximum value, it will sound and light alarm, and turn on the fan and purifier.
4. Use MQ-135 to detect the toluene value. If it exceeds the set maximum value, it will sound and light alarm, and turn on the fan and purifier.
5. Detect the TVOC value and CO2 value through SGP30. If it exceeds the set maximum value, it will give an audible and visual alarm, and turn on the fan and purifier.
6. Set each upper limit value through the buttons, and you can manually control the fan and purifier and switch modes.
7. Display data through the display screen
Extended functions: Send measurement data to the mobile phone through the Bluetooth module, and can control fans and purifiers, and switch modes

2. Data Overview

Physical information

Please add image description

Simulation data

Please add image description

3. Display of some information on 51 microcontroller

1. Physical picture display

Microcontroller model: STC89C52
Power supply interface: TYPE-C
Board type: PCB integrated board, thickness 1.2, two-layer board (upper and lower layers are copper-clad and grounded)
Device type: The components are basically pin type, and some buck chips will use SMD type.

2. Simulation diagram display

Simulation software version: proteus8.9
Circuit connection method: network label connection method
Note: Some physical components are not included in the simulation. They will be replaced by other components with similar working principles in the simulation. This may cause the physical program to be different from the simulation program.

3. Schematic display

Software version: AD2013
Circuit connection method: network label connection method
Note: The schematic diagram only shows the pin diagram of the module, not the internal structure diagram of the module.

4. PCB diagram display

Exported from the schematic diagram, there is a project number in the middle, which is hidden under the base of the microcontroller and will not be seen after inserting the microcontroller.
Two-layer board, top and bottom covered with copper and grounded.

IV. Display of some information on 32 microcontroller

1. Physical picture display

Microcontroller model: STM32F103C8T6
Power supply interface: TYPE-C
Board type: PCB integrated board, thickness 1.2, two-layer board (upper and lower layers are copper-clad and grounded)
Device type: The components are basically pin type, and some buck chips will use SMD type.

2. Schematic display

Software version: AD2013
Circuit connection method: network label connection method
Note: The schematic diagram only shows the pin diagram of the module, not the internal structure schematic diagram of the module.

3. PCB diagram display

Exported from the schematic diagram, there is a project number in the middle, which is hidden under the base of the microcontroller and will not be seen after inserting the microcontroller.
Two-layer board, top and bottom covered with copper and grounded.

5. System block diagram

Drawing software: VISIO
This design uses a single-chip microcomputer as the core controller, plus other modules to form the entire system of this design, including the central control part, the input part and the output part. The central control part adopts a single-chip microcomputer controller, whose main function is to obtain the data of the input part, and finally control the output part after internal processing and logical judgment. The input consists of three parts. The first part is the natural gas detection module, through which the natural gas in the current environment is detected; the second part is the carbon monoxide detection module, through which the carbon monoxide in the current environment is detected; the third part is the toluene detection module, through which the Detect toluene in the current environment; the fourth part is the formaldehyde detection module, through which the formaldehyde in the current environment is detected; the fifth part is the SGP30 module, through which the carbon dioxide and TVOC in the current environment are detected; the sixth part is the analog-to-digital conversion module, This module converts the analog voltage measured by the sensor into a digital quantity; the seventh part is the button module, through which the interface can be switched, the threshold is set, the mode is switched, etc.; the eighth part is the power supply module, through which the entire system can be supplied Provide power. The output consists of three parts. The first part is the display module, through which the monitored data and the set threshold can be displayed; the second part is the relay module, which controls ventilation and purification respectively through two relays; the third part is the sound and light alarm module , when the monitored value is not within the set threshold, an audible and visual alarm will be issued. In addition, the Bluetooth module serves as both input and output. The Bluetooth module is connected to the mobile phone and can transmit the monitored data to the user’s mobile phone. The user can also send instructions through the mobile phone to control the work of the relay and its mode switching. The specific system block diagram is shown in Figure 3.1.

6. Partial program display

Software version: keil5
Note: The logic program and driver are separated and distributed in main.c and other .c files

*******display function
*****/
void Display_function(void)
{
switch(flag_display) //Display different interfaces according to different display mode flags
{
case 0: //Interface 0: measurement interface, showing each measurement value and mode
Oled_ShowString(1, 0, "T:");
sprintf(display_buf,"%d ",trq_value);
Oled_ShowString(1, 2, display_buf);

Oled_ShowString(1, 10, "C:");
sprintf(display_buf,"%d ",co_value);
Oled_ShowString(1, 12, display_buf);

Oled_ShowString(2, 0, "A:");
sprintf(display_buf,"%d ",har_value);
Oled_ShowString(2, 2, display_buf);

Oled_ShowString(2, 10, "J:");
sprintf(display_buf,"%d ",jb_value);
Oled_ShowString(2, 12, display_buf);

Oled_ShowString(3, 0, "O:");
sprintf(display_buf,"%d ",co2_value);
Oled_ShowString(3, 2, display_buf);

Oled_ShowString(3, 10, "V:");
sprintf(display_buf,"%d ",tvoc_value);
Oled_ShowString(3, 12, display_buf);

if(flag_mode == 0)
Oled_ShowCHinese(4,0,"Mode: Automatic");
else
Oled_ShowCHinese(4,0,"Mode: Manual");
break;

case 1: //Interface 1: Display and set the maximum value of natural gas
Oled_ShowCHinese(1,0,"Set the maximum value of natural gas");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",trq_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

case 2: //Interface 2: Display and set the maximum value of carbon monoxide
Oled_ShowCHinese(1,0,"Set the maximum carbon monoxide");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",co_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

case 3: //Interface 3: Display and set the maximum formaldehyde value
Oled_ShowCHinese(1,0,"Set the maximum formaldehyde value");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",har_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

case 4: //Interface 4: Display and set the maximum value of toluene
Oled_ShowCHinese(1,0,"Set the maximum value of toluene");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",jb_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

case 5: //Interface 5: Display and set the maximum carbon dioxide value
Oled_ShowCHinese(1,0,"Set the maximum carbon dioxide");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",co2_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

case 6: //Interface 6: Display and set TVOC maximum value
Oled_ShowCHinese(1,0,"setting");
Oled_ShowString(1,4,"TVOC");
Oled_ShowCHinese(1,4,"maximum value");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",tvoc_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;

default:
break;
}
}

/****
*******Handling function
*****/
void Manage_function(void)
{
if(flag_display == 0) //Measurement interface
{
if(flag_mode == 0) //If in automatic mode
{ //If the value is greater than the set maximum value, ventilation, purification, and triggering the alarm
if(har_value > har_max || trq_value > trq_max || co_value > co_max || jb_value > jb_max || co2_value > co2_max || tvoc_value > tvoc_max)
      {
        RELAY_TF = 1;
        RELAY_JH = 1;
        if(time_num % 5 == 0)
        {
          LED = ~LED;
          BEEP = ~BEEP;
        }
      }
      else
      {
        RELAY_TF = 0;
        RELAY_JH = 0;
        LED = 1;
        BEEP = 0;
      }
}
else //In manual mode, turn off the sound and light alarm
    {
      LED = 1;
      BEEP = 0;
    }
}
else //Set the interface and close the two relays
{
RELAY_TF = 0;
    RELAY_JH = 0;
LED = 1;
BEEP = 0;
}
}