[SCM Graduation Project] [hj-008] Air quality (smoke, natural gas or gas, CO, harmful gas concentration)

1. Basic introduction

Item name:
Air quality (smoke, natural gas or coal gas, CO, harmful gas concentration) system design based on single-chip microcomputer

Project number: mcuclub-hj-008
Microcontroller type: STM32F103C8T6
Specific functions:
1. Use MQ-2 to detect the smoke value. If it exceeds the set maximum value, it will sound and light alarm, and turn on the fan and purifier.
2. 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.
3. 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.
4. Use MQ-135 to detect harmful mixed gas values. If the value exceeds the set maximum value, an audible and visual alarm will be issued, and the fan and purifier will be turned on.
5. Set the upper limit through the buttons, and you can manually control the fan and purifier and switch modes.
6. 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 a picture description

Simulation data

Please add an 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 smoke detection module, through which the smoke in the current environment is detected; the second part is the natural gas detection module, through which the natural gas in the current environment is detected; the third part is the carbon monoxide detection module, through which the Detect carbon monoxide in the current environment; the fourth part is the harmful gas detection module, through which harmful gases in the current environment are detected; the fifth part is the analog-to-digital conversion module, through which the analog voltage measured by the sensor is converted into a digital quantity; The sixth part is the button module, through which you can switch interfaces, set thresholds, switch modes, etc.; the seventh part is the power supply module, through which the entire system can be powered. 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_ShowCHinese(1, 0, "Harmful atmosphere:");
sprintf(display_buf,"%dPPM ",har_value);
Oled_ShowString(1, 8, display_buf);

Oled_ShowCHinese(2, 0, "Natural gas:");
sprintf(display_buf,"%dPPM ",trq_value);
Oled_ShowString(2, 8, display_buf);

Oled_ShowCHinese(3, 0, "Smoke:");
sprintf(display_buf,"%dPPM ",smog_value);
Oled_ShowString(3, 6, display_buf);

sprintf(display_buf,"CO: %dPPM ",co_value);
Oled_ShowString(4, 0, display_buf);

if(flag_mode == 0)
Oled_ShowCHinese(4,6,"automatic");
else
Oled_ShowCHinese(4,6,"Manual");
break;

case 1: //Interface 1: Display and set the maximum smoke value
Oled_ShowCHinese(1,0,"Set the maximum smoke value");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",smog_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 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 3: //Interface 3: 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 4: //Interface 4: Display and set the maximum value of harmful gases
Oled_ShowCHinese(1,0,"Set the maximum harmful gas");
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;

default:
break;
}
}

/****
*******Handling function
*****/
void Manage_function(void)
{
if(flag_display == 0) //Measurement interface
{
if(flag_mode == 0) //If in automatic mode
{
if(smog_value > smog_max || har_value > har_max || trq_value > trq_max || co_value > co_max)//If the value is greater than the set maximum value, ventilation, purification, and triggering the alarm
      {
        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, turn off the two relays and the sound and light alarm
{
RELAY_TF = 0;
    RELAY_JH = 0;
LED = 1;
BEEP = 0;
}
}