Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 5, No. 3, 2023 14 Design and Implementation of A Simple Pot Watering Control System Cheng Pan1, Geng Hua2, Xiaozhen Liu3, * 1School of Information and Electrical Engineering, Hebei University of Engineering, Handan 056002, China 2School of Information and Electrical Engineering, Hebei University of Engineering, Handan 056002, China 3Handan Polytechnic College, Handan 056002, Hebei, China * Corresponding author Abstract: People who like to care for plants need to take care of plants in addition to the work pressure, which consumes people's time and energy. To solve this problem, an intelligent pouring system based on STM32 and WiFi module ESP8266 was designed. The system took STM32F103 development board as the main control core, combined with ESP8266, soil moisture sensor, temperature and humidity sensor DHT11, photosensitive resistance and other sensors to carry out data transmission to realize temperature and humidity monitoring of flowers. The system can carry out local control through the terminal, realize manual mode control based on MQTT platform and Java language, and set alarm threshold of each parameter. The results show that the system can be applied to different types of plants, which provides convenience for people to conserve plants. Keywords: STM32F103, Long-range Control, Intelligent Flower Watering, Java. 1. Introduction Due to the rapid development of modern society, people's care of flowers is not in place, resulting in the decline of flowers. Therefore, it is necessary to develop intelligent and automatic flower cultivation system. In order to solve the above problems, there are automatic watering systems at home and abroad that use sensor technology to collect plant environmental information and set the soil moisture threshold and watering time in advance, which can automatically water or fill light, but have not been connected to the remote end. To some extent, it is novel and practical to know the state of their own plants, which brings great convenience to people's life and work. Further research on smart POTS could better manage flower plants for people and reduce the amount of energy spent on flower cultivation. In view of the lack of existing research, this paper implemented an intelligent watering system, which can control the pot by mobile phone, alarm when the soil moisture and light are lower than the threshold, and humidify and fill the light. When the air temperature and humidity is lower than the set threshold, the alarm will also be generated. Both the OLED screen and APP can display real-time environmental parameters, and the thresholds of air temperature and humidity, light intensity and soil moisture can be manually adjusted on the APP, so that the intelligent watering system can be used for flower cultivation with different habits [1]. 2. Methodology 2.1. Design of intelligent watering system This paper designs an intelligent watering system based on STM32 and WiFi, which consists of four parts, including control part, APP part, sensor part and reaction part, as shown in Figure 1 [2]. The control part is the main control chip, which is connected with the WiFi module in the sensor part, the reaction part and the APP part. The sensor includes soil moisture sensor, temperature and humidity sensor, and photoresistor sensor, which are used to detect soil moisture, air temperature and humidity, and light intensity respectively. The APP part is the WiFi module connected with the APP through the MQTT platform.The system uses STM32F103 microcontroller as the main control part, including ESP8266 WiFi module, light, soil moisture, air temperature and humidity sensor. The ESP8266 WiFi module is used for wireless communication, and the photosensitive resistance sensor detects the light intensity around the potted plants. Soil moisture sensor is used to measure soil moisture; DHT11 Temperature and Humidity sensor Used to measure the ambient temperature and humidity. The work flow of the system is as follows: first, the photosensitive resistance sensor, soil moisture sensor and air temperature and humidity sensor collect data, and then display each value on the OLED screen through the single chip microcomputer. When the indicators reach a certain threshold, the alarm system will be triggered, and the system will automatically take corresponding measures, such as turning on the water pump, filling light, etc. The mobile phone opens the hot spot and communicates with the mobile APP through the ESP8266WiFi module. The APP can control the system through manual mode and automatic mode [3-4]. 15 Figure 1. System overall block diagram In order to realize the intelligent watering system, the corresponding hardware design and software design should be completed. The hardware part includes soil moisture detection circuit, OLED screen display circuit, ESP8266WIFI module circuit, buzzer alarm circuit, photosensitive resistance sensor circuit, etc. The hardware design work needs to complete the interconnection of all parts of the circuit, and finally realize the complete hardware circuit. The software work includes compiling STM32 MCU with Keil, developing APP with Java language, debugging ESP8266 module with AT instruction. The control part receives the data of each sensor part to realize the information transmission, and transmits it to the sensor part after the judgment; The sensors in the irrigation area are soil moisture, air temperature and humidity, light intensity and other sensors. The sensors collect the data of the environment and soil conditions around the flowerpot, and focus on the control technology and software programming of the watering system. Soil moisture sensor, photoresistor sensor, air temperature and humidity sensor display soil moisture, light intensity, air temperature and humidity on the OLED screen, and decide whether the water pump is on or not and whether the fill light is on or not according to the interrupt service program of the single chip microcomputer. If watering is needed, the single chip microcomputer sends out irrigation signals, and the pump opens for work; If the light intensity needs to be enhanced, the single-chip microcomputer sends out a supplementary light signal, and the supplementary light lamp turns on. The APP can adjust the most suitable light intensity, soil moisture, air temperature and humidity thresholds, display the parameters detected by the sensor, or manually turn on the fill light and water pump to adjust the plants. 2.2. Main control module design STM32F103 has 40 pins, 7 pins are RST, the main function of the pin is to initialize the entire single chip computer program, serial communication for serial transmission. Pin number PB12, PB13, PB14 and PB15 is SPII2, which is connected with the module with SPI interface. The pins of PA4, PA5, PA6 and PA7 are SPI1. PB6, PB7, PB8, PB9 pins are used for PWM output and can be configured with PWM of four ports. Pins PC13, PC14 and PC15 are related to the clock. Pins PC14 and PC15 are connected to crystal oscillator. Pin 1 VB is used as the backup power supply. STM32 microcontroller, crystal oscillator circuit, power circuit, reset circuit composed of STM32 microcontroller minimum system. One end of the crystal oscillator circuit is connected to the PC14 pin, and the other end is connected to the PC15 pin; One end of the power supply and reset circuit is powered by MCU3.3V, and the other end is connected to GND of MCU. Pin 1 of the debugging circuit is connected to PB5, pin 4 is connected to PB6, and the other two ends are connected to VCC and GND respectively [5-6]. 2.3. The design of WiFi module The WiFi module uses the ESP8266 module, which can perform data transmission and control the establishment of WiFi hotspots. The WiFi module is connected to the STM32 MCU in the following ways. No. 1 and No. 5 VCC and GND, which provide voltage for the circuit; No. 8 pin TX for serial communication transmitter, and the single chip directly for data transmission; Pin No. 4 RX is the serial communication receiver, receiving data feedback of the single chip microcomputer in real time. Pin 4 and pin 8 of ESP8266 are 16 serial sending interfaces and serial receiving interfaces corresponding to pins 6 and 7 in STM32 respectively. Through these two interfaces, data is exchanged with STM32 module in real time. 2.4. The design of sensor module Sensors include soil moisture sensor, photoresistor sensor, and DHT11 temperature and humidity sensor. The surface of the soil moisture sensor used in this design is treated by nickel plating, which can enhance the electrical conductivity, but also avoid the problem of easy rust after contact with the soil, thus prolonging the service life. Soil moisture sensor VCC pin connected to STM32 microcontroller 3.3-5V power supply; GND pin The external GND pin is connected. AOUT pin is connected to No. 5 pin of the single chip microcomputer. When connected, both red and blue leds light up, which proves that the soil moisture sensor works properly. Photoresistor sensor: Uses a photoresistor to detect the intensity of light. One end is connected to STM32 microcontroller 5V power supply, and the other end is connected to microcontroller GND. The pins of the DHT11 temperature and humidity sensor are VCC external 3.3V-5V power supply, DATA pins are connected to pin 25 of the I/O port of the STM32F103 microprocessor, NC pins are suspended, and GND pins are grounded [7]. 2.5. The design of alarm module The alarm circuit selects the active buzzer module. When the soil moisture, air temperature and humidity, and light intensity reach the threshold, the alarm will remind the user to repair the pot. One end of the alarm module is connected to MCU3.3V for power supply, one end is connected to MCU GND, and the other end is connected to PB12 pin. Triode input to low level is not switched on, buzzer does not work; At high level, the base and emitter are on, a current passes through, and the buzzer works. 2.6. The design of OLED display module OLED screen is selected as the display in this design. VCC pin of OLED screen is connected to 3.3V power supply of single chip microcomputer, GND is connected to single chip microcomputer GND, SCL is connected to single chip microcomputer PB10 pin, and SDA is connected to single chip microcomputer PB11 pin. 3. System software part 3.1. APP software design Step 1: Download Android Studio and install JDK to configure the environment for your computer. Step 2: Create a project file, follow the default configuration, select a device, select an empty project, select a mobile device, and then enter the project. Step 3: The project architecture of Android studio is mainly composed of two files, the first is the program file (mainactivity.java), the second is the.xml file (activity_main.xml), in which the program file is mainly for writing logical programs, the second file is equivalent to the drawing interface, Can complete the layout of some controls and other actions, and then can complete the creation of logical programs in the programming document, as well as the call to the control. The ID of the control allows two files to be linked together. Write the program file (MainActivity.java), and the main program screenshot is shown in Figure. 2 [8]. Figure 2. Program file Step 4: Write the layout file (MainActivity.xml). The screenshot of the main program is shown in Figure.3. 17 Figure 3. Layout file Step 5: It is not necessary to download the APP to the mobile phone. You can use the emulator to simulate the APP in the software. Figure 4. The APP displays the results on the phone 3.2. System main program design The main program to complete the following functions, soil moisture sensor to measure the moisture content of the soil, if reached a critical point, the pump open; The light intensity detected by the photosensitive sensor is small. If it reaches the threshold, the fill light lamp will be turned on. DHT11 Temperature and Humidity sensor The DHT11 Temperature and humidity sensor measures the temperature and humidity around the basin. If the sensor reaches the threshold, a buzzer alarms. The main flow diagram is shown in Figure 5. 18 Figure 5. Main flow diagram As can be seen from the main flow diagram, the working flow of the system is as follows: the light intensity, air temperature and humidity, and soil moisture are tested at the same time to determine whether the light intensity is lower than the set threshold. If the result is yes, the buzzer will alarm and turn on the fill light lamp to fill light for the pot. If no, the system continues to detect the light intensity. Determine whether the soil moisture is lower than the set critical value. If the result is yes, the buzzer will alarm and the water pump will be turned on for watering and humidification. If no, the system continues to test the soil moisture. Determine whether the air temperature and humidity is lower than the set threshold. If it is, the buzzer will alarm; If no, the system continues to detect the air temperature and humidity. 3.2.1. The subroutine design of ESP8266 WiFi module After the ESP8266WiFi module is powered on, it connects to the current hot spot and establishes TCP connection with the server. Through the initialization of the serial port, the WiFi module receives the signal sent by STM32F103 and is confirmed by the WiFi module ESP8266. The serial port of the single chip microcomputer receives the data sent by the WiFi module. If it is below the set threshold, the terminal will be triggered. If it is not below the threshold, the detection will continue. 3.2.2. DHT11 sensor subroutine design DHT11 in this system is used to detect the temperature and humidity in the air. The working process of the air temperature and humidity sensor is as follows: after the system is powered on, the serial port is initialized, the MCU reads the value detected by the temperature and humidity sensor to obtain the air temperature and humidity and displays it on the OLED screen to judge whether the value detected is lower than the set threshold. If the result is yes, the buzzer will be turned on to alarm. If no, go back to check. 3.2.3. Soil moisture sensor subroutine design Soil moisture sensors measure that soil moisture changes with soil conductivity (soil resistance increases with drought). Measure resistance between the two electrodes of the sensor. When an adjustable threshold is exceeded, the comparator activates the digital output. After the system is powered on, the serial port is initialized, the soil moisture sensor detects it, and displays it on the OLED screen through the analog-to- digital conversion circuit to determine whether the detected data is lower than the set threshold. If yes, start the water pump for humidification. If not, go back and check. 3.2.4. OLED LCD display subroutine design The STM32 uses a variety of OLED modes to choose from, including 8080 mode (13 signal lines), 6800 mode (13 signal lines), SPI mode (four lines), and IIC mode (two lines) (also known as I2C). The four modes are set via the BS1 and BS2 of the module. 3.2.5. Photosensitive sensor subroutine design In terms of detecting the intensity of light, the photosensitive sensor used in this system can convert the light information into a telecommunication signal. The sensitive wavelength is around the visible wavelength, as well as the infrared wavelength and the ultraviolet wavelength. Photoresistor can convert photoresistor information into photosensitive voltage information. After the system is powered on, the serial port is initialized, and the MCU reads the light intensity value and displays it on the OLED screen to judge whether the detected value is lower than the set threshold. If the result is yes, the supplementary light lamp is turned on to fill light. If no, return to check again. 19 3.2.6. Buzzer subroutine design In this design, the buzzer is used to alarm, the system is powered on, the serial port is initialized, the buzzer is waiting to receive the interrupt signal, if received, the buzzer will issue an alarm; Instead, wait. 4. System Test 4.1. System function test In order to better achieve the desired watering and filling light effect, the design has been preliminarily completed after several debugging. 1. Under normal circumstances, the system works as shown in Figure 6 below. 6 7 8 9 10 11 2.The threshold is raised, the detected soil moisture is below the threshold, the buzzer sounds an alarm, and the water pump is activated, as shown in Figure 7. 3.When the light intensity detected by the photosensitive sensor is 1891lx, the threshold set at this time is 2000lx, which is lower than the threshold, so the fill light is turned on, as shown in Figure 8. After the ambient light intensity increases, it is higher than the set threshold, so the supplementary light is extinguished, as shown in Figure 9. 4.When the temperature is lower than the set threshold, manually open the water pump as shown in Figure 10. If the light intensity is lower than the set threshold, turn on the fill light manually, as shown in Figure 11.In addition, when the ambient air temperature and humidity below the set threshold, the buzzer module sends an alarm. After functional testing, it can be concluded that the design can realize the following functions: local photosensitive resistance sensor, soil moisture sensor, temperature and humidity sensor DHT11 can detect various parameters and display them on the OLED screen; remote APP can realize 20 the switch between manual mode and automatic mode. All parameters can be displayed in real time on the APP and the threshold can be set independently. 5. Conclusion Finally realized an intelligent watering system based on STM32 MCU and ESP8266WiFi module. The system uses STM32F103 development board and ESP8266WiFi module as the main control core, combined with soil moisture sensor, temperature and humidity sensor DHT11, photosensitive resistance sensor to complete. It can be controlled locally through the system terminal or remotely by the APP developed based on MQTT platform and Java language. Up to now, the design still has the following defects, when the air temperature and humidity around the plant is detected to be higher than the set value, it cannot take the most appropriate treatment method; When the light intensity is too high, it can be adopted to block the light in the subsequent improvement, which needs to be improved on the system later. References [1] Shi Ge, Zhai Juan, Pan Xiangli. Intelligent Watering System based on single Chip Microcomputer [J]. Journal of Software, 20,41(11):145-147+152. [2] Heng Ting. Design of intelligent control watering system [J]. Agricultural Technology and Equipment,2022(06):38-39+42. [3] Xingcan Liu,Hao Yin and Chen Zang. Design of Intelligent Watering System Based on STM32[J]. Academic Journal of Engineering and Technology Science,2019,2(1). [4] Weicheng Huang,Liang Jin,Juncheng Zhao. Design of Home Infrared Alarm System Based on STM32[J]. Advances in Computer, Signals and Systems,2022,6(6). [5] WANG Xiaoyan. Principle and Hardware Circuit Design of STM32 Single Chip Microcomputer [J]. Southern Agricultural Machinery, 20,51(14):163-164. [6] Liu Canhua, Yang Lian, He Shaojian. Hardware Circuit Design of Massage Chair Control System Based on STM32 [J]. Mechanical and Electrical Engineering Technology, 2023, 52(01): 72-75. [7] Li Zhiwei, Dong Wei, Huang Shuangcheng. Design of Agricultural Greenhouse Temperature and Humidity Monitoring System based on DHT11 [J]. Industrial Instrumentation and Automation, 2021(01):39-43. [8] Hong Huihuang, Pan Shanliang. Intelligent hotel system design based on MQTT [J]. Wireless Communication Technology, 202, 31(02):59-62.