Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 6, No. 1, 2023 3 Design of Air Quality Detection System Based on MCU Chilian Tang Zhongshan Polytechnic College, Zhongshan, 528404, China Abstract: Because of the deterioration of air quality, haze weather phenomenon increased, the phenomenon of increased harm. Many regions in China incorporate the haze phenomenon into the fog as a disastrous weather warning and forecast. Collectively known as“Haze Weather.”. The haze mainly consists of PM2.5, PM10, PM0.1 and heavy metals such as nickel, arsenic, chromium and lead. There have been a number of major smog-related incidents, such as the Great Smog that killed more than 4,000 people in four days and the Beijing smog epidemic in early 2013. Therefore, the measurement of PM2.5 becomes more and more important. This design uses STC89C51 single-chip microcomputer as the control center, by GP2Y1010AU0F dust sensor to measure the air dust concentration, LCD1602 display display current air dust concentration. According to the set alarm value alarm prompt, the corresponding color indicator light is lit, the system circuit is simple, stable, high integration, easy debugging, high testing precision, has a certain practical value. Keywords: PM2.5, SCM, Dust concentration, GP2Y1010AU0F. 1. Introduction Because of the deterioration of air quality, haze weather phenomenon increased, the phenomenon of increased harm. Many regions in China incorporate the haze phenomenon into the fog as a disastrous weather warning and forecast. Collectively known as"Haze Weather.". The smog is mainly composed of PM2.5, PM10, PM0.1 and heavy metals such as nickel, arsenic, chromium and lead. The elderly, children and patients with heart and lung diseases are susceptible to PM2.5 pollution, the monitoring and control of PM2.5 becomes more and more important. The basic realization method of the air quality PM2.5 detection scheme proposed in this design is a circuit composed of a single-chip microcomputer, a dust monitoring sensor, a display module, an alarm module, etc. , the concentration of PM2.5 in the air was collected by GP2Y1010AU0F dust sensor. After processing by STC89C51 single-chip microcomputer, it was displayed on LCD1602 liquid crystal and indicated by LED and buzzer. 2. Hardware Circuit Design 2.1. The system is structured as follows Figure 1. The composition of the system structure diagram 2.2. System overview This circuit is controlled by STC89C51 single-chip microcomputer as the core, in addition, mainly through the circuit design of 5 modules to achieve functions, they are LCD display module, dust sensor, a/D conversion, buzzer circuit, LED indicator circuit. The schematic diagram of the system is shown in figure 2 below: 4 Figure 2. Schematic diagram of the system 2.3. Microcontroller minimum system The minimum system of single-chip microcomputer is a necessary part to make single-chip microcomputer work normally and exert its function. For 51 series microcontroller, the minimum system should generally include: microcontroller, Crystal Circuit, reset circuit, input/output equipment. Microcontroller minimum system block diagram as shown in figure 3 Figure 3. Microcontroller minimum system block diagram 2.4. Reset circuit In the single-chip microcomputer system, reset circuit is very critical, when the program run off (running abnormal) or crash (stop running) , it needs to be reset. MCS-5l series MCU reset pin RST (the 9th pin) appears more than 2 machine cycle high level, the MCU on the implementation of the Reset operation. If the RST continues to be high, the MCU is in a state of cyclic reset. Reset operation usually has two basic forms: power-on automatic reset and switch reset. At the same time, the negative electrode of the capacitor is connected to RESET. The voltage is applied to the resistor. The input of RESET is high and the chip is RESET. With the + 5V power supply to charge the capacitor, the resistance on the voltage gradually reduced, and finally equal to about 0, the chip works normally. The two ends of the capacitor are connected in parallel for the reset button. When the reset button is not pressed down, the circuit realizes power-on reset. After the chip works normally, manual reset is achieved by pressing the button to make the RST pin appear high level. The reset circuit diagram is shown in figure 4: P1 .01 P1 .12 P1 .23 P1 .34 P1 .45 P1 .56 P1 .67 P1 .78 R ST9 P3 .0 (R X D)10 P3 .1 (T XD )11 P3 .2 (IN T0)12 P3 .3 (IN T1)13 P3 .4 (T 0)14 P3 .5 (T 1)15 P3 .6 (W R)16 P3 .7 (R D )17 X TA L218 X TA L119 G ND20 (A8 )P 2 .0 21(A9 )P 2 .1 22(A1 0)P2 .2 23(A1 1)P2 .3 24(A1 2)P2 .4 25(A1 3)P2 .5 26(A1 4)P2 .6 27(A1 5)P2 .7 28PS EN 29A LE/PR O G 30EA /VP P 31(AD 7)P0 .7 32(AD 6)P0 .6 33(AD 5)P0 .5 34(AD 4)P0 .4 35(AD 3)P0 .3 36(AD 2)P0 .2 37(AD 1)P0 .1 38(AD 0)P0 .0 39V CC 40 U 1 89 C5 1 /52 Y 1 12M H z C 2 30 C 3 30 C OM1 R 12 R 23 R 34 R 45 R 56 R 67 R 78 R 89 R P1 10 K V CC R 1 10 K V CC V CC + C 1 10 uF 3 2 1 P1 PO W E R V CC 11 2 233 4 455 6 6 S1 SW IT CH G N D 1 V C C 2 V 0 3 R S 4 R /W 5 EN 6 D 0 7 D 1 8 D 2 9 D 3 10 D 4 11 D 5 12 D 6 13 D 7 14 A 15 K 16 U 5 LC D _16 02 L R 3 10 K R 4 1K D 0 D 1 D 2 D 3 D 4 D 5 D 6 D 7 R S EN D 0 D 1 D 2 D 3 D 4 D 5 D 6 D 7 R S EN C S1 C H02 C H13 G ND4 D I 5D O 6C LK 7V CC 8 U 4 A DC 08 32 V CC V CC V CC 1 2 3 4 5 6 R 5 15 0 + C 4 22 0uF V CC V CC V CC + C 5 47 0uf R 6 22 0 R 7 2 .2k R 8 2 .212 D 1 LE DG 12 D 2 LE DY 12 D 3 LE DR V CC Q 1 90 12 B 1 B ELL R 2 2.2k V CC K 1 K 2 K 3 5 Figure 4. Reset circuit diagram 2.5. Design of dust sensor circuit According to the dust sensor GP2Y1010AU in the planning document for the description of the pin: as shown in figure 5 Figure 5. Sensor GP2Y1010AU pin diagram The circuit design of the dust sensor is shown in figure 6: Figure 6. Circuit diagram of the dust sensor The dust sensor GP2Y1010AU outputs an analog voltage by measuring the concentration of air dust particles, which is proportional to the concentration of dust particles. Therefore, in the schematic diagram of the simulation, we use a local voltage limiting circuit designed by a variable resistor to replace the sensor: 2.6. A/D conversion ADC0832 packaging machine pin description as shown in figure 7: Figure 7. ADC0832 package diagram CS: Chip selection enable, low-level chip enable. CH0: simulate input channel 0, or use as IN +/-. CH1: simulate input channel 1, or use as IN +/-. GND: chip reference 0 potential (ground). DI: Data Signal Input, select channel control. DO: Data Signal output, convert data output. CLK: Chip Crystal Input. VCC/Ref: power input and reference voltage input (multiplexed). 2.7. LCD display module design LCD1602 is used as display device output information in 6 the system. Compared with the traditional LED digital display device, the LCD module has the advantages of small size, low power consumption, rich display content, etc. , according to the pin function circuit design as shown in Figure 8: Figure 8. LCD display circuit diagram Figure 9. Simulation circuit diagram 2.8. Led indicator circuit The red, yellow and green indicator lamp is connected with the P2.0 port P2.1 Port and P3.1 Port of the single-chip microcomputer. Led positive are connected to power supply, when the MCU IO output low-level, the corresponding LED will be lit. The circuit diagram for the LED is shown in figure 10: Figure 10. The schematic of the LED 3. Program Design and Software Application 3.1. Main programming /******************************************** ************************ * name: Main () * function: Main function ******************************************** ***************************/ void main() { uchar h; uint sum; EA = 0; Timer0_Init(); //Timer 0 initializes EA = 1; RW=0; L1602_init(); while(1) { if (FlagStartRH == 1&&set==0) //Check the temperature and humidity conversion mark { TR0 = 0; for(h=0;h<50;h++) { DA=adc0832(0); sum=sum+DA; delay_ms(100); Key(); } DA=sum/50; sum=0; DA=DA*(float)(DA/5); ALARM(); if(set==0) display(); TR0 = 1; } Key(); ALARM(); } } 3.2. The design of the main sub-functions In addition to the main program, the program also defines some functions to facilitate the main program call, mainly LCD initialization program, display function, alarm display, alarm sub-function, a/D conversion function. The following sections focus on the A/D conversion function. Single-chip microcomputer control principle of ADC0832: Under normal circumstances ADC0832 and MCU interface should be 4 data lines, are CS, CLK, DO, Di. But because DO and Di are not effective at the same time in communication and the interface with MCU is bidirectional, so the circuit design can be DO and DI in parallel on a data line to use. (see Figure 3) when the ADC0832 is not working its CS input should be high, when the chip is disabled, CLK and DO/DI levels can be arbitrary. When an A/D conversion is performed, the CS enable end must first be placed at a low level and held at that low level until the conversion is complete. At the same time, the processor inputs the crystal pulse to CLK, and DO/DI uses the data signal selected by the DI input channel. 7 Before the first crystal pulse sinks, the DI terminal must be at a high level, indicating the start signal. Before the 2nd and 3rd Pulse Sinks, the DI terminal should input 2 bits of data for selecting the channel function, its function item see table below. Table 1. Single-chip microcomputer channel function table As shown in Table 1, when the 2-bit data is“1” and“0”, only CH0 is converted to a single channel. When the 2-bit data is“1”, “1”, only the CH1 single-channel conversion. When the 2-bit data is“0”, “0”, CH0 as a positive input side IN + , CH1 as a negative input side IN-for input. When the 2-bit data is“0”, “1”, CH0 as a negative input IN-, CH1 as a positive input IN + input. After the third pulse sinks, the input level of the DI terminal loses its input function, and the Do/DI terminal then uses the data output DO to convert the reading of the data. Starting from the 4th Pulse Sink, the DO end outputs the highest bit of the converted data, DATA7, and then the DO end outputs the next bit for each pulse sink. The one- byte data output is complete until the 11th pulse emits the lowest bit data, DATA0. It is from this bit that the next opposite byte of data is output, that is, from the 11th byte of the sink output DATD0. Then output 8-bit data, to the 19th pulse when the data output is completed, also marks the end of an A/D conversion. Finally, the CS high-level disable chip will be converted directly after the data processing can be. 3.3. ADC0832 data reader process: Figure 11. ADC0832 data reading program flowchart The actual programming code is: /***********AD0832converter****************** / uchar ADC0832(bit mode,bit channel) { uchar i,dat,ndat; ADCS = 0; _nop_(); _nop_(); ADDI = 1; ADCLK = 1; _nop_(); _nop_(); ADCLK = 0; _nop_(); _nop_(); ADDI = mode; ADCLK = 1; _nop_(); _nop_(); ADCLK = 0; _nop_(); _nop_(); ADDI = channel; ADCLK = 1; _nop_(); _nop_(); ADCLK = 0; ADDI = 1; dat = 0; //Now read the converted data and output it in sequence from the highest bits (d 7 to D 0) for(i = 0;i < 8;i++) { dat <<= 1; ADCLK=1; _nop_(); _nop_(); ADCLK=0; _nop_(); _nop_(); dat |= ADDO; } 8 ndat = 0; if(ADDO == 1) ndat |= 0x80; //Now continue reading the reverse data (from D1 to D7) for(i = 0;i < 7;i++) { ndat >>= 1; ADCLK = 1; _nop_(); _nop_(); ADCLK=0; _nop_(); _nop_(); if(ADDO==1) ndat |= 0x80; } ADCS=1; ADCLK=0; ADDI=1; if(dat==ndat) return(dat); else return 0; } 4. Design Applications 4.1. Major sources of PM2.5 The composition of particulate matter is complex and depends largely on its source. There are mainly natural and man-made sources, but the greater harm is the latter. There are two types of aerosol in the academic world: Primary aerosol and Secondary aerosol. Nature:Natural sources include soil dust (which contains oxide mineral and other components) , sea salt (the second largest source of particulate matter, which is similar in composition to seawater) , plant pollen, spores, bacteria, etc. . Natural disasters, such as volcanic eruptions that release large amounts of ash into the atmosphere, forest fires, or naked coal fires, and dust storms can all transport large amounts of fine particles into the atmosphere. Man-made source: Artificial sources include fixed sources and mobile sources. Fixed sources include various fuel combustion sources, such as power generation, metallurgy, petroleum, chemical, textile printing and dyeing and other industrial processes, heating, cooking process coal and gas or fuel emissions. The flow source is mainly the exhaust gas discharged into the atmosphere by various kinds of vehicles when they use fuel in the process of running. PM2.5 can be made from oxides of sulfur and nitrogen. And these gas pollutants are often caused by human combustion of fossil fuels (coal, oil, etc.) and waste. In developing countries, coal burning is the main form of household heating and energy supply. Diesel vehicles without advanced exhaust gas treatment facilities are also a source of particulate matter. Diesel-burning trucks have higher levels of particulate matter due to impurities in their emissions. Indoors, secondhand smoke is the largest source of particulate matter. The source of particulate matter is incomplete combustion, so as long as it is by burning tobacco products, will produce particles with serious hazards, the use of better-quality cigarettes is only a smoker's comfort, it may even cause greater harm because of its lower odor; the same applies to gold paper burning, incense burning and burning mosquito- repellent incense. But after cooking for 5 minutes, PM2.5 increased by 20 times. Atmospheric Chemistry: In addition to natural and man- made sources, gaseous precursor pollutants in the atmosphere can produce secondary particles through atmospheric chemical reactions to achieve the phase transition from gas to particles. Such as: The gaseous sulfuric acid comes from the oxidation of SO2 by OH radical. [2] salt hydrate: such as xcl · YH2O, XNO3 · YH2O, XSO4 · YH2O, with the change of humidity, the effect of hydrate on PM2.5 Is Greater, tiny solution droplets of salt are also formed due to changes in humidity. 4.2. Current status and common data of PM2.5 In our country, there are many types of particulate pollution in urban environment, which can be divided into: traditional soot type, such as Urumqi, Lanzhou, Taiyuan and so on (especially in winter); A mixture of soot, dust and motor vehicles, such as Zhengzhou, Shijiazhuang, etc. , and a combination, such as Beijing, Tianjin, Guangzhou, etc. . With the rapid development of economy, the problem of air pollution occurred in foreign countries for decades appears in many cities of our country, showing complex and compressed form. At present, the air quality of more than 2/3 cities in our country is not up to the standard and has entered the stage of large-scale ecological degradation and compound environmental pollution. Without effective control measures, most cities in China will eventually develop into a complex particulate pollution state. PM2.5 is the most important pollutant to characterize compound air pollution. Today, China has one of the worst PM2.5 pollution regions. Commonly used indicators and data: The fine particulate matter standard, proposed by the United States in 1997, is intended to more effectively monitor the emergence of small particles harmful to human health that have been ignored in the old standard as a result of increasing industrialization. Fine Particulate Matter Index (FSI) has become an important index for monitoring air pollution. By the end of 2010, most countries in the world had not carried out monitoring of fine particulate matter, except for some countries in the United States and the European Union, which have included fine particulate matter in national standards and imposed mandatory restrictions, most commonly used to monitor PM10. New air quality standards for PM2.5 monitoring networks: According to the new air quality standards for the PM2.5 network, the 24-hour mean values are distributed as follows: 9 Table 2. New air quality standards for PM2.5 monitoring network Air quality rating Standard 24-hour PM2.5 mean Yu 0~35 Good 35~75 Light pollution 75~115 Moderate pollution 115~150 Heavy pollution 150~250 Serious pollution Greater than 250 And above World Health Organization (WHO-RRB-2005 air quality guidelines Project Annual average Daily average Criteria 10 25 Transition Goal 1 35 75 Transition Goal 2 25 50 Transition Goal 3 15 37.5 4.3. Primary use This design can be used for indoor and outdoor air quality (mainly PM2.5) detection, can be used for long-term detection of PM2.5 concentration. References [1] Liu Hongbin. The present situation of PM2.5 in our country and the countermeasures. Wuhan: Journal of Hubei University of Economics. 2012. [2] Wang Xingzhi loved the Qin. The principle and interface technology of AT89 series microcontroller. Beijing: Beijing University of Aeronautics and Astronautics Press. 2004. [3] Zheng Feng, Wang Qiaozhi. 51 single-chip microcomputer application system typical module development complete. Beijing: China Railway Press. 2011. [4] STC. 8-bit Microcontroller with 8K Bytes In-System Programmable Flash STC89C51.1999 [5] Principle and application technology of single-chip microcomputer. Beijing: Higher Education Press. 2009. [6] Luo Yaping. Indoor harmful gas monitoring system based on STC89C51. Shanxi electronic technology. 2011. [7] Fan Honggang, Wei Xuehai. 51 single-chip microcomputer self-study notes. Beijing: Beijing University of Aeronautics and Astronautics Press. 2010. [8] General Yang, General Li. Microcontroller program design and application from the foundation to practice. Beijing. China Machine Press. 2006. [9] Li Weiti, Guo Qiang. Liquid crystal display application technology. Beijing: Publishing House of Electronics Industry. 2006[11] Sharpe dust sensor GP2Y1010AU0F instructions for use ADC0832 ADC product specification