# Design and Implementation of Wireless Environment Monitoring System Based on STM32

Authors: Qu Xilong; Liu Shengzong; Fu Sha; He Hong; Hu Ying; Xiao Leyi
Journal: Scientific Programming
 (2021)

---

## Abstract

This paper first designed the overall scheme of a wireless-based intelligent environment monitoring system; this system is comprised of the following four parts: server part, client part, slave computer part, and master computer part. The master computer is equipped with a wireless transmission module and an LCD module. Slave computers are equipped with temperature-humidity sensing modules and wireless transmission modules. The server side has two major interfaces: data display and server establishment. An Android phone as the client can realize the communication between the mobile APP and server through network communication to obtain environmental data in real time. The hardware part of the system consists of wireless transmission module, temperature and humidity module, smoke module, lighting module, flame module, and LCD module. The software implementation part mainly includes the design and implementation of serial communication, the design and implementation of wireless communication, the design and implementation of collection of data acquisition in each sensor module, and the design and implementation of network communication as well as the design and implementation of display unit. With the cooperation of these four parts, we can automatically sense and control the state of the environment to realize human-computer interaction.


---

## Body

## 1. Introduction

With the science advancement and technology popularization, intelligent devices enjoy more and more widespread application, and problems such as the accuracy of environmental issues have been aroused therefrom [1, 2]. The previous environmental monitoring was carried out by means of manual monitoring, which has many shortcomings from the present point of view, including low efficiency and unscientific management system [3–6]. It was not conducive to the full utilization of resources and scientific management. Moreover, it was not difficult to find from the major accidents in these years that many were caused by human factors [7–10].For example, greenhouses, industrial factories, and other places have higher requirements for their surrounding environment [11, 12]. Although many greenhouses and factories are also equipped with corresponding heating, humidifying, and ventilation equipment, these types of equipment are basically manually operated [13, 14]. Under the circumstances, once there is a large workload of equipment inspection and maintenance, it will cause problems such as high labor intensity. In addition, this method is not able to achieve accurate and real-time control of the environment, having become incapable of meeting the needs of the rapid development of today’s society [15–17]. Therefore, the development of a wireless environmental monitoring system that integrates environmental data collection, transmission, and display will greatly reduce the labor intensity of operators and improve the accuracy of environmental monitoring [18, 19].Now, traditional environmental monitoring technology has been widely used in the production of various industries in China, having developed into a relatively complete system [20]. Intelligent environmental monitoring technology, which can achieve centralized monitoring of multiple environmental factors, is also applied in some developed countries [21, 22]. But its high cost makes it difficult to popularize. In recent years, many research institutes in China have studied intelligent environmental monitoring technology, and the country has also given great support [23–25]. Judging from the current domestic and foreign environments, the wired environment monitoring technology has been relatively mature, but its application range is very limited and has obvious limitations [26–28]. Therefore, it is necessary to design a system that can wirelessly send these data to the host for processing [29, 30].This system is to design a wireless environment monitoring device based on environmental data collection, transmission, and display. Environmental monitoring based on wireless technology has sufficient development space and application prospects, and it can be widely used in the production and development of industry and agriculture. Therefore, the development of such an intelligent environmental monitoring system will be able to be widely used to meet the needs of market development.The remainder of this paper is organized as follows: Section2 introduces the related work. Section 3 introduces the overall design of this system. Then, the design and implementation of system hardware circuit are elaborated in Section 4. Section 5 gives the design and implementation of system software. And system function debugging is executed in Section 6. Finally, a conclusion is given in Section 7.


## 2. Related Work

Curran and Norrby used RFID to locate the items or people in the indoor environment [31]. But RFID is high cost and security is not strong enough, which limits its wide application. Yang et al. extended the process-oriented structured system analysis on the existing intelligent transportation architecture to establish an intelligent transportation system based on the new generation wireless communication technology, and further in-depth analysis will be performed to discuss the required additional capabilities of network, services, and application support in the view of user, function, information, connection, and communication [32]. Dey et al. considered a home-based wireless ECG monitoring system using ZigBee technology [33]. But such systems are often designed in isolation, with no consideration of existing home control networks and smart home solutions. Liu used multisensor data fusion technology, ARM technology, ZigBee technology, GPRS, and other technologies and studied and developed an intelligent environmental monitoring system [34]. But the cost of the GPRS communication module is high. A lot of research on wireless sensor networks optimized IIR broadband digital differentiators and integrators by using SALP group algorithm, automatically detected network interference and intrusion, and offloaded vehicular task by using the game-theoretic method [35–37]. The current wireless communication technology is more and more widely used. Therefore, using wireless technology to design a low-cost, stable, and reliable environmental detection system is of great significance.


## 3. Overall Design

After analyzing the system requirements, an integrated communication method is adopted, including slave computer, master computer, server, and client. STM32 is used as the master controller, QT is used to design the human-machine interactive interface, and TCP network communication is adopted to realize the communication with the client, so that the master computer, server, and client have the function of observing the environment. The system framework is as shown in Figure1.Figure 1
Overall framework of the system.The slave computer of this system realizes data acquisition and transmits the data to the master computer through the wireless module. The master computer transmits the data to the server through the serial port, and the client obtains the server data through network communication. Various modules work in coordination to achieve real-time monitoring of the environment. This system mainly completes the design of the following four parts:(1)
Slave computer partTemperature-humidity sensor module, photosensitive sensor module, smoke sensor module, and flame sensor module are used to collect data on surrounding environmental parameters.(2)
Master computer partNRF24L01 wireless transmission module, digital tube module, and LCD screen module are adopted, which are connected to the slave computer through wireless technology to acquire data through wireless technology, so as to display these acquired data on the digital tube and LCD screen.(3)
ServerA computer is used as the server to realize communication with master computer through serial port. A QT interface is established to display environmental data and realize network communication with the client.(4)
ClientAn Android phone is used as the client terminal to establish a client terminal display interface and implement network communication with the server.This system will be applied in the wireless monitoring of the environment. It adopts the communication method integrating slave computer, master computer, server, and client so that users can monitor online through the client and PC to ensure the safe and high-quality production of the environment such as greenhouses and factories. This system is built on the basis of wireless, serial, and network communication, and various modules are interconnected through different communication methods to achieve human-computer interaction. Based on these functions, this system adds functional modules to the slave computer, such as temperature-humidity sensor, photosensitive sensor, smoke sensor, and flame sensor as well as NRF24L01 module to achieve real-time monitoring of the environment.The research process of this system is divided into the following steps:(1)
Hardware environment of the overall design(2)
Building an overall software platform(3)
Collection of environmental data by sensors(4)
Wireless transmission and display of data(5)
Data transmission realized by serial communication(6)
Data transmission between client and server realized by network programming(7)
Design and implementation of QT graphical interface(8)
Test for system operation stability


### 3.1. Overall Design Scheme for the System

After the analysis of the research topic, an integrated communication method of slave computer, master computer, server, and client is adopted. STM32 is used as the master controller, QT is employed to design the human-computer interaction interface, and the communication between the server and the client is realized by relying on TCP network communication, so that the master computer, the server, and the client have the function of real-time monitoring of the environment. The system is mainly designed to realize the following functions:Data acquisition: Temperature-humidity sensor module, photosensitive sensor module, smoke sensor module, and flame sensor module are used to collect data from the surrounding environment.Wireless transmission: Use NRF24L01 module to send and receive data, so as to realize communication between slave computer and master computer.Fire protection function: Monitor the fire condition in the environment through flame and smoke sensors.Alarm unit: The acoustooptic alarm device is adopted. By setting the threshold of environmental data, the alarm signal will be sent off once the relevant data exceed the threshold value.Human-machine interaction interface: The server obtains and displays the environmental data from the master computer through the serial port, while the client obtains and displays the data from the server through the network communication.


