Design and development of software for intelligent monitoring and control system of modern agricultural greenhouse

. In recent years, with the improvement of large-scale planting in rural areas, greenhouse cultivation technology has been developed rapidly. Intelligent monitoring and control of modern agricultural greenhouse is a hot topic at present. Based on the design requirements of modern greenhouse and the architecture of software design, this paper designs and develops the main program, data acquisition subroutine, alarm subroutine, control keystroke subroutine and display driver subroutine of the system based on the STM32F103ZET6 main control chip, and realizes the design of intelligent monitoring and control system of greenhouse, This study is of great significance for the establishment of scientific ecological environment of plants and the realization of high quality and high yield of crops.


Introduction
With the rapid development of science and technology, modern agriculture can form a scientific environment for the growth of crops through artificial intelligence, so as to change the growth cycle of crops and achieve high quality, high yield and low consumption of crops. In the process of technological innovation and development, greenhouse technology is an embodiment of agricultural modernization. Its characteristic is to establish the scientific ecological environment of crop growth by artificial method, to eliminate the influence of seasonal change on crop growth, and to get rid of the dependence of crops on natural conditions, so it will be an important means for farmers to increase production and income.
Intelligent monitoring and control system of modern agricultural greenhouse is composed of hardware circuit and software programming. Based on the design of system hardware circuit, this study mainly discusses the software design and development of greenhouse system, so as to realize environmental monitoring and control within the greenhouse.

Design requirements of the intelligent monitoring and control system
(1) Real-time collection of temperature and humidity parameters in greenhouse and processing and display of collected data; (2) According to the requirements of plant growth environment conditions, the temperature and humidity values in the greenhouse are set by independent keys. When the greenhouse environment exceeds the set threshold parameters, the system will alarm and start the control system at the same time. Adjust the temperature and humidity, light intensity and CO2 concentration in the greenhouse to the specified parameter values; (3) The intelligent monitoring and control system of greenhouse should have high sensitivity, reliability and anti-interference ability; (4) Technical indicators require: Temperature range: -10~70℃, temperature accuracy: ±0.4℃, humidity range: 0~90%, humidity accuracy: ±3% RH. The system adopts the design scheme is shown in figure  1. Based on the requirement of design, the system uses STM32F103ZET6 as the main control chip. In Figure 1, STM32F103ZET6 is adopted as the main control chip, DS18B20 as the temperature acquisition sensor, BH1750 as the CO2 concentration detection sensor, DH11 as the humidity detection sensor and SGP30 as the light intensity detection sensor. After the environmental parameters detected by the sensor are fed back to the STM32F103ZET6 microcontroller for data processing, the environmental information of the greenhouse will be displayed on the ST7735 TFT LCD display in real time. At the same time, users can set the environmental parameters required in the greenhouse through the button circuit according to the growth conditions of plants [1].

Architecture of Software Design
The software design and development of intelligent monitoring and control system of greenhouse is carried out after the hardware circuit design of the system is completed. the whole software design is modularized by C language programming [2]. The specific design contents are: the design of the main program of the system, the design of the data acquisition subroutine, the design of the relay control subroutine, the design of the alarm subroutine, the design of the control key subroutine and the display driver subroutine, etc. The main program is the main body of the whole system program design, the purpose of which is to connect the independent subroutine modules through the programming method to meet the system design requirements and functions, Its specific design architecture is shown in Figure 2.

Design of System Main Program
The main program is the main part of the whole system program design, the system of the main program design are implemented based on the hardware circuit design is completed, the software design, first plan the STM32F103ZET6 single-chip microcomputer pin, then use the C language to design the whole system program, here take temperature detection as an example, the main control program design process is as follows: (1) initialization of the system; (2) read the temperature value set by the system; (3) the actual temperature value detected by the temperature sensor feedback to the STM32F103ZET6 Single chip microcomputer for data processing; (4) Automatically adjust the ecological conditions of plants in the greenhouse by relay; (5) display the actual temperature value of the system by ST7735TFT LCD, the specific flow is shown in Figure 3.

Design of Data Acquisition Subprogram
The data acquisition of the system is composed of humidity sensor (DHT11), temperature sensor (DS18B20), light sensor (SGP30) and CO2 concentration detection sensor (BH1750FVI) [3]. The sensor communicates with the main control chip (STM32F103ZET6) through the IIC. Under the communication protocol of the system, when the STM32F103ZET6 sends out the request signal through the I/O port, the sensor will collect the environmental data, convert the data and send the data. The program design flow is shown in Figure 4.  When the sensor collects the signal, it often encounters some interference pulses, which will affect the data acquisition. Therefore, the median average filtering algorithm is usually used to solve this problem in programming. The process is as follows: (1) comparing N collected data and removing the largest and smallest data; (2) calculating the arithmetic average of N-2 data. This method can not only filter the pulse interference, but also filter the random electromagnetic pulse with small amplitude, thus reducing the false alarm function of the system. The specific filter subroutine design flow is shown in Figure 5.

