Remote control irrigation system for tea gardens based on STM32
Authors:XU Weihai, ZHANG Wu, ZUO Guanpeng, ZHANG Chao, YAO Yuqing, FENG Jinlei, MIAO Benben (College of Information and Computer, Anhui Agricultural University, Hefei, Anhui 230036)
Abstract
To accurately detect the water needs of tea trees during their growth and to automatically control precise irrigation in tea gardens, a system based on the Cortex-M3 core was designed. This system uses both SD storage cards and servers for data storage, and GPRS for data transmission, allowing for the automatic monitoring and regulation of the moisture required by tea trees at different growth stages. Experimental results show that the system is reliable, easy to operate, has strong scalability, and good market application prospects.
Keywords
STM32; GPRS; Humidity; Tea Trees
1 Introduction
Under natural conditions, the moisture required for the growth of tea trees is mainly provided by natural rainfall [1]. In most tea-growing areas of China, the annual rainfall is about 1200 ~ 1800 mm. Although the total rainfall generally meets the moisture needs of tea trees during their growth stages, the monthly distribution of rainfall is uneven, often leading to insufficient moisture for tea trees. Moreover, many tea-growing areas experience droughts in summer and autumn. To mitigate the impact of these phenomena on tea tree growth, tea quality, and yield, it is necessary to develop precise automatic irrigation control schemes based on the water requirements of tea trees at different growth stages [2].
Precise irrigation is an effective means of supplementary irrigation in tea gardens. The system will irrigate in a timely, adequate, and targeted manner according to environmental conditions and crop growth, achieving goals such as saving irrigation water and increasing tea garden yield [3-4].
In recent years, research on precise irrigation has delved into comprehensive irrigation control that combines water evaporation, environmental meteorological factors, etc. DigitalSun has developed an automated sensor network system [5], and ZHANG Wei et al. [6] designed a precise irrigation system based on ZigBee wireless sensor networks and fuzzy control methods. However, due to limitations in environment, cost, and other conditions, the application range is limited to a few farmland systems, making large-scale promotion difficult [7]. Most systems are focused on controlling electromagnetic valves and pipelines, making them hard to universally apply to current farmland irrigation systems.
This paper designs a remote irrigation monitoring system for tea gardens, deploying several soil moisture sensors at different soil depths. By analyzing the information collected from the sensor network, the upper computer can control the opening and stopping of multiple electromagnetic valves, detect faults, and perform functions such as data collection, storage, and uploading.
2 Overall System Design
This system uses the STM32F103ZET6 as the main controller, and the overall system can be divided into core control module, data acquisition module, data storage module, data transmission module, execution device module, and human-computer interaction module. The overall layout of the system is shown in Figure 1.
The data acquisition module collects soil moisture information, and the collected information is transmitted to the core control module via the RS485 interface, and displayed in real-time on the LCD touch screen [8]. The median filtering method is used to process the information, and the processed information is stored in the SD storage card. The core control module compares the soil moisture against pre-set ranges to determine whether it is within the normal moisture range, thereby issuing different control commands to regulate soil moisture. Users can also control the electromagnetic valves through the capacitive touch screen according to their needs to ensure the tea trees maintain good growth conditions.
Additionally, the core control module can wirelessly transmit data to the upper computer via the GPRS network, allowing users to monitor changes in soil moisture in real-time from the upper computer and issue corresponding commands for remote intelligent control of soil moisture.
2.1 Core Control Module
The core control part uses the STM32F103ZET6 microprocessor based on the Cortex-M3 core, which has 64 kb SRAM, 512 kb FLASH, and several peripherals, generally meeting the design requirements. Control functions are implemented through the GPIO ports on the processor. The core control part determines whether the soil moisture is within the pre-set normal range by monitoring the high and low levels on the GPIO interface of the STM32F103ZET6, and uses this to control the corresponding electromagnetic valves, thus controlling the entire irrigation system.
2.2 Data Acquisition Module
The RS485 interface is designed using USART2 serial port as the interface between the core controller and the sensors. The irrigation system mainly executes actions based on the feedback information from the sensors, so the overall performance of the sensors directly affects the stability and accuracy of the entire irrigation system [9]. This paper uses the RS-WS-N01-TR soil moisture temperature and humidity sensor, which has a moisture detection range of 0% ~ 100%, with a detection accuracy of ±3%, operating environment of -40 ~ 80 ℃, powered by 5 ~ 30 V DC, with a power consumption of approximately 0.4 W, and outputs RS485 signals. The sensor features high accuracy, fast response, stable output, and is less affected by soil salinity, meeting the design requirements.
Regarding sensor layout, three sensors are set at soil depths of 20, 40, and 60 cm to obtain moisture values at different depths in the tea garden. A schematic diagram of the sensors is shown in Figure 2.
2.3 Data Storage Module
The data storage part consists of an SD storage card and a server. The system connects to the SD storage card via the SDIO interface to achieve real-time storage of soil moisture data. Due to the limited storage space of the SD card, users can adjust the time interval for clearing the SD card through the capacitive touch screen. Additionally, data will be transmitted to the server for storage in the server’s database.
2.4 Data Transmission Module
Field meteorological conditions are complex, and the distance between the sensors and the control terminal is relatively far, so an effective and long-distance wired transmission protocol is required between them. This paper uses the RS-485 protocol and CRC for verification. The distance from the control terminal to the server is even longer, requiring a method that provides stable internet connectivity; this paper uses GPRS communication, with the communication protocol adopting the Mobus-RTU format [10]. GPRS networks have wide coverage and stable transmission, fully meeting the design requirements. The GPRS module used in this design is the USR-G780 V2 module from Youren Internet of Things Company. This is a 4G DTU module compatible with 485/232 for wireless transmission. The GPRS module is simple to use, provides stable transmission, and meets the design needs.
This paper sets the GPRS working mode through AT commands to network transparent transmission mode. In this mode, STM32F103ZET6 sends data to the specified server through the serial port. The device can also receive data from the server and forward the information to the STM32 serial port. Communication between GPRS and the server uses a long socket connection. STM32F103ZET6 transmits messages received from the sensors to the GPRS module, which packages the data and transmits it to the base station via the antenna. The base station sends the message to the specified server via TCP, where the server runs a socket server program to unpack the received data [6,11]. The unpacked data is saved to MySQL using JDBC. A physical diagram of the GPRS module is shown in Figure 3.
2.5 Execution Device Module
This module mainly consists of electromagnetic valves, relays, water pumps, and nutrient tanks, with the main function of supplementing moisture during the growth of tea trees. The driving circuit principle of the electromagnetic valve is shown in Figure 4, where pin 2 of J1 connects to pin PA4 of STM32, and J2 connects to the electromagnetic valve.
When the soil moisture value collected by the sensors is processed and found to be below the set range, the PA4 interface of the STM32 continuously outputs a low level, causing the relay to close, which leads to the phototransistor’s brightness increasing with the input current. The output current of the phototransistor increases, turning on the transistor. When the transistor is turned on, the phototransistor lights up, and the electromagnetic valve switch opens. When the soil moisture value exceeds the set range, the electromagnetic valve closes.
2.6 Human-Computer Interaction Module
The human-computer interaction module is the most important part of the system, with functions such as data analysis, data storage query, and system settings. The data collected by the system will be displayed in real-time on the LCD capacitive touch screen and stored on the SD card.
The system has two control modes: automatic and manual. In automatic mode, the system collects soil moisture information at regular intervals. To prevent misoperation, the system removes sudden sensor values. The method used in this system is to compare the difference between the collected data and the previous data to see if it is less than the system’s set 3%. If it is less than 3%, it is considered correct data, and the electromagnetic valve is controlled to open or close; if greater than 3%, the system will use the last data to control the electromagnetic valve. In manual mode, users can set the normal range of soil moisture, data collection, and storage sending intervals on the capacitive touch screen, and can also directly operate the system and electromagnetic valve through the control module [12]. The control system structure block diagram is shown in Figure 5.
3 Software Design of the System
The software design of this system mainly includes the software design of the lower computer control terminal and the upper computer software design.
3.1 Lower Computer Control Terminal Software Design
The lower computer software is developed using C language in the Keil uVision5 IDE integrated development environment, and its main flow is shown in Figure 6. After the system works stably, it begins to analyze the data obtained from the data acquisition part and determines whether the soil moisture content is within the normal range set by the user. When the soil moisture is below the lower limit of the normal range, irrigation begins, and when it exceeds the upper limit, irrigation stops. If the system cannot determine whether to open or close the electromagnetic valve based on moisture levels, it will transmit fault information to the upper computer and the user’s mobile phone via GPRS, ensuring real-time monitoring and resolution of faults.
3.2 Upper Computer Software Design
The upper computer software is developed using Netbeans 8.0, with a simple and easy-to-operate interface that facilitates good human-computer interaction. The upper computer software consists of setting modules, data modules, control modules, and transmission modules, allowing real-time data display and query, and can transmit data to the manager’s mobile phone or server. The structural block diagram is shown in Figure 7. The 4G DTU USR-G780 module used in the data transmission part can transmit data to the server for storage in real-time.
Through the upper computer software, users can view the moisture values of the soil at different depths at any time and remotely control the opening and closing of the electromagnetic valves. The upper computer software setting interface is shown in Figure 8. The setting interface is divided into two parts: IP/port number and soil temperature and humidity sensor. The IP/port number interface sets the public IP of the database and specifies the port number. After clicking connect, the software initializes and automatically configures the GPRS baud rate, IP address, and port parameters. Additionally, on this page, users can select to open or close different electromagnetic valves, changing the moisture content of the soil in real-time. The soil temperature and humidity interface displays the readings of sensors at different depths in the same location. Furthermore, the opening and closing of the electromagnetic valves and the uploading of data are usually completed automatically by the software. To meet user needs at different stages, users can manually control the opening and closing of the electromagnetic valves or add data to the database through the upper computer operation interface.
4 System Test Results
The test results of the system are shown in Table 1, with the test site being the Huangshan tea garden, and the time of testing in mid-September 2019, on a clear day with no rain. The system began its first irrigation at 14:00, which ended at 16:00.
Analysis of the system data shows that when the soil moisture is below the set lower limit, the electromagnetic valve activates. The upper soil moisture changes most significantly, while the middle layer remains within a controllable range, and the lower layer shows minimal change. The moisture variation trend is shown in Figure 9, with the red, blue, and yellow curves corresponding to the upper (Top), middle (Middle), and lower (Low) soil moisture changes, respectively.
From the moisture variation trend, it can be seen that the upper soil evaporates significantly faster than the middle and lower layers. Due to the distance between the electromagnetic valve outlet and the sensor, the collected data has a certain delay. The moisture variation trend indicates that the system has high stability, ensuring the water required for plant growth, effectively preventing over-irrigation, and achieving remote control.
5 Conclusion
This design developed an automatic irrigation control system for tea gardens based on STM32F103ZET6, which can achieve real-time monitoring and regulation of soil moisture in tea gardens, and communicate with the upper computer and mobile phones through GPRS technology, thus enabling remote control of the experimental field irrigation system. Experimental results show that the soil moisture in the upper, middle, and lower layers remains within the normal range set by the system, with good stability and high accuracy, meeting the water requirements of tea trees at different growth stages. At the same time, the system is easy to operate, highly scalable, and has good market application prospects.
References omitted
Funding Project:National Natural Science Foundation of China (31771679); Key Research and Development Project of Anhui Province in 2018 (1804a07020108);Open Fund Project of Key Laboratory of Internet of Things Technology Integration and Application, Ministry of Agriculture in 2016 (2016KL05); Key Research and Development Project of Anhui Province in 2019 (201904a06020056)
Source of Literature:XU Weihai, ZHANG Wu, ZUO Guanpeng, et al. Remote Control Irrigation System for Tea Gardens Based on STM32[J]. Journal of Jianghan University (Natural Science Edition), 2020, 48(1): 73-80.
DOI:10.16389/j.cnki.cn42-1737/n.2020.01.010