### 3.2. Features of the System

This system uses a wireless transmission platform plus various sensor modules and integrates with serial communication and TCP network communication to form an intelligent wireless environment monitoring system [38–40]. It is used to substitute the original manual field monitoring work and ensures that users can obtain environmental data in real time through network transmission. Therefore, the staff can monitor and manage the environment in real time through the client APP, so that one person can monitor multiple environmental conditions at the same time, thereby greatly improving work efficiency.This system is divided into four parts in terms of structure, namely, the slave computer part, the master computer part, the server part, and the client part.(1)
Slave computer part: Adopting photosensitive sensor, smoke sensor, flame sensor, and temperature-humidity sensor to realize the collection of environmental data and realize the wireless transmission of data through the NRF24L01 wireless module.(2)
Master computer part: NRF24L01 wireless module is used to realize data communication with slave computer, display data through digital tube and LCD screen, and send data to server through serial port.(3)
Server part: A computer is adopted as the server to realize communication with master computer through serial port, and QT interface is established to display environment data and realize network communication with client.(4)
Client part: An Android phone is adopted as the client terminal to achieve network communication with the server and obtain and display environmental data in real time.This system uses a wireless transmission platform plus various sensor modules and integrates with serial communication and TCP network communication to form an intelligent wireless environment monitoring system, which has the following advantages compared with the traditional manual field monitoring mode:(1)
This system ensures continuous work for a long time and can work in various environments and even under special extreme conditions (including closed environment).(2)
The environment information can be controlled in real time, and comprehensive monitoring can be planned according to different parameter requirements so as to ensure that there is no omission or repetition in monitoring.(3)
This system can realize wireless transmission, and the client and server can communicate with each other through the network. The master computer can wirelessly receive the data of the slave computer. As a result, working staff can remotely monitor one or more similar environments for convenient and efficient management.This system uses multiple NRF24L01 wireless modules, which are installed on all master and slave computers, so as to realize the wireless communication between master and slave computers. This system adopts the network communication based on TCP protocol, which is characterized by being able to realize remote data acquisition in the local area network. Finally, this system employs STM32F103ZET6 as the core processing chip. The chip is characterized by high stability, high performance, and large memory, and thereby it is suitable for processing complex data.Based on the system application requirements and characteristics, it is required to first make a general plan for the system, including the design of the system architecture, wireless transmission, serial communication, and selection and design of network communication. The system takes STM32-based wireless environment monitoring system as the research object, establishes and selects suitable object models, and finally designs a physical model of STM32-based wireless environment monitoring system through the design of software and hardware.


### 3.3. Key Technical Issues and Main Technical Indicators

#### 3.3.1. Wireless Transmission Part

The wireless transmission part uses the NRF24L01 sensor and sends the data collected by the slave computer to the master computer for processing through the SPI protocol, thereby realizing the data communication between the master computer and the slave computer and then realizing real-time display of the environmental data and intelligent alarm function through the analysis of the received data. The SPI protocol works in a master-slave mode. This system uses one master one slave mode. The master device determines the slave device through the enable signal so that the master-slave devices can be connected and the data transmission can be synchronized by the clock signal.


#### 3.3.2. Sensor Technology

(1)
Photosensitive sensor module: This system uses the built-in photosensor of the demo board STM32 to determine the light value in combination with its internal analog-to-digital conversion.(2)
Temperature-humidity sensor module: This system uses a DHT11 digital temperature-humidity sensor to collect data of temperature and humidity to obtain the required data through Time Division Multiplexing (TDM) performed according to the transmission protocol.(3)
Flame sensor module: This system uses the flame sensor module YL-38 to detect the fire source. This module can detect whether there is an open flame around the system and then output high electrical level and low electrical level. The slave computer can determine if the warehouse is at risk of fire by detecting the high electrical and low electrical level.(4)
Smoke sensor module: This system uses the smoke sensor module MQ-2 to monitor the smoke concentration. It can detect whether the smoke concentration in the environment exceeds the standard. The module is equipped with an adjustable potentiometer, which can adjust the output sensitivity of TTL, so as to more precisely determine whether there are hidden dangers in the environment by combining with other module values in the environment.(5)
Wireless transmission module: This system uses the NRF24L01 wireless transmission module and realizes wireless communication based on SPI protocol. Users can easily realize wireless communication functions.


#### 3.3.3. Network Communication Technology

Network communication technology is a very important component of this system. This system uses the network integrated by the QT development platform to build servers and clients by applying the TCP protocol so as to ensure that multiple clients can obtain the current environmental data. The TCP protocol can provide not only connection-oriented reliable services but also full-duplex reliable channels. TCP protocol requires such a connection process that the connection between the client and the server shall be established first before transmitting data, and the client will actively release after the data transmission is completed. Through the network programming interface provided by the socket, a special file descriptor (socket descriptor) is obtained by using the socket, and the subsequent steps of network programming based on the TCP protocol will be implemented through the socket descriptor.


## 3.1. Overall Design Scheme for the System

After the analysis of the research topic, an integrated communication method of slave computer, master computer, server, and client is adopted. STM32 is used as the master controller, QT is employed to design the human-computer interaction interface, and the communication between the server and the client is realized by relying on TCP network communication, so that the master computer, the server, and the client have the function of real-time monitoring of the environment. The system is mainly designed to realize the following functions:Data acquisition: Temperature-humidity sensor module, photosensitive sensor module, smoke sensor module, and flame sensor module are used to collect data from the surrounding environment.Wireless transmission: Use NRF24L01 module to send and receive data, so as to realize communication between slave computer and master computer.Fire protection function: Monitor the fire condition in the environment through flame and smoke sensors.Alarm unit: The acoustooptic alarm device is adopted. By setting the threshold of environmental data, the alarm signal will be sent off once the relevant data exceed the threshold value.Human-machine interaction interface: The server obtains and displays the environmental data from the master computer through the serial port, while the client obtains and displays the data from the server through the network communication.


## 3.2. Features of the System

This system uses a wireless transmission platform plus various sensor modules and integrates with serial communication and TCP network communication to form an intelligent wireless environment monitoring system [38–40]. It is used to substitute the original manual field monitoring work and ensures that users can obtain environmental data in real time through network transmission. Therefore, the staff can monitor and manage the environment in real time through the client APP, so that one person can monitor multiple environmental conditions at the same time, thereby greatly improving work efficiency.This system is divided into four parts in terms of structure, namely, the slave computer part, the master computer part, the server part, and the client part.(1)
Slave computer part: Adopting photosensitive sensor, smoke sensor, flame sensor, and temperature-humidity sensor to realize the collection of environmental data and realize the wireless transmission of data through the NRF24L01 wireless module.(2)
Master computer part: NRF24L01 wireless module is used to realize data communication with slave computer, display data through digital tube and LCD screen, and send data to server through serial port.(3)
Server part: A computer is adopted as the server to realize communication with master computer through serial port, and QT interface is established to display environment data and realize network communication with client.(4)
Client part: An Android phone is adopted as the client terminal to achieve network communication with the server and obtain and display environmental data in real time.This system uses a wireless transmission platform plus various sensor modules and integrates with serial communication and TCP network communication to form an intelligent wireless environment monitoring system, which has the following advantages compared with the traditional manual field monitoring mode:(1)
This system ensures continuous work for a long time and can work in various environments and even under special extreme conditions (including closed environment).(2)
The environment information can be controlled in real time, and comprehensive monitoring can be planned according to different parameter requirements so as to ensure that there is no omission or repetition in monitoring.(3)
This system can realize wireless transmission, and the client and server can communicate with each other through the network. The master computer can wirelessly receive the data of the slave computer. As a result, working staff can remotely monitor one or more similar environments for convenient and efficient management.This system uses multiple NRF24L01 wireless modules, which are installed on all master and slave computers, so as to realize the wireless communication between master and slave computers. This system adopts the network communication based on TCP protocol, which is characterized by being able to realize remote data acquisition in the local area network. Finally, this system employs STM32F103ZET6 as the core processing chip. The chip is characterized by high stability, high performance, and large memory, and thereby it is suitable for processing complex data.Based on the system application requirements and characteristics, it is required to first make a general plan for the system, including the design of the system architecture, wireless transmission, serial communication, and selection and design of network communication. The system takes STM32-based wireless environment monitoring system as the research object, establishes and selects suitable object models, and finally designs a physical model of STM32-based wireless environment monitoring system through the design of software and hardware.


