Indoor environment monitoring device based on STM32

. Based on people's demand for indoor air quality monitoring, an indoor ambient intelligence detection system with STM32F103C8T6 microcontroller as the core controller is designed, which can monitor the current indoor temperature, humidity, suspended particles (PM10) and toxic and harmful gases in the air in real time, accurately and effectively. And the current indoor environment is transmitted to the computer for display through Bluetooth, so as to warn people in time and avoid harm to human health. The system has the characteristics of small size, convenience, reliability and simple operation, and can be widely used in the field of indoor environment detection.


Introduction
Over the years, due to the acceleration of industrialization, people have excessively cut down trees, exploited coal mines and other resources, and discharged waste water and gas at will, thus establishing the rapid economic development on the basis of destroying the natural environment and lacking the protection of the natural environment. Therefore, with the economic development, the natural environment has been seriously polluted and destroyed, and environmental problems have become increasingly prominent. For example, in recent years, major industrial cities such as Beijing, Shanghai, Tianjin and Nanjing have experienced sandstorms, smog and fog, which seriously threaten people's physical and mental health. A large number of studies have shown that if people live indoors with polluted air for a long time and inhale polluted air containing various harmful substances,It will cause many diseases such as sore throat, respiratory tract infection, skin allergy, asthma and cough. In China, it is not uncommon for people to suffer from diseases or deaths caused by living in polluted indoor air every year. For example, people's respiratory tract is stimulated and infected due to the high content of suspended particles (PM10) in the air. Thereby causing people to suffer from various respiratory diseases; When people use coal, natural gas, liquefied petroleum gas, etc. for cooking or heating, gas poisoning is caused by insufficient ventilation or improper operation. In addition, there are not a few cases of humidity and nasal mucosa injury caused by too humid or dry air. To sum up the above. It is necessary to design an environmental monitoring system that can monitor the temperature and humidity, suspended particles, formaldehyde, benzene series, coal gas and liquefied natural gas in the air in real time. When the pollutants in the air exceed the standard, it can warn people and create a healthy, safe and comfortable living environment for people. In this system, a 32-bit microcontroller STM32F103C876 based on ARM Cortex-M3 core is used as the core periphery, which is matched with the suspended particle sensor GP2Y1010AU0F of sharp company, the high-performance digital temperature and humidity composite sensor DTH11, and the formaldehyde sensor MQ138, smoke sensor MQ135 and combustible gas sensor MQ2 of weisheng electronics company. Through Bluetooth wireless communication technology, the system can send the current indoor environment data to the upper computer software on the computer for real-time monitoring. When there is an abnormal situation, it can record the abnormality and give an alarm. This system has the characteristics of small size, convenience, reliability and simple operation, and can be widely used in the field of indoor environment detection.

System overall framework design,
This system can be divided into upper computer and lower computer. The overall framework of the system is shown in Figure 1. The upper computer is mainly responsible for displaying and monitoring environmental information, while the lower computer is responsible for collecting current environmental data and transmitting it to the upper computer. The overall workflow of the system is that the lower computer collects the surrounding environment information through sensors. Then package the data and transmit the data packet to the upper computer through Bluetooth wireless communication technology. After unpacking and verifying the data packet, the upper computer displays the environmental information on the computer, and gives an alarm and records if there is any abnormal situation.

Overall hardware design
The hardware of the lower computer can be divided into three parts: control part, environment acquisition part and wireless data transmission. The overall framework of the lower computer hardware is shown in Figure 2. The environmental collection part can be divided into temperature and humidity collection part, suspended particles collection part, formaldehyde and benzene series collection part, combustible gas collection part and smoke and harmful gas collection part. The environment collection part mainly collects the surrounding environment and obtains the data information of the surrounding environment. In the control part, the STM32F103C8T6 microcontroller is used as the core of the control part, which is responsible for processing various tasks of the system, such as sensor data reading and data packet processing. The wireless data transmission part is mainly responsible for transmitting the environmental data collected by the system to the computer. The computer receives the data and displays it on the interface through the upper computer software.