Figure 6. Flow chart of alarm subroutine
Here, take the CO2 concentration acquisition as an example to discuss the design process of the alarm subroutine. When the concentration of the CO2 exceeds the set threshold parameter, the alarm system starts to work. STM32F103ZET6 the main control chip will send out the acousto-optic alarm drive signal, drive the buzzer and LED lights for acousto-optic alarm. During the programming, in order to prevent the false alarm of the system, the sensor needs to detect the collected CO2 concentration quickly before the system can delay the alarm. Its subroutine design process is shown in Figure  6.

Design of Key Test Subprogram
When the system initializes the port, ST7735TFT LCD display, DS18B20 sensor and BH1750FVI sensor, the program enters the main loop state. When entering the main cycle, the system first detects the key module. When the STM32F103ZET6 main control chip continuously detects that the I/O port is low level, it indicates that the key is connected, so the key triggered is determined STM32F103ZET6 the main control chip, and the corresponding control function is executed. The flow chart of the detection module is shown in Figure 7.

Design of LCD Subprogram
The system adopts ST7735TFT LCD as the environment state display module. In the design process, the ST7735TFT LCD pin is directly connected with the STM32F103ZET6 main control chip. When the system initialization is completed, the LCD module can work. When using ST7735 TFT LCD, when the "busy mark" of ST7735 TFT LCD module is low, the module can display the status according to the previous Settings.
The working process is as follows: (1) the main control chip executes the initialization program of ST7735 TFT LCD; (2) the main control chip executes the delay waiting program, waiting for the data collected by DS18B20 and BH1750FVI sensors; (3) the main control chip sends data to ST7735 TFT LCD; (4) the ST7735 TFT LCD reads the "write address" and displays the contents on the ST7735 TFT LCD according to the "write address". Its design process is shown in Figure 8.

Design of Relay Control Subprogram
Relay is a kind of "automatic switch" that uses small current to control large current operation. In the circuit system, it plays a role of automatic regulation, safety protection, circuit conversion and so on. In the design process of this system, four relay control circuits are used to control the temperature, humidity, CO2 concentration and light intensity in the greenhouse to ensure the scientific ecological environment of plant growth in the greenhouse. Its programming flow is shown in Figure 9.

Design of System Hardware
The intelligent monitoring and control system of modern agricultural greenhouse is composed of hardware circuit and software programming. For the hardware circuit design of the system, the system uses the STM32F103ZET6 as the main control chip, the ST7735TFT LCD as the environment condition monitoring display, the buzzer and the LED as the acousto-optic alarm, the S18B20 as the digital temperature sensor, the DHT11 as the humidity sensor, the key circuit as the CO2 detection sensor, and the key circuit as the function setting. With the support of the software, The whole function of the system is realized [4]. The process of system assembly and debugging is as follows: (1) cascade the designed hardware circuit on the PCB board and download the designed system software to STM32F103ZET6 [5]; (2) Software debugging, hardware debugging and joint debugging of hardware and software of the system. After debugging, the functions of the system are as follows: (1) after power on, when the sensor detects that the environmental parameters in the greenhouse exceed the set threshold, the relay and fan of the system will start to work, and the buzzer and LED light will give audible and optical alarm; (2) the system collects the temperature and humidity, light intensity and CO2 concentration of the greenhouse environment, and displays them through ST7735 TFT LCD in real time. The experiment proves that the system realizes all the functions given by the design requirements [6], and its real object is shown in Figure  10.

Conclusion
Through the above discussion, it can be seen that based on the design requirements of intelligent monitoring and control system of modern agricultural greenhouse, based on the hardware circuit design, the system proposes the software design framework, and uses C language to design the main program, filter subprogram, alarm subprogram, relay driver subprogram, key control subprogram and display. Through the assembly and debugging of the system, it shows that the system realizes the functions of real-time monitoring, display, control and sound and light alarm of the environmental status of the greenhouse. Because the system changes the growth cycle and ecological environment of crops by artificial methods, it is of great significance to realize the technical innovation of high quality, high yield and low consumption of agriculture.