## 3.3. Key Technical Issues and Main Technical Indicators

### 3.3.1. Wireless Transmission Part

The wireless transmission part uses the NRF24L01 sensor and sends the data collected by the slave computer to the master computer for processing through the SPI protocol, thereby realizing the data communication between the master computer and the slave computer and then realizing real-time display of the environmental data and intelligent alarm function through the analysis of the received data. The SPI protocol works in a master-slave mode. This system uses one master one slave mode. The master device determines the slave device through the enable signal so that the master-slave devices can be connected and the data transmission can be synchronized by the clock signal.


### 3.3.2. Sensor Technology

(1)
Photosensitive sensor module: This system uses the built-in photosensor of the demo board STM32 to determine the light value in combination with its internal analog-to-digital conversion.(2)
Temperature-humidity sensor module: This system uses a DHT11 digital temperature-humidity sensor to collect data of temperature and humidity to obtain the required data through Time Division Multiplexing (TDM) performed according to the transmission protocol.(3)
Flame sensor module: This system uses the flame sensor module YL-38 to detect the fire source. This module can detect whether there is an open flame around the system and then output high electrical level and low electrical level. The slave computer can determine if the warehouse is at risk of fire by detecting the high electrical and low electrical level.(4)
Smoke sensor module: This system uses the smoke sensor module MQ-2 to monitor the smoke concentration. It can detect whether the smoke concentration in the environment exceeds the standard. The module is equipped with an adjustable potentiometer, which can adjust the output sensitivity of TTL, so as to more precisely determine whether there are hidden dangers in the environment by combining with other module values in the environment.(5)
Wireless transmission module: This system uses the NRF24L01 wireless transmission module and realizes wireless communication based on SPI protocol. Users can easily realize wireless communication functions.


### 3.3.3. Network Communication Technology

Network communication technology is a very important component of this system. This system uses the network integrated by the QT development platform to build servers and clients by applying the TCP protocol so as to ensure that multiple clients can obtain the current environmental data. The TCP protocol can provide not only connection-oriented reliable services but also full-duplex reliable channels. TCP protocol requires such a connection process that the connection between the client and the server shall be established first before transmitting data, and the client will actively release after the data transmission is completed. Through the network programming interface provided by the socket, a special file descriptor (socket descriptor) is obtained by using the socket, and the subsequent steps of network programming based on the TCP protocol will be implemented through the socket descriptor.


## 3.3.1. Wireless Transmission Part

The wireless transmission part uses the NRF24L01 sensor and sends the data collected by the slave computer to the master computer for processing through the SPI protocol, thereby realizing the data communication between the master computer and the slave computer and then realizing real-time display of the environmental data and intelligent alarm function through the analysis of the received data. The SPI protocol works in a master-slave mode. This system uses one master one slave mode. The master device determines the slave device through the enable signal so that the master-slave devices can be connected and the data transmission can be synchronized by the clock signal.


## 3.3.2. Sensor Technology

(1)
Photosensitive sensor module: This system uses the built-in photosensor of the demo board STM32 to determine the light value in combination with its internal analog-to-digital conversion.(2)
Temperature-humidity sensor module: This system uses a DHT11 digital temperature-humidity sensor to collect data of temperature and humidity to obtain the required data through Time Division Multiplexing (TDM) performed according to the transmission protocol.(3)
Flame sensor module: This system uses the flame sensor module YL-38 to detect the fire source. This module can detect whether there is an open flame around the system and then output high electrical level and low electrical level. The slave computer can determine if the warehouse is at risk of fire by detecting the high electrical and low electrical level.(4)
Smoke sensor module: This system uses the smoke sensor module MQ-2 to monitor the smoke concentration. It can detect whether the smoke concentration in the environment exceeds the standard. The module is equipped with an adjustable potentiometer, which can adjust the output sensitivity of TTL, so as to more precisely determine whether there are hidden dangers in the environment by combining with other module values in the environment.(5)
Wireless transmission module: This system uses the NRF24L01 wireless transmission module and realizes wireless communication based on SPI protocol. Users can easily realize wireless communication functions.


## 3.3.3. Network Communication Technology

Network communication technology is a very important component of this system. This system uses the network integrated by the QT development platform to build servers and clients by applying the TCP protocol so as to ensure that multiple clients can obtain the current environmental data. The TCP protocol can provide not only connection-oriented reliable services but also full-duplex reliable channels. TCP protocol requires such a connection process that the connection between the client and the server shall be established first before transmitting data, and the client will actively release after the data transmission is completed. Through the network programming interface provided by the socket, a special file descriptor (socket descriptor) is obtained by using the socket, and the subsequent steps of network programming based on the TCP protocol will be implemented through the socket descriptor.


## 4. Design and Implementation of System Hardware Circuit

This system is divided into server part, client part, slave computer part, and master computer part. The server and client terminals realize data transmission through TCP-based network communication; the master computer is composed of LCD display and acoustooptic alarm device; the slave computer part consists of temperature-humidity sensor, smoke sensor, photosensitive sensor, flame sensor, and NRF24L01 wireless module. The master computer communicates with the slave computer through the NRF24L01 wireless module, and the master computer communicates with the server through the serial port. The system integrates acquisition, display, and transmission and has a high degree of intelligence, which reduces the labor intensity of operators and improves the accuracy of environmental monitoring.


### 4.1. Slave Computer Part

#### 4.1.1. Slave Computer MCU-STM32F103

(1) Introduction. STM32F1 series enhanced chips with Cortex-M3 as the kernel is used by this system as the controller MCU of slave computer. Cortex-M3 is a 32-bit RISC processor with a built-in high-speed memory and a working frequency of 72 MHz. It has a rich I/O port and peripherals. It is capable of operating in the temperature range of −40°C to +105°C, and it has an unprecedented advantage in the 32-bit microcontroller market.(2) Function. The chip is mainly responsible for the normal coordination of various sensor modules of the slave computer. The data collected by the sensor is simply processed, analyzed, and then sent to the master computer through the NRF24L01 wireless transmission module and assists the master computer to control the entire system operation. The lower part of this system uses the minimum boar of STM32F103ZET6.


#### 4.1.2. Smoke Sensor Module