STM32F103C8T6
Core Edition s8-bit microcontroller with high performance. Among them, resistive humidity sensor is used for collecting environmental humidity, NTC thermistor is used for collecting environmental temperature, and indoor ambient intelligence monitoring system adopts MQ135, MQ 2 and MQ 138 semiconductor gas sensors produced by Weisheng Technology Company, among which MQ 135 is sensitive to ammonia, sulfide, benzene and smoke.MQ2 is sensitive to combustible gases such as liquefied gas, propane and hydrogen. MQ138 is sensitive to formaldehyde, ethanol and acetone. Specific semiconductor gas sensors detect specific gases within a certain concentration range. The MQ series semiconductor gas sensor has simple driving circuit, long service life and low cost, It is widely used in air quality monitoring, air pollution alarm, air filter and other occasions. The MQ135,MQ2,MQ138 semiconductor gas sensors are sensors using tin dioxide as gas sensitive materials. when tin dioxide is in clean air, its conductivity is relatively low, while when tin dioxide is in polluted air, Its conductivity is proportional to the concentration of pollutants. If a resistor is connected in series in the circuit, the change of conductivity can be converted into the change of analog voltage, and then the gas concentration of air pollutants can be calculated by sampling and conversion with ADC of microcontroller. Bluetooth is a 2.4GHz wireless communication technology with low power consumption, low cost and short distance. ISM (industrial, scientific and medical) band of 4GHz, so it can be used without applying for permission from the radio department. Bluetooth can be used not only for transmitting voice and data, but also for networking communication. With strong anti-interference ability, low power consumption and small size, Bluetooth technology is widely used in various fields. In this system, The communication between the lower computer and the upper computer uses Bluetooth wireless technology: the lower computer sends the data packet to the Bluetooth wireless communication module through the serial port, and then the Bluetooth wireless communication module sends the data packet to the Bluetooth receiving module of the upper computer through Bluetooth technology, unpacks it, extracts the environmental data and displays it on the interface. The model of Bluetooth module used in this system is HC-05, which supports the masterslave integrated mode, the power supply voltage is 3.3V, and the data communication interface is USART serial port 1. when the Bluetooth module receives data from the serial port, it will automatically transmit the data wirelessly to another paired Bluetooth module through Bluetooth , and after the other Bluetooth module receives the data. And send the data to the application equipment through the serial port, so as to realize the transparent transmission of the data.

Overall design of software
The upper computer is the monitoring software running on the computer, which is responsible for displaying and monitoring the environmental information transmitted by the lower computer, and can alarm and record the event in time when a certain data exceeds the standard. The upper computer adopts the idea of modular design and divides the software into three parts: data transmission, data processing and human-computer interaction.The data transmission module is mainly responsible for receiving data packets from the lower computer from the system port, while the data processing part is responsible for processing and verifying the data packets, and the human-computer interaction part is responsible for presenting the environmental data on the software interface, monitoring the data, and recording the abnormal event if there is any data abnormality. The overall software flow chart of the upper computer is shown in Figure 3. In this system, when opening the upper computer software, first initialize the Serial Port class, call the PortName method to obtain all the available serial ports on the current computer, and map the currently available serial ports to the drop-down menu of the software interface. When the user clicks to connect to the indoor environment detection system, the baud rate of the serial port is set to 115200b, no parity bit and a stop bit. Then open the selected port and listen. When there is data coming, the data receiving event is triggered, and after receiving the data, the data is transmitted to the data processing function for processing. After receiving the data packet sent by the lower computer. Because all the data stored in the Serial port cache are obtained by Reading the serial port through the read class of Serial Port, these data may contain multiple data packets transmitted by the lower computer. In order to accurately find a complete data packet. It is necessary to process the read data to some extent.

System test
The indoor environment is monitored by the upper computer software, and pollution sources such as methane, liquefied petroleum gas and smoke are placed near the indoor ambient intelligence monitoring system. According to different test conditions, the system will have different reactions. The experimental results show that the indoor ambient intelligence monitoring system can detect pollutants very quickly. At the same time, record the content of pollutants exceeding the standard on the software interface and warn people.

Conclusion
In this paper, an intelligent system is designed and developed, which can monitor harmful substances such as temperature, humidity, PM10, formaldehyde and liquefied petroleum gas in indoor environment in real time. If the measured items exceed the standard, it will record and alarm in time. As this system adopts a 32-bit microcontroller STM32F103C8T6 with high cost performance, powerful functions and low power consumption, and at the same time, it is equipped with a variety of sensors on the periphery. Using wireless data transmission technology combined with upper computer, the indoor environment can be monitored accurately and effectively, and the humanized man-machine interface can make people know the current indoor environment information conveniently and quickly. It provides powerful reference information for protecting people's physical and mental health and improving people's living environment. It has certain reference value for studying the source of indoor pollutants.