Hardware Implementation of STM32 Microcontroller-Based Indoor Environment Monitoring System

Microcontroller is widely used in the intelligent life of modern society. Intelligent development based on Microcontroller to solve the actual needs of people’s life, work, study and other fields is the core of Microcontroller application. Therefore, it is a task for researchers to understand the structure and performance of microcontroller, develop software, and be familiar with the method and process of intelligent development based on microcontroller. And with that in mind, this paper designs and produces a physical hardware system for indoor environment detection based on STM32 microcontroller. The system can detect the light intensity, temperature and humidity, and CO gas concentration in the indoor environment; and the data is integrated and processed by the STM32 microcontroller to display the current parameter values of each quantity in the indoor environment on a 3.5-inch resistive screen; at the same time, the PC can also log in to the OneNET cloud platform through the web page, and display the light intensity, temperature and humidity, and CO gas concentration values in the indoor environment in real time in the device created by OneNET for real-time viewing. The system can also display the light intensity, temperature and humidity, and CO gas concentration values in the indoor environment in real time. The hardware system has been tested and tested to achieve its function.


Introduction
The intensity of light, temperature and humidity, and CO gas concentration in 2. Hardware Design Implementation

STM32 Indoor Detection System Design Ideas
Based on STM32F103 series microcontroller development board for indoor detection system design ideas.
1) The data of indoor environment temperature and humidity collected by temperature and humidity sensor module in real time is transmitted to STM32 microcontroller, integrated and processed to display the current environment temperature and humidity on 3.5 inch resistive screen [3]; and the microcontroller is connected to OneNET platform through WIFI module ESP8266, the measured temperature and humidity data can be uploaded to PC or cell phone in real time to understand the environment in real time [4]; if the collected indoor temperature is too high and exceeds the set threshold value, the buzzer will alarm.
2) The data of light intensity in the indoor environment is collected in real time with the photoresistor light-sensing module and transmitted to the microcontroller. After the data is processed by the microcontroller, it is converted into light intensity figures and transmitted to the OneNET cloud platform through the ESP8266 module, and the light intensity in the current environment can be viewed remotely in real time in the device established by the OneNET cloud platform.
3) The voltage value of CO gas concentration in the indoor environment is collected in real time with the CO sensor module and transmitted to the micro-Open Journal of Applied Sciences controller, after the microcontroller converts the voltage value into CO concentration value between 0 and 100, and the data is uploaded to the OneNET cloud platform using the ESP8266 module, and the CO concentration in the current environment can be viewed in the device established by the OneNET platform at any time, and if the air CO concentration exceeds the set threshold, the buzzer alarms and sends alarm information to the user. 4) Using the WIFI module ESP8266 module, the data collected by the sensor is handed over to the MCU, and according to the EDP protocol of OneNET platform. It is encapsulated into data packets using json format and uploaded to OneNET platform, which parses the data packets and displays them to the web side using line graphs and dials to present them to the users intuitively and conveniently [5].

Hardware Design of STM32 Indoor Detection System
System hardware selection and connection: The core controller of the system is selected STM32F103 microcontroller development board (MCU), whose hardware circuit is shown in Figure 1, it is the main chip is STM32F103ZET6, equipped with 512 KB flash memory and 16 MB extended SPI flash memory, contains a power supply circuit, control circuit, download circuit, crystal circuit and reset circuit, can use a variety of interfaces Development of various experiments and design of a development board [6]. Photoresistor sensor module, hardware circuit as shown in Figure 2, the wiring of the photoreceptor module, VCC connected to the positive 3.3 V power supply, GND connected to the negative power supply, the output analog AO interface and the main control chip MCU PF6 pin connection. The integrated digital humidity and temperature sensor DHT11, hardware circuit as shown in Figure 3, its connection, VCC pin connected to the 3.3 V power supply, GND connected to the negative side of the power supply, data output interface and the main chip MCU PG11 pin connection for data transmission.CO gas sensor MQ-7, hardware circuit as shown in Figure 4, this sensor has a very sensitive sense of CO gas concentration, also This sensor is very sensitive to CO gas concentration and is also suitable for smoke and hazardous gas detection, its wiring, VCC connected to 5 V power supply positive, GND connected to power supply negative, output analog AO port and the main chip MCU PA7 pin connection. 3.5 inch resistive screen TFT-LCD, hardware circuit as shown in Figure 5, its resolution 480 * 320, size: 97.4 * 56.4, has 16-bit 8080 parallel port, its wiring, TFT-LCD pin and MCU corresponding pin connection. LCD pins are connected to the corresponding pins of MCU. There is also WIFI module ATK-ESP8266, hardware circuit as shown in Figure 6, its wiring VCC connected to 3.3 V power supply positive, GND ground, ATK-ESP8266 serial output RXD pins and serial input TXD pins connected with MCU serial input TXD pins and serial output RXD pins. The relay module, wired in such a way that VCC is connected to the positive terminal of 5 V power supply, GND is connected to the negative terminal of power supply, and the IN pin is connected to the PG10 pin of MCU. Open Journal of Applied Sciences