(1) Introduction. This system uses an MQ-2 smoke sensor to detect the smoke concentration in the environment. This sensor has a high sensitivity to gas and so on, with a long service life and reliable stability. The principle is that when flammable gas is present in the environment, the electrical conductivity of the sensor increases with the increase of the concentration of the flammable gas in the air, thereby determining the concentration of the flammable gas in the current environment. Use a simple circuit to output high electrical level and low electrical level, and set a threshold for exceeding the standard. When the output is of a high level, it means that the concentration exceeds the standard.(2) Function. MQ-2 in this system is responsible for detecting whether the smoke concentration in the environment exceeds the standard.(3) Working Principle. The signals output by most sensor modules are relatively weak, and there is no exception for smoke sensors. Therefore, the output signals need to be processed through a set circuit to meet the processor’s requirements for input signal detection. This system uses a noninverting proportional amplifier circuit to reduce expansion on hardware and achieve the highest cost performance.


#### 4.1.3. Flame Sensor Module

(1) Introduction. This system uses a flame sensor module YL-38 to detect the fire source in the environment. When a fire source exists in the environment where the sensor is located, the sensor module will send a high-level signal to the main control chip. It can monitor the infrared light with the wavelength range of 700 nm–1000 nm and detection angle of 60 degrees, and the value is inversely proportional to the intensity of external infrared light.(2) Function. In this system, the flame sensor is responsible for detecting the flame in warehouse.(3) Working Principle. The flame sensor module is equipped with a far-infrared flame probe, which can convert the change in the intensity of external infrared light into the change in current. The high level and low level of the digital interface DO can reflect whether the ambient flame spectrum exceeds the set threshold so that the processor can judge whether there is fire condition in the current environment only by checking the high level and low level of the digital interface DO. If it exceeds the set threshold, it will output high level, and the switch indicator will be lighted. Its schematic diagram is as shown in Figure 2.Figure 2
Schematic diagram of the flame sensor.


#### 4.1.4. Temperature-Humidity Sensor Module

(1) Introduction. This system is equipped with a temperature-humidity sensor module DHT11 on the slave computer to collect temperature and humidity information in the environment. It is a temperature-humidity composite sensor with a calibrated digital signal output. It is designed with a single bus data format, which can complete data communication every four milliseconds. This string of data is divided into a decimal part and an integer part. The specific data format is as follows: the first eight digits represent the integer part of the humidity, and the next eight digits represent the decimal part of humidity. The further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. This system is only accurate to the integer part of temperature and humidity. The physical object is as shown in Figure 3.Figure 3
Physical picture of temperature-humidity sensor.(2) Function. The temperature-humidity sensor module is responsible for collecting ambient temperature and humidity in this system.(3) Working Principle. The module includes a resistive humidity sensing element and an NTC temperature measuring element and is connected to a high-performance 8-bit microcontroller. The sensing layer of the resistance humidity sensor will be interfered with by chemical vapor, and the diffusion of chemical substances in the sensing layer may cause the measurement value to drift and decrease the sensitivity. The hardware connection diagram is shown in Figure 4.Figure 4
Hardware schematic diagram of temperature-humidity sensor.


#### 4.1.5. Photosensitive Sensor Module

(1) Brief Introduction. This system uses the photosensitive sensor that comes with the demo board STM32 to obtain the light illumination value by combining with its internal ADC.(2) Function. The photosensitive sensor module in this system is responsible for the function of collecting ambient light illumination.(3) Working Principle. This module is mounted on the master computer, reads the voltage value of the photosensitive sensor (LS1) through channel 6 (PF8) of ADC3, and converts it into a light intensity value of 0–100. The brighter the light on the module is, the larger the value could be; the darker the light on the module is, the smaller the value could be. Therefore, the change in light intensity can be viewed by blocking LS1 and illuminating LS1 with light during the experiment. The hardware connection diagram is as shown in Figure 5.Figure 5
Hardware schematic diagram of photoelectric sensor.(1) Brief Introduction. This system uses multiple wireless modules, which are, respectively, mounted on the master computer and the slave computer to realize the wireless communication between the master computer and the slave computer. The wireless module NRF24L01 works in the 2.4 GHz–2.5 GHz ISM frequency band, uses FSK modulation, and integrates the Enhanced Short Burst protocol. Hardware Schematic Diagram of NRF24L01 Wireless Module is as shown in Figure 6. This module can not only realize point-to-point communication but also implement single-point-to-multipoint (up to one-to-six) communication. Its communication speed can reach 2 Mbps. This module is simple and easy to learn. Users can easily implement the function of wireless communication only by reserving 5 GPIOs and 1 interrupt input pin for the microcontroller system. Most demo boards have assigned pins to this module, and some of them are designed with related drivers, so it boasts of very good cost performance.Figure 6
Hardware schematic diagram of NRF24L01 wireless module.(2) Function. The wireless module in this system realizes the wireless communication between the master computer and the slave computer and is responsible for the data transmission between the two.(3) Working Principle. The master computer and the slave computer are, respectively, equipped with wireless modules and configured with different modes. In this system, the slave computer is configured with data transmission mode, while the master computer is configured with data reception mode. This module uses the SPI protocol for communication, which just requires connection and data read/write in accordance with the standard SPI protocol.


### 4.2. Master Computer Part

#### 4.2.1. Master Computer MCU-STM32F103

The MCU is mainly responsible for receiving the data collected by the sensor modules transmitted by the slave computer, configuring the acoustooptic alarm device, combining with the data to implement the alarm function, and sending the data to the server through the serial port. This section uses the STM32F103ZET6 battleship board.


#### 4.2.2. NRF24L01 Wireless Module

The master computer part of this system uses the same model of the NRF34L01 wireless module as the slave computer, of which the wireless module is used to send data, and the master computer is used to receive data.


#### 4.2.3. LCD Module

(1) Introduction. This system uses the built-in TFTLCD liquid crystal module of the demo board. TFT is a thin film transistor. Each pixel of the liquid crystal display is equipped with one TFT. The LCD module is designed with the size of 2.8 inches, the resolution of 320 ∗ 240, and a 16-bit true color display (RGB565: 5 red, 6 green, and 5 blue). Different colors can be displayed through RGB descriptions, and its interface is designed with a 16-bit 80-parallel port. This LCD screen can greatly improve the image quality.(2) Function. This module displays the data of the slave computer in this system. The hardware connection diagram is as shown in Figure 7.Figure 7
Hardware schematic diagram of LCD.


### 4.3. Server Part and Client Part

This system uses a laptop as the server, and this system uses an Android phone as the client.


## 4.1. Slave Computer Part

### 4.1.1. Slave Computer MCU-STM32F103

(1) Introduction. STM32F1 series enhanced chips with Cortex-M3 as the kernel is used by this system as the controller MCU of slave computer. Cortex-M3 is a 32-bit RISC processor with a built-in high-speed memory and a working frequency of 72 MHz. It has a rich I/O port and peripherals. It is capable of operating in the temperature range of −40°C to +105°C, and it has an unprecedented advantage in the 32-bit microcontroller market.(2) Function. The chip is mainly responsible for the normal coordination of various sensor modules of the slave computer. The data collected by the sensor is simply processed, analyzed, and then sent to the master computer through the NRF24L01 wireless transmission module and assists the master computer to control the entire system operation. The lower part of this system uses the minimum boar of STM32F103ZET6.


### 4.1.2. Smoke Sensor Module

(1) Introduction. This system uses an MQ-2 smoke sensor to detect the smoke concentration in the environment. This sensor has a high sensitivity to gas and so on, with a long service life and reliable stability. The principle is that when flammable gas is present in the environment, the electrical conductivity of the sensor increases with the increase of the concentration of the flammable gas in the air, thereby determining the concentration of the flammable gas in the current environment. Use a simple circuit to output high electrical level and low electrical level, and set a threshold for exceeding the standard. When the output is of a high level, it means that the concentration exceeds the standard.(2) Function. MQ-2 in this system is responsible for detecting whether the smoke concentration in the environment exceeds the standard.(3) Working Principle. The signals output by most sensor modules are relatively weak, and there is no exception for smoke sensors. Therefore, the output signals need to be processed through a set circuit to meet the processor’s requirements for input signal detection. This system uses a noninverting proportional amplifier circuit to reduce expansion on hardware and achieve the highest cost performance.


