Design of Smart Home Control System of Internet of Things Based on STM32

In order to further reduce the cost and power consumption of smart homes, and increase the control methods of smart homes, a smart home monitoring system based on STM32 single-chip microcomputer is designed. The system uses STM32F103C8T6 as the main control chip, which collects the data information of temperature, humidity, light intensity, PM2.5 and methane concentration sent by the sensor, supplemented by a WIFI module, and uses ESP8266WIFI communication technology to transmit the data to the platform. The system test results show that when the room temperature exceeds 26 degrees, the refrigeration relay module works. When the PM2.5 concentration exceeds 150μg/m3, the fan turns on. When the methane concentration in the natural gas exceeds 1600 ppm, the buzzer alarms and the curtain relay works. System users can monitor and display home measurement data through OLED screens, Qt interface, mobile apps, and monitor and display home measurement data. Users can remotely monitor home conditions through the mobile client APP, and realize functions such as home temperature control, environmental detection, and curtain control.


Introduction
With the development of social processes and the increasingly serious global industrialization pollution, people are paying more and more attention to the living environment. Research generally believes that too high or too low temperature is harmful to the residential users [1] , and moderate humidity in the air is a good condition for the residential users. To ensure a high-quality living environment, it is particularly important to design a system that can monitor the home environment in real time and obtain accurate environmental data [2][3][4] . At present, there are two main ways to obtain home environment information: one is real-time monitoring data on the Internet, and the other is home environment detection devices [5] . The former has a large monitoring range and is usually used to monitor data in a certain area, and the data obtained is mostly data from monitoring points, which is for reference only and not universal. Based on the above problems, this article designs a smart home control system based on the STM32 single-chip microcomputer Internet of Things. The user can remotely monitor the home situation through the mobile phone client APP, and realize the functions of home temperature control, environmental detection and curtain control. In addition, the system runs 2 well and has a friendly operating interface, which meets the functional requirements of smart homes and can meet the needs of general household environment monitoring.

System overall design
This smart home system uses the microprocessor STM32F103RCT6 based on the Cortex-M3 core as the main control chip, with 3 ADC controllers, supporting a total of 23 channels, including 21 external and 2 internal signal sources, and its external interface It is also very rich, with multiple serial ports USB to control SPI I2C. Collect data information through temperature and humidity, light, PM2.5, and smoke and gas sensor modules. ESP8266WIFI module communicates with STM32 single-chip microcomputer through USART. Data collected by STM32 single-chip microcomputer is transmitted to cloud server through WIFI module for storage. After the mobile APP is registered and bound, it will be connected to WIFI The module realizes one-key network configuration, and can access the cloud server to receive data information to realize remote control on the mobile phone. When the preset temperature is exceeded, the single-chip microcomputer controls the heating and cooling module through high and low levels after receiving the digital signal to control the temperature in the environment; when the PM2.5 concentration in the environment exceeds 150μg/m³, it is collected After the analog signal is converted by A/D, the single-chip microcomputer outputs the PWM signal through the transistor and drives the fan module to change the PM2.5 concentration in the environment; when the methane concentration in the air exceeds 1600ppm, the analog signal collected by the MQ-2 gas sensor After A/D is converted into a digital signal, the single-chip microcomputer outputs a low-level signal to make the curtain relay work to reduce the methane concentration. The overall structure of the system is shown in Figure 1 below. Fig.1 The overall structure of the system

System hardware structure
The hardware structure of this system is shown in Figure 2. It is based on the STM32F103RCT6 microcontroller, which includes EEPROM memory, SRAM memory, Flash memory, smoke and combustible gas (liquefied gas, methane, alcohol, etc.) sensors, photosensitive sensors, PM2.5 Dust sensor, temperature and humidity sensor, Wi-Fi wireless module, OLED screen, DC motor, relay, buzzer, fan, etc. STM32F407ZGT6 is a 32-bit microcontroller with ARM Cortex-M3 as the core launched by STMicroelectronics, 48KB SRAM, 256KB FLASH, 2 basic timers, 4 general-purpose timers, and 2 advanced timers Adapter, 2 DMA controllers (12 channels in total), 51 general-purpose 3 IO ports and 64 LQFP packages. It contains a high-performance RISC core with a running frequency of 72MHz and is connected to two APB buses externally. STM32F103RCT6 has a 12-bit analog-to-digital converter, timer, PWM timer, standard and advanced communication interfaces, which can satisfy the requirements of the system.

Remote monitoring framework design
Remote monitoring hardware ESP8266-12 module, 5V low-level trigger relay, 220V to 5V switch isolation power module, ASM1117-3.3 [6] , J3 transistor, touch switch, 1K resistance, 10K resistance, breadboard relay, ESP8266, touch switch Use the GPIO port as a button, short press the control relay, and long press to enter the hotspot network distribution mode. The remote monitoring software is created by the cloud computing it create data points, and burn the cloud computing firmware to complete the one-click network configuration. The working framework of remote monitoring is shown in Figure 3 below.

Lower computer design process
When the system is powered on, the STM32 microcontroller is initialized to perform initialization operations on each module of the system, and the data collected by the sensor module is processed by the MCU and displayed on the OLED screen and the mobile phone. When the collected temperature exceeds 26 degrees and the methane concentration exceeds 1600ppm, the refrigeration module relay works to cool down, and the curtain relay works to reduce the methane concentration in the environment. When the temperature and methane concentration drop below the preset value, the refrigeration relay and curtain relay module stop operating. The development flow chart of the lower computer is shown in Figure 4.

Results and discussion
After the system software and hardware are built, the system is tested every 15 minutes in a small space and the system tests are performed multiple times. The measurement data results show that the system error is within a reasonable range. Selected part of the experimental test results are shown in Table 1 During the test, when there was no methane gas at the beginning, the methane concentration in the first test was zero, did not exceed the threshold, the buzzer did not alarm at low level, and the curtain relay did not work and the green LED did not turn on. After simulating methane leakage with a lighter, the second and third time the methane concentration exceeds 1600ppm, the buzzer will trigger an alarm at high level, and the curtain module relay will actuate the green LED light. As time increases, the methane concentration will gradually decrease until it is zero. The temperature of the test result basically remained at about 29 degrees, exceeding the threshold of 26 degrees, the cooling relay module action LED lights, PM2.5 exceeds 150μg/m³, the fan is turned on to change the PM2.5 concentration in the environment to achieve the effect of purifying the air. In general, the system error designed in this paper meets the requirements and can realize the control of the smart home system. The measurement results are shown in Figure 5 below.

Conclusions
The smart home control system solution designed in this paper realizes the remote monitoring of the living environment and home equipment, thus getting rid of tedious operations, creating a convenient living environment, and greatly reducing costs and power consumption. After testing, the monitoring system is stable and reliable, the detection is accurate, and it is easy to transplant and expand. In addition, on the basis of this system design, a face recognition access control function based on