Software Programming
The process of hardware design of the detection system not only considers the connection of the hardware, but also requires consideration of the control program writing. After the realization of the system hardware, it must be controlled by the program, and each part must be coordinated to achieve its set function.
The more complex and complicated the function of the system, the more difficult it is to write the internal control code, therefore. The more complex the system, the more difficult it is to write the internal control code. Therefore, the control program should be written in a logical and rational manner, and the program should be more concise and logical under the condition of ensuring the normal operation of the system. The software part of this system design process is: the choice of programming language, the design of the main function code, serial port design, interrupt design, display part design, temperature and humidity part, light part, WIFI module part, gas concentration part and alarm part design. C language was chosen for this program programming.

Main Program Design
The main program, as the beginning of the STM32 microcontroller program operation, is written to contain mainly the initialization of each part of the mod-

Subroutine Design
The main program needs to call each subroutine when it is executed. The subroutines of this system mainly include temperature measurement subroutine, humidity measurement subroutine, light intensity detection subroutine, CO gas concentration measurement subroutine, relay subroutine, alarm system subroutine, threshold subroutine, display subroutine, serial port subroutine and interrupt

1) Temperature and humidity measurement subroutine design
The sensor is initialized by the DHT11_init function, and the temperature and humidity values of the DHT11 are read according to the execution sequence of each bus. Use the dht11_read_data function to read the temperature and humidity values read from the DHT11 [7]. If the return value is zero it means that the reading was successful, if the return value is 1, the reading failed. The file DHT11.h contains mainly port parameters and function declarations, and the code is relatively simple [8]. After successful initialization, the data is collected at 100 ms intervals and uploaded to the OneNET cloud platform for data display.

2) Light intensity measurement subroutine design
Add the file lsens.c under the HARDWARE group and add the header file lsens.h to the header file's include path. The photoresistor sensor is initialized using the Lsens_Init function, followed by the PF6 interface initialization bit analog input interface, followed by the channel ADC3 initialization using the

3) Measuring gas concentration subroutine design
The flow of CO gas concentration detection subroutine design is shown in

STM32 Indoor Detection System Hardware Debugging and Testing
Choose Keil 5 as the programming software, after installing MDK5, install the installation package that supports the STM32F1 series development board: Keil.STM32F1xx_DFP.1.0.5.pack, after the installation is complete, you can develop and run the program. The program will be run on the STM32 microcontroller, and the program will be modified in time for any errors, warnings and other problems that may occur during the program run, until the program can be compiled successfully on the Keil5 software without errors. The entire program can run normally in the microcontroller and the modules can cooperate with each other to achieve the expected functions of the system. Since the One-NET cloud platform is chosen to receive the detected data from the WIFI module on the PC side, the account of the OneNET cloud platform is logged in first Open Journal of Applied Sciences before use. The connection is made so that the device created in OneNET platform can be online and realize the data transfer between microcontroller and PC [9].
The modules are connected to the STM32 microcontroller, and care is taken not to connect the wrong pins when connecting them. The physical connection is shown in Figure 9, and after the control program is installed and debugged, the devices established on the OneNET platform are viewed online. The actual test is conducted indoors, and the measured data of temperature and humidity, light intensity, and CO gas concentration in the environment are displayed on a 3.5" resistive screen, as shown in Figure 10. Meanwhile, OneNET cloud platform can display the detected data in real time with both refraction graph and dial, and present the detected data with a line graph for temperature as shown in Figure 11, humidity as shown in Figure 12, CO gas concentration as shown in Figure 13, and light intensity as shown in Figure 14 [10]. Figure 11 shows the temperature change detected during the 6-minute period. Figure 12 shows the humidity change detected during the 6-minute period. Figure 13 shows the change of CO gas concentration detected during the period of 6 minutes. Figure 14 shows Open Journal of Applied Sciences      The test results show that the finished object can better implement the expected functions of the STM32 indoor detection system.

Conclusions
After the system test was completed, the actual indoor environment was measured with the system. The measured value of indoor temperature was 26˚C, the humidity value was 50%, the data displayed by OneNET platform was compared with the actual real-time weather data in the cell phone, the measured data was reasonable and the test result was good. The system uses the gas generated by the lighter ignition instead of CO gas when testing the CO concentration, and the CO gas concentration in the room appears to rise substantially when the lighter is ignited, and the test result is good. The system detects the indoor light intensity at night with a value of 30. When the photoresistor module is illuminated with a flashlight, the indoor light intensity value rises significantly to 84. When the light is too dark in the indoor environment, the relay is triggered and a small light is illuminated, and the test effect is ideal. This further verifies the feasibility of the designed hardware indoor environment detection system in practical application.
This design has solved the problem of indoor environmental testing data transmission and display through the network. This result can make good use of modern network technology to realize the intelligent management of family living environment, and further promote the realization of intelligent detection and control of community environment. It has a good social application value.
Secondly, this hardware system design process and methods for detailed production operation instructions, the STM32 microcontroller-based development to solve the actual needs of the real world of hardware design training for electronics students and microcontroller development enthusiasts application design training, advocate and guide students to design and produce such hardware physical system with realistic significance and solve the actual problems of society, so that students are familiar with the various resources of STM32 microcontroller development board, and they also improve students' awareness of solving the practical needs of the real society, realize the theory to practical application, cultivate students' independent innovation ability, well enhance students' hands-on ability, and achieve the purpose of talent training.