### 4.1.3. Flame Sensor Module

(1) Introduction. This system uses a flame sensor module YL-38 to detect the fire source in the environment. When a fire source exists in the environment where the sensor is located, the sensor module will send a high-level signal to the main control chip. It can monitor the infrared light with the wavelength range of 700 nm–1000 nm and detection angle of 60 degrees, and the value is inversely proportional to the intensity of external infrared light.(2) Function. In this system, the flame sensor is responsible for detecting the flame in warehouse.(3) Working Principle. The flame sensor module is equipped with a far-infrared flame probe, which can convert the change in the intensity of external infrared light into the change in current. The high level and low level of the digital interface DO can reflect whether the ambient flame spectrum exceeds the set threshold so that the processor can judge whether there is fire condition in the current environment only by checking the high level and low level of the digital interface DO. If it exceeds the set threshold, it will output high level, and the switch indicator will be lighted. Its schematic diagram is as shown in Figure 2.Figure 2
Schematic diagram of the flame sensor.


### 4.1.4. Temperature-Humidity Sensor Module

(1) Introduction. This system is equipped with a temperature-humidity sensor module DHT11 on the slave computer to collect temperature and humidity information in the environment. It is a temperature-humidity composite sensor with a calibrated digital signal output. It is designed with a single bus data format, which can complete data communication every four milliseconds. This string of data is divided into a decimal part and an integer part. The specific data format is as follows: the first eight digits represent the integer part of the humidity, and the next eight digits represent the decimal part of humidity. The further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. This system is only accurate to the integer part of temperature and humidity. The physical object is as shown in Figure 3.Figure 3
Physical picture of temperature-humidity sensor.(2) Function. The temperature-humidity sensor module is responsible for collecting ambient temperature and humidity in this system.(3) Working Principle. The module includes a resistive humidity sensing element and an NTC temperature measuring element and is connected to a high-performance 8-bit microcontroller. The sensing layer of the resistance humidity sensor will be interfered with by chemical vapor, and the diffusion of chemical substances in the sensing layer may cause the measurement value to drift and decrease the sensitivity. The hardware connection diagram is shown in Figure 4.Figure 4
Hardware schematic diagram of temperature-humidity sensor.


### 4.1.5. Photosensitive Sensor Module

(1) Brief Introduction. This system uses the photosensitive sensor that comes with the demo board STM32 to obtain the light illumination value by combining with its internal ADC.(2) Function. The photosensitive sensor module in this system is responsible for the function of collecting ambient light illumination.(3) Working Principle. This module is mounted on the master computer, reads the voltage value of the photosensitive sensor (LS1) through channel 6 (PF8) of ADC3, and converts it into a light intensity value of 0–100. The brighter the light on the module is, the larger the value could be; the darker the light on the module is, the smaller the value could be. Therefore, the change in light intensity can be viewed by blocking LS1 and illuminating LS1 with light during the experiment. The hardware connection diagram is as shown in Figure 5.Figure 5
Hardware schematic diagram of photoelectric sensor.(1) Brief Introduction. This system uses multiple wireless modules, which are, respectively, mounted on the master computer and the slave computer to realize the wireless communication between the master computer and the slave computer. The wireless module NRF24L01 works in the 2.4 GHz–2.5 GHz ISM frequency band, uses FSK modulation, and integrates the Enhanced Short Burst protocol. Hardware Schematic Diagram of NRF24L01 Wireless Module is as shown in Figure 6. This module can not only realize point-to-point communication but also implement single-point-to-multipoint (up to one-to-six) communication. Its communication speed can reach 2 Mbps. This module is simple and easy to learn. Users can easily implement the function of wireless communication only by reserving 5 GPIOs and 1 interrupt input pin for the microcontroller system. Most demo boards have assigned pins to this module, and some of them are designed with related drivers, so it boasts of very good cost performance.Figure 6
Hardware schematic diagram of NRF24L01 wireless module.(2) Function. The wireless module in this system realizes the wireless communication between the master computer and the slave computer and is responsible for the data transmission between the two.(3) Working Principle. The master computer and the slave computer are, respectively, equipped with wireless modules and configured with different modes. In this system, the slave computer is configured with data transmission mode, while the master computer is configured with data reception mode. This module uses the SPI protocol for communication, which just requires connection and data read/write in accordance with the standard SPI protocol.


## 4.1.1. Slave Computer MCU-STM32F103

(1) Introduction. STM32F1 series enhanced chips with Cortex-M3 as the kernel is used by this system as the controller MCU of slave computer. Cortex-M3 is a 32-bit RISC processor with a built-in high-speed memory and a working frequency of 72 MHz. It has a rich I/O port and peripherals. It is capable of operating in the temperature range of −40°C to +105°C, and it has an unprecedented advantage in the 32-bit microcontroller market.(2) Function. The chip is mainly responsible for the normal coordination of various sensor modules of the slave computer. The data collected by the sensor is simply processed, analyzed, and then sent to the master computer through the NRF24L01 wireless transmission module and assists the master computer to control the entire system operation. The lower part of this system uses the minimum boar of STM32F103ZET6.


## 4.1.2. Smoke Sensor Module

(1) Introduction. This system uses an MQ-2 smoke sensor to detect the smoke concentration in the environment. This sensor has a high sensitivity to gas and so on, with a long service life and reliable stability. The principle is that when flammable gas is present in the environment, the electrical conductivity of the sensor increases with the increase of the concentration of the flammable gas in the air, thereby determining the concentration of the flammable gas in the current environment. Use a simple circuit to output high electrical level and low electrical level, and set a threshold for exceeding the standard. When the output is of a high level, it means that the concentration exceeds the standard.(2) Function. MQ-2 in this system is responsible for detecting whether the smoke concentration in the environment exceeds the standard.(3) Working Principle. The signals output by most sensor modules are relatively weak, and there is no exception for smoke sensors. Therefore, the output signals need to be processed through a set circuit to meet the processor’s requirements for input signal detection. This system uses a noninverting proportional amplifier circuit to reduce expansion on hardware and achieve the highest cost performance.


## 4.1.3. Flame Sensor Module

(1) Introduction. This system uses a flame sensor module YL-38 to detect the fire source in the environment. When a fire source exists in the environment where the sensor is located, the sensor module will send a high-level signal to the main control chip. It can monitor the infrared light with the wavelength range of 700 nm–1000 nm and detection angle of 60 degrees, and the value is inversely proportional to the intensity of external infrared light.(2) Function. In this system, the flame sensor is responsible for detecting the flame in warehouse.(3) Working Principle. The flame sensor module is equipped with a far-infrared flame probe, which can convert the change in the intensity of external infrared light into the change in current. The high level and low level of the digital interface DO can reflect whether the ambient flame spectrum exceeds the set threshold so that the processor can judge whether there is fire condition in the current environment only by checking the high level and low level of the digital interface DO. If it exceeds the set threshold, it will output high level, and the switch indicator will be lighted. Its schematic diagram is as shown in Figure 2.Figure 2
Schematic diagram of the flame sensor.


## 4.1.4. Temperature-Humidity Sensor Module

