[SCM Graduation Project] [hj-006-5] Natural gas, CO gas detection | Air quality detection | Harmful gas detection

1. Basic introduction

Item name:
Design of natural gas and CO 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-006-5
Microcontroller type: STC89C52
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. Set the upper limit through the buttons, and you can manually control the fan and purifier and switch modes.
4. 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 gas detection module, through which the natural gas or coal gas and carbon monoxide in the current environment are detected; the second part is the button module, through which the interface can be switched, thresholds set, modes switched, etc.; the third part It is a power supply module through which power can be supplied to the entire system. 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

*******Monitoring function
*****/
void Monitor_function(void)
{
char fasong[256];
if(flag_display == 0) //Measurement interface
{
if(time_num % 10 == 0) //Detect once every 2 seconds
{
if(DO1 == 0)
fgas_value = 60*(Get_Adc_Average(1,1)*3.3/4096.0); //Get gas concentration
else
fgas_value = 0;
if(DO2 == 0)
co_value = 60*(Get_Adc_Average(5,1)*3.3/4096.0); //Get the carbon monoxide concentration
else
co_value = 0;
}
}
\t
if(time_num % 20 == 0) //Send once every 4 seconds
{
sprintf(fasong,"Gas concentration:%dppm\r\\
",fgas_value);
UsartPrintf(USART1,fasong);
sprintf(fasong,"Carbon monoxide concentration:%dppm\r\\
",co_value);
UsartPrintf(USART1,fasong);
}
if(USART1_WaitRecive() == 0)
{
if(strstr((char*)usart1_buf,"A") != NULL) //Switch to automatic mode
{
flag_mode = 0;
}
else if(strstr((char*)usart1_buf,"B") != NULL)//Ventilation switch, purification switch
{
flag_relay = 0;
flag_mode = 1;
}
else if(strstr((char*)usart1_buf,"C") != NULL)//Ventilation is on, purification is on
{
flag_relay = 1;
flag_mode = 1;
}
USART1_Clear();
}
}

/****
*******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 gas and carbon monoxide concentration, mode
Oled_ShowCHinese(1, 0, "Gas:");
sprintf(display_buf,"%dPPM ",fgas_value);
Oled_ShowString(1, 6, display_buf);

Oled_ShowCHinese(2, 0, "Carbon monoxide:");
sprintf(display_buf,"%dPPM ",co_value);
Oled_ShowString(2, 10, display_buf);
\t\t
Oled_ShowCHinese(3, 0, "Mode:");
if(flag_mode == 0)
Oled_ShowCHinese(3,3,"automatic");
else
Oled_ShowCHinese(3,3,"Manual");
break;

case 1: //Interface 1: Display and set the maximum gas value
Oled_ShowCHinese(1,0,"Set the maximum gas value");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",fgas_max);
Oled_ShowString(2, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(2, 7, " ");
}
break;
\t\t\t
case 2: //Interface 2: Display and set the maximum value of carbon monoxide
Oled_ShowCHinese(1,2,"settings");
Oled_ShowCHinese(2,0,"Maximum carbon monoxide value");
if(time_num % 5 == 0)
{
sprintf(display_buf,"%d ",co_max);
Oled_ShowString(3, 7, display_buf);
}
if(time_num % 10 == 0)
{
Oled_ShowString(3, 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(fgas_value > fgas_max || co_value > co_max) //The gas value or carbon monoxide value is greater than the set maximum value
{
RELAY_TF = 1;
RELAY_JH = 1;
flag_alarm = 1;
}
else //If it is between the set upper and lower limits, turn off both relays
{
RELAY_TF = 0;
RELAY_JH = 0;
flag_alarm = 0;
}
}
    else //Manual mode controls the relay according to the button press
{
flag_alarm = 0;
LED = 1;
BEEP = 0;
switch(flag_relay)
{
case 0: // Ventilation switch, purification switch
RELAY_TF = 0;
RELAY_JH = 0;
break;

case 1: // Ventilation on, purification on
RELAY_TF = 1;
RELAY_JH = 1;
break;
default:
break;
}
}
if(flag_alarm == 1 & amp; & amp; time_num %2 == 0) //If there is an abnormality, sound and light alarm
{
LED = ~LED;
BEEP = ~BEEP;
}
else if(flag_alarm == 0)
    {
      LED = 1;
      BEEP = 0;
    }
}
else //Set the interface and close the two relays
{
RELAY_TF = 0;
RELAY_JH = 0;
LED = 1;
BEEP = 0;
}
}