(1) Introduction. This system is equipped with a temperature-humidity sensor module DHT11 on the slave computer to collect temperature and humidity information in the environment. It is a temperature-humidity composite sensor with a calibrated digital signal output. It is designed with a single bus data format, which can complete data communication every four milliseconds. This string of data is divided into a decimal part and an integer part. The specific data format is as follows: the first eight digits represent the integer part of the humidity, and the next eight digits represent the decimal part of humidity. The further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. This system is only accurate to the integer part of temperature and humidity. The physical object is as shown in Figure 3.Figure 3
Physical picture of temperature-humidity sensor.(2) Function. The temperature-humidity sensor module is responsible for collecting ambient temperature and humidity in this system.(3) Working Principle. The module includes a resistive humidity sensing element and an NTC temperature measuring element and is connected to a high-performance 8-bit microcontroller. The sensing layer of the resistance humidity sensor will be interfered with by chemical vapor, and the diffusion of chemical substances in the sensing layer may cause the measurement value to drift and decrease the sensitivity. The hardware connection diagram is shown in Figure 4.Figure 4
Hardware schematic diagram of temperature-humidity sensor.


## 4.1.5. Photosensitive Sensor Module

(1) Brief Introduction. This system uses the photosensitive sensor that comes with the demo board STM32 to obtain the light illumination value by combining with its internal ADC.(2) Function. The photosensitive sensor module in this system is responsible for the function of collecting ambient light illumination.(3) Working Principle. This module is mounted on the master computer, reads the voltage value of the photosensitive sensor (LS1) through channel 6 (PF8) of ADC3, and converts it into a light intensity value of 0–100. The brighter the light on the module is, the larger the value could be; the darker the light on the module is, the smaller the value could be. Therefore, the change in light intensity can be viewed by blocking LS1 and illuminating LS1 with light during the experiment. The hardware connection diagram is as shown in Figure 5.Figure 5
Hardware schematic diagram of photoelectric sensor.(1) Brief Introduction. This system uses multiple wireless modules, which are, respectively, mounted on the master computer and the slave computer to realize the wireless communication between the master computer and the slave computer. The wireless module NRF24L01 works in the 2.4 GHz–2.5 GHz ISM frequency band, uses FSK modulation, and integrates the Enhanced Short Burst protocol. Hardware Schematic Diagram of NRF24L01 Wireless Module is as shown in Figure 6. This module can not only realize point-to-point communication but also implement single-point-to-multipoint (up to one-to-six) communication. Its communication speed can reach 2 Mbps. This module is simple and easy to learn. Users can easily implement the function of wireless communication only by reserving 5 GPIOs and 1 interrupt input pin for the microcontroller system. Most demo boards have assigned pins to this module, and some of them are designed with related drivers, so it boasts of very good cost performance.Figure 6
Hardware schematic diagram of NRF24L01 wireless module.(2) Function. The wireless module in this system realizes the wireless communication between the master computer and the slave computer and is responsible for the data transmission between the two.(3) Working Principle. The master computer and the slave computer are, respectively, equipped with wireless modules and configured with different modes. In this system, the slave computer is configured with data transmission mode, while the master computer is configured with data reception mode. This module uses the SPI protocol for communication, which just requires connection and data read/write in accordance with the standard SPI protocol.


## 4.2. Master Computer Part

### 4.2.1. Master Computer MCU-STM32F103

The MCU is mainly responsible for receiving the data collected by the sensor modules transmitted by the slave computer, configuring the acoustooptic alarm device, combining with the data to implement the alarm function, and sending the data to the server through the serial port. This section uses the STM32F103ZET6 battleship board.


### 4.2.2. NRF24L01 Wireless Module

The master computer part of this system uses the same model of the NRF34L01 wireless module as the slave computer, of which the wireless module is used to send data, and the master computer is used to receive data.


### 4.2.3. LCD Module

(1) Introduction. This system uses the built-in TFTLCD liquid crystal module of the demo board. TFT is a thin film transistor. Each pixel of the liquid crystal display is equipped with one TFT. The LCD module is designed with the size of 2.8 inches, the resolution of 320 ∗ 240, and a 16-bit true color display (RGB565: 5 red, 6 green, and 5 blue). Different colors can be displayed through RGB descriptions, and its interface is designed with a 16-bit 80-parallel port. This LCD screen can greatly improve the image quality.(2) Function. This module displays the data of the slave computer in this system. The hardware connection diagram is as shown in Figure 7.Figure 7
Hardware schematic diagram of LCD.


## 4.2.1. Master Computer MCU-STM32F103

The MCU is mainly responsible for receiving the data collected by the sensor modules transmitted by the slave computer, configuring the acoustooptic alarm device, combining with the data to implement the alarm function, and sending the data to the server through the serial port. This section uses the STM32F103ZET6 battleship board.


## 4.2.2. NRF24L01 Wireless Module

The master computer part of this system uses the same model of the NRF34L01 wireless module as the slave computer, of which the wireless module is used to send data, and the master computer is used to receive data.


## 4.2.3. LCD Module

(1) Introduction. This system uses the built-in TFTLCD liquid crystal module of the demo board. TFT is a thin film transistor. Each pixel of the liquid crystal display is equipped with one TFT. The LCD module is designed with the size of 2.8 inches, the resolution of 320 ∗ 240, and a 16-bit true color display (RGB565: 5 red, 6 green, and 5 blue). Different colors can be displayed through RGB descriptions, and its interface is designed with a 16-bit 80-parallel port. This LCD screen can greatly improve the image quality.(2) Function. This module displays the data of the slave computer in this system. The hardware connection diagram is as shown in Figure 7.Figure 7
Hardware schematic diagram of LCD.


## 4.3. Server Part and Client Part

This system uses a laptop as the server, and this system uses an Android phone as the client.


## 5. Design and Implementation of System Software

Software design is the process of developing an appropriate implementation plan based on the requirements. As the macroidea of the whole system, it reflects the entire software to a certain extent. The software development of the environmental monitoring system based on wireless transmission is divided into four parts: software design and implementation of data acquisition terminal on the slave computer, software design and implementation of data processing on the master computer, software design and implementation of the server, and software design and implementation of the client. Each part needs to be designed with a corresponding driver. The software structure of the system is as shown in Figure8.Figure 8
Structure diagram of system software.This system uses multiple types of sensor modules to collect environmental information (temperature-humidity, smoke concentration, etc.), so it is necessary to set a corresponding analysis program for each sensor. The following is the introduction to the configuration of each sensor.


### 5.1. Temperature-Humidity Sensor Module

This system is connected to DHT11 temperature-humidity sensor module by pin No. 11 of GPIOG and realizes the control. DHT11 is a digital sensor that collects the data of temperature and humidity. Designed with a single bus data format, DHT11 can complete data communication every four milliseconds. The specific data format is as follows: the first eight digits represent the integer part of the humidity, the next eight digits represent the decimal part of the humidity, the further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. The checksum data is the sum of the first four bytes. Using the checksum data can effectively ensure the accuracy of data transmission.The specific process of temperature-humidity data collection is as follows: after the processor sends the start signal, the temperature-humidity module starts to work and sends out a response signal while sending a data packet representing the temperature and humidity. After receiving this part of the data, the processor can choose to use the specific part of the data according to users’ requirements and conducted conversion on related data, such as temperature-humidity data with decimals and temperature-humidity without decimals.The flame sensor module is controlled by No. 12 pin of GPIOA, and the IO port is set as the input mode. The smoke sensor module is controlled by No. 11 pin and No. 15 pin of GPIOA and converts the analog value into digital value through the AD chip. Therefore, the IO port is also set as input mode. The photosensitive sensor module is controlled by No. 8 pin of GPIOF and converts the analog quantity into digital quantity through the AD chip, so the IO port is set as the input mode at the same time.


### 5.2. Design for Wireless Transmission Driver

This system adopts wireless transmission technology to realize the data communication function between the master computer and the slave computer. It is required to first collect the data of each module, then perform quantitative processing on the data, and finally transmit the data.


#### 5.2.1. Data Collection and Integration

This system needs to collect and integrate the following data, including temperature, humidity, flame status, smoke concentration, and light intensity. It is realized by calling the data collection functions of each sensor module, including Get_SensorData (), DHT11_Read_Data (& temperature, & humidity), and Lsens_Get_Val (). Then, the data are sent to the server through printf ().


#### 5.2.2. Configuration of SPI Protocol

This system uses the NRF34L01 wireless transmission module to send data and adopts SPI communication protocol to realize communication. This system will, respectively, configure the STM32 SPI interface as the master-slave mode to achieve the initialization and read and write operations of the upper and slave computers. The initialization and read and write operations of the SPI interface can be realized through programming so that data communication can be implemented through NRF24L01.


#### 5.2.3. Configuration of NRF24L01 Wireless Module

This system uses a wireless module in both the master computer and the slave computer. Data is sent from the slave computer to the master computer. Therefore, the slave computer is configured as the sending mode and the master computer is configured as the receiving mode.


### 5.3. Design of Serial Communication Driver

This system is designed to connect the master computer and the server through a serial port. Therefore, serial port communication is used to achieve communication between the master computer and the server. The serial port can be used to realize long-distance communication. As asynchronous communication, its most important parameters include the baud rate, data bit, stop bit, and parity bit. Therefore, to achieve serial communication between the master computer and the server, the user needs to configure the matches related parameters to the communication port. These parameters are described as follows:Baud rate: the number of bits transmitted per second (9600, 115200, etc.)Parity bit: error check method in serial communication, which can indicate the accuracy of the transmitted dataStop bit: the last bit of a single packet, which indicates the end of the packetData bit: a parameter that measures the actual data bits in a communicationThe master computer of this system realizes the serial transmission of data by calling the printf () function. The following code initializes the serial port and configures the printf () function.


### 5.4. Network Communication Driver Design

This system uses TCP protocol to realize network communication so that communication can be realized between mobile phone client and computer server. The TCP/IP protocol has been implemented in the protocol stacks owned by mobile phones and computers and can be used quickly and easily. In addition, TCP is a connection-based transmission protocol, by which data can be transmitted more stably and reliably. To use the TCP protocol, the users first need to establish a socket to support the TCP/IP protocol and indicate specific applications.This system configures TCP programming for the server and client respectively. The programming idea is as shown in Figure9.Figure 9
The programming idea.Socket is widely used in network communication. Socket can identify a specific application because it contains the information necessary for network communication: IP address (local; remote), protocol port number (local; remote), and communication protocol (TCP, UDP, etc.). The connection process can be divided into the following three steps:(1)
Server’s monitoring: Monitor the network status in real time and wait for connection requests of the client.(2)
Client’s request: The client’s socket makes a connection request.(3)
Connection confirmation: After the server socket monitors the connection request of the client socket, it responds to the request of the client socket and establishes a new process.The configuration procedure for establishing a connection by using socket is in Appendix A).


### 5.5. Design for Display Interface Program

The interface design of this system is divided into three parts according to the software design requirements: master computer interface design, server interface design, and client interface design. The master computer interface design includes digital tube display and LCD display; the server interface design includes environmental data display interface and server interface; the client part includes one data read interface.The design for display interface program is in Appendix B, the server interface design is in Appendix C, and the client interface design is in Appendix D.


### 5.6. Data Processing Algorithm

According to the software design requirements, this system will adopt a user-defined data transmission format and implement the alarm function through data analysis.The implementation of the alarm device is in Appendix E, and the data transmission protocol is in Appendix F.


## 5.1. Temperature-Humidity Sensor Module

This system is connected to DHT11 temperature-humidity sensor module by pin No. 11 of GPIOG and realizes the control. DHT11 is a digital sensor that collects the data of temperature and humidity. Designed with a single bus data format, DHT11 can complete data communication every four milliseconds. The specific data format is as follows: the first eight digits represent the integer part of the humidity, the next eight digits represent the decimal part of the humidity, the further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. The checksum data is the sum of the first four bytes. Using the checksum data can effectively ensure the accuracy of data transmission.The specific process of temperature-humidity data collection is as follows: after the processor sends the start signal, the temperature-humidity module starts to work and sends out a response signal while sending a data packet representing the temperature and humidity. After receiving this part of the data, the processor can choose to use the specific part of the data according to users’ requirements and conducted conversion on related data, such as temperature-humidity data with decimals and temperature-humidity without decimals.The flame sensor module is controlled by No. 12 pin of GPIOA, and the IO port is set as the input mode. The smoke sensor module is controlled by No. 11 pin and No. 15 pin of GPIOA and converts the analog value into digital value through the AD chip. Therefore, the IO port is also set as input mode. The photosensitive sensor module is controlled by No. 8 pin of GPIOF and converts the analog quantity into digital quantity through the AD chip, so the IO port is set as the input mode at the same time.


## 5.2. Design for Wireless Transmission Driver

This system adopts wireless transmission technology to realize the data communication function between the master computer and the slave computer. It is required to first collect the data of each module, then perform quantitative processing on the data, and finally transmit the data.


### 5.2.1. Data Collection and Integration

This system needs to collect and integrate the following data, including temperature, humidity, flame status, smoke concentration, and light intensity. It is realized by calling the data collection functions of each sensor module, including Get_SensorData (), DHT11_Read_Data (& temperature, & humidity), and Lsens_Get_Val (). Then, the data are sent to the server through printf ().


### 5.2.2. Configuration of SPI Protocol

This system uses the NRF34L01 wireless transmission module to send data and adopts SPI communication protocol to realize communication. This system will, respectively, configure the STM32 SPI interface as the master-slave mode to achieve the initialization and read and write operations of the upper and slave computers. The initialization and read and write operations of the SPI interface can be realized through programming so that data communication can be implemented through NRF24L01.


### 5.2.3. Configuration of NRF24L01 Wireless Module

This system uses a wireless module in both the master computer and the slave computer. Data is sent from the slave computer to the master computer. Therefore, the slave computer is configured as the sending mode and the master computer is configured as the receiving mode.


## 5.2.1. Data Collection and Integration

This system needs to collect and integrate the following data, including temperature, humidity, flame status, smoke concentration, and light intensity. It is realized by calling the data collection functions of each sensor module, including Get_SensorData (), DHT11_Read_Data (& temperature, & humidity), and Lsens_Get_Val (). Then, the data are sent to the server through printf ().


## 5.2.2. Configuration of SPI Protocol

This system uses the NRF34L01 wireless transmission module to send data and adopts SPI communication protocol to realize communication. This system will, respectively, configure the STM32 SPI interface as the master-slave mode to achieve the initialization and read and write operations of the upper and slave computers. The initialization and read and write operations of the SPI interface can be realized through programming so that data communication can be implemented through NRF24L01.


## 5.2.3. Configuration of NRF24L01 Wireless Module

This system uses a wireless module in both the master computer and the slave computer. Data is sent from the slave computer to the master computer. Therefore, the slave computer is configured as the sending mode and the master computer is configured as the receiving mode.


## 5.3. Design of Serial Communication Driver

This system is designed to connect the master computer and the server through a serial port. Therefore, serial port communication is used to achieve communication between the master computer and the server. The serial port can be used to realize long-distance communication. As asynchronous communication, its most important parameters include the baud rate, data bit, stop bit, and parity bit. Therefore, to achieve serial communication between the master computer and the server, the user needs to configure the matches related parameters to the communication port. These parameters are described as follows:Baud rate: the number of bits transmitted per second (9600, 115200, etc.)Parity bit: error check method in serial communication, which can indicate the accuracy of the transmitted dataStop bit: the last bit of a single packet, which indicates the end of the packetData bit: a parameter that measures the actual data bits in a communicationThe master computer of this system realizes the serial transmission of data by calling the printf () function. The following code initializes the serial port and configures the printf () function.


## 5.4. Network Communication Driver Design

This system uses TCP protocol to realize network communication so that communication can be realized between mobile phone client and computer server. The TCP/IP protocol has been implemented in the protocol stacks owned by mobile phones and computers and can be used quickly and easily. In addition, TCP is a connection-based transmission protocol, by which data can be transmitted more stably and reliably. To use the TCP protocol, the users first need to establish a socket to support the TCP/IP protocol and indicate specific applications.This system configures TCP programming for the server and client respectively. The programming idea is as shown in Figure9.Figure 9
The programming idea.Socket is widely used in network communication. Socket can identify a specific application because it contains the information necessary for network communication: IP address (local; remote), protocol port number (local; remote), and communication protocol (TCP, UDP, etc.). The connection process can be divided into the following three steps:(1)
Server’s monitoring: Monitor the network status in real time and wait for connection requests of the client.(2)
Client’s request: The client’s socket makes a connection request.(3)
Connection confirmation: After the server socket monitors the connection request of the client socket, it responds to the request of the client socket and establishes a new process.The configuration procedure for establishing a connection by using socket is in Appendix A).


## 5.5. Design for Display Interface Program

The interface design of this system is divided into three parts according to the software design requirements: master computer interface design, server interface design, and client interface design. The master computer interface design includes digital tube display and LCD display; the server interface design includes environmental data display interface and server interface; the client part includes one data read interface.The design for display interface program is in Appendix B, the server interface design is in Appendix C, and the client interface design is in Appendix D.


## 5.6. Data Processing Algorithm

According to the software design requirements, this system will adopt a user-defined data transmission format and implement the alarm function through data analysis.The implementation of the alarm device is in Appendix E, and the data transmission protocol is in Appendix F.


## 6. System Function Debugging

This system mainly judges and debugs from the data display of each sensor module. Start the system and obtain multiple data in real time on the mobile APP, and judge whether the collected data meet the corresponding conditions according to different environmental conditions, such as the light intensity and the temperature.


### 6.1. Temperature-Humidity Module

The slave computer is equipped with a temperature-humidity sensor module to collect temperature and humidity information in the environment. DHT11 has obvious advantages, such as strong anti-interference ability. It is designed with a single bus data format, which can complete data communication every four milliseconds. This series of data is divided into decimal and integer parts. The specific data format is as follows: the first eight digits represent the integer part of the humidity, the next eight digits represent the decimal part of the humidity, the further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. This system is only accurate to the integer part of the temperature and humidity. Start the system, then open the serial port, and debug the mobile APP to receive the temperature and humidity data collected by the temperature-humidity sensor.


### 6.2. Flame Sensor Module

The slave computer is equipped with a flame sensor module to collect the flame status information in the environment. It can monitor the infrared light with the wavelength in the range of 700 nm–1000 nm, with the detection angle of 60 degrees, and the value is inversely proportional to the intensity of external infrared light. Start the system, then open the serial port, debug the mobile APP to receive the flame status data information collected by the flame sensor, and lean the lighter to the flame sensor module. The collected data is displayed in real time through the serial port.


### 6.3. Smoke Sensor Module

The slave computer is equipped with a smoke sensor module, which can collect the smoke concentration information in the environment. The MQ-2 gas sensor can detect flammable gases in the environment and judge the environmental safety status by combining with the flame sensor module. Start the system, then open the serial port, and debug the mobile APP to receive the smoke concentration data information collected by the smoke sensor. During the debugging process, it is required to use the unburned gas released by the lighter as the detected gas, and let the gas slowly approach the sensor.


### 6.4. Photosensitive Sensor Module

The slave computer is equipped with a photosensitive sensor to collect light intensity information in the environment. This system reads the voltage value of the photosensitive sensor through channel 6 of ADC3 and converts it into the light intensity value of 0∼100. The brighter the light on the module is, the larger the value could be; the darker the light is, the smaller the value would be. Start the system, then open the serial port, and debug the mobile APP to receive the smoke concentration data information collected by the smoke sensor. It is required to check the light intensity change by adjusting the light source of mobile phone.


## 6.1. Temperature-Humidity Module

The slave computer is equipped with a temperature-humidity sensor module to collect temperature and humidity information in the environment. DHT11 has obvious advantages, such as strong anti-interference ability. It is designed with a single bus data format, which can complete data communication every four milliseconds. This series of data is divided into decimal and integer parts. The specific data format is as follows: the first eight digits represent the integer part of the humidity, the next eight digits represent the decimal part of the humidity, the further next eight digits represent the integer part of the temperature, the following next eight digits represent the decimal part of the temperature, and the last eight digits represent the checksum data. This system is only accurate to the integer part of the temperature and humidity. Start the system, then open the serial port, and debug the mobile APP to receive the temperature and humidity data collected by the temperature-humidity sensor.


## 6.2. Flame Sensor Module

The slave computer is equipped with a flame sensor module to collect the flame status information in the environment. It can monitor the infrared light with the wavelength in the range of 700 nm–1000 nm, with the detection angle of 60 degrees, and the value is inversely proportional to the intensity of external infrared light. Start the system, then open the serial port, debug the mobile APP to receive the flame status data information collected by the flame sensor, and lean the lighter to the flame sensor module. The collected data is displayed in real time through the serial port.


## 6.3. Smoke Sensor Module

The slave computer is equipped with a smoke sensor module, which can collect the smoke concentration information in the environment. The MQ-2 gas sensor can detect flammable gases in the environment and judge the environmental safety status by combining with the flame sensor module. Start the system, then open the serial port, and debug the mobile APP to receive the smoke concentration data information collected by the smoke sensor. During the debugging process, it is required to use the unburned gas released by the lighter as the detected gas, and let the gas slowly approach the sensor.


## 6.4. Photosensitive Sensor Module

The slave computer is equipped with a photosensitive sensor to collect light intensity information in the environment. This system reads the voltage value of the photosensitive sensor through channel 6 of ADC3 and converts it into the light intensity value of 0∼100. The brighter the light on the module is, the larger the value could be; the darker the light is, the smaller the value would be. Start the system, then open the serial port, and debug the mobile APP to receive the smoke concentration data information collected by the smoke sensor. It is required to check the light intensity change by adjusting the light source of mobile phone.


## 7. Conclusion

With the science advancement and technology popularization, intelligent devices enjoy more and more widespread application, and problems such as the accuracy of environmental issues have been aroused therefrom. The previous environmental monitoring was carried out by means of manual monitoring, which has many shortcomings from the present point of view, including low efficiency and unscientific management system. It was not conducive to the full utilization of resources and scientific management. Moreover, it was not difficult to find from the major accidents in these years that many were caused by human factors. The development of an intelligent monitoring system can solve the related problems. The system can implement the following functions:(1)
Real-time collection of environmental information is implemented, and data can be processed and analyzed through processors.(2)
The wireless transmission of data is realized so that the communication between the master computer and the slave computer can be implemented.(3)
The serial communication of data is realized so that the communication between the master computer and the server can be implemented.(4)
The network communication of data is implemented, and the environmental status can be monitored through a mobile APP from a long distance.(5)
The intelligent alarm function can be implemented.



---

*Source: 6070664-2021-10-28.xml*