Automated Irrigation System using STM32 and Modbus RTU Protocol

Irrigation is the practice of watering farmland to make it ready for agriculture. It allows to agriculture crops, maintain landscapes in less rainfall areas. Agriculture land in India was about 60.45% in 2016 according to World Bank. Water usage from ground water is about 65% for irrigation. This project is focused on efficient use of ground water without wastage or overflow of water on farmland using moisture sensor connected to microcontroller. STM32 a 32 bit ARM cortex-M3 microcontroller is used which is more efficient compared to other microcontroller. Also Modbus RTU protocol is used to cover wide area of farmland for monitoring. Moisture sensor value is sent to cloud for remote monitoring and analysis of data using GSM Module. This system reduces the risk of low crop yield due to shortage of water. Automated irrigation system can be used for analysis of the different crop water consumption and also nature of the soil. Keywords— Automated Irrigation; Modbus RTU protocol; Moisture sensor; SIM900 GSM module; STM32F103C8 IC; ThingSpeak IOT platform.

INTRODUCTION The automated irrigation system refers to the system with no or minimum of farmer involvement except some urgent need when there is a failure in system and no need of water in some situations. Growing of crop with good yield improves farmer's life and as well as availability of large amount of raw materials for textiles, jute, sugar, tobacco industries. Need for large quantity of food is required to feed large population in India. To meet this requirement quantity and yield of crop is very important. Quantity and yield of corps and soil productivity depend on quantity and quality of water for irrigation. Suitability of water for usage in agriculture is determined by factors such as PH, Salinity, Carbonate and bicarbonates, Toxic anions, Nutrients. Sources of water for irrigation are rainwater, lakes and rivers (surface water). Other sources of water are reuse of municipal wastewater and drainage water which must be tested before using it to irrigation. Automated irrigation system reduces efforts of farmers. Disadvantage of surface irrigation is over flow of water from agriculture land which is not utilized for growth of crops. Using automated irrigation system manual turn on or off the ground water pump is avoided in which farmer can monitor water for more crops without any risk, saving of underground water from unnecessary wastage and avoiding loss of soil structure and nutrients.
II. LITERATURE SURVEY Xin Fang [1] has published the paper in which STM32 is used to control the pressure of water flow to the residential area buildings. Pump set is controlled through variable frequency device or frequency converter. Frequency inverter control the motor speed to which in turn decides water outflow from the pump set and to the buildings. Komal Kumar N[2] proposed the system in which MH Sensor series KY-033 with moisture sensor is used to check amount of water present in the soil and moisture content parameters can be modified according to the crop in which farmer grow in his land. Aurdino Nano is used as a controller. Indranil Banerjee [3] developed a project in which Si7021 moisture sensor and PH sensor data is uploaded to cloud or server. There are three main blocks such as nodes, hub and server or cloud. Nodes has Aurdino Uno and it is connected to Pump, moisture sensor and PH sensor for detecting moisture or water content level in the soil and soil fertility. Wenzhu[4] You proposed the system with embedded Modbus gateway which has ARM5708 processor. Project has STM32F103VC controller which is connected to DHT11 digital temperature and humidity sensor, MQ-2 and MQ-7 gas sensors used for gas detection in buildings. Shivang Raj [5] proposed a project with different farmland in city which is used for government to visualize the requirement of water for different types of crops. By this analysis supply demand problem can be solved. This project has several sensor networks connected to the local IOT network. Dataset collected from each crops and climatic conditions. For this dataset K-Nearest Neighbors (KNN) algorithm is applied to find out the top three crops which is best suited for the particular farmland.

A. Block diagram
The proposed system as shown in Figure 1 consists of water level sensor, 16*2 Display, GSM Module, DC motor, STM32 board, MAX485 Module, Aurdino Uno board, solenoid value and moisture sensor as shown in the figure. In this project STM32 and Aurdino boards are used to control the flow of water to the crop based on the condition of moisture sensor value. Basically STM32 is considered as a master device that receives moisture sensor data from three slaves which are Aurdino Uno boards connected with moisture sensor and solenoid valve placed in different locations. Solenoid value is used to control the flow of water. If solenoid valve is ON, water flows to the crop. If solenoid valve is in OFF condition, water flow will be stopped representing that the water in crop is sufficient for its growth. This ON and OFF signal to valve is given by the Aurdino board according to the moisture sensor value which is in As shown in Figure 2 ,Initialize GPIO pins for indicating Modbus data communication, initialize UART for receiving Modbus query and sending the response/ reply for corresponding request from STM32. Check volumetric moisture content in the area of land where slaves are placed. If moisture level is low, pour water to particular area of land through solenoid valve. If solenoid valve is energized, valve will be opened and water flow will start. If solenoid valve is de-energized, valve will be closed and water flow stops. If moisture level is high then stop flow of water. Receive query message from master and send reply using Modbus protocol. Modbus protocol initially checks for the particular slave specified in the query message format. Also query message has function code, no. of data to be accessed, address, and total query message checksum. Reply message has function code, no. of data sent, Moisture sensor data and checksum.

IV. SYSTEM IMPLEMENTATION A. Modbus protocol
Master sends a request with function code and data request and Slave responds with the same function code and corresponding data response with certain action performed based on request. Master receives a response. If there is an error detected in request from Master. Slave sends an exception code along with its function code to Master. Table I represents Function Codes with its definition.  MAX485 on-board chip as shown in Figure 3, it is a slew rate limited transceiver used for RS-485 communication. It consumes low power for its operation. It works at 300µA current rate and +5v power supply. It supports half-duplex communication to apply the function of converting TTL level into RS-485 level. It can send data at maximum transmission rate of 2.5Mbps. This module draws supply current between 120µA and 500µA. Driver outputs can be put at a high impedance state through the thermal shutdown circuit with limited short circuit current. Receiver input of Max485 Module has a fail-safe feature which guarantees logic high output if the input is open circuit.

C. Moisture Sensor Module
Amount of water present in soil can be identified by moisture sensor YL-69 or HL-69 by connecting it to Aurdino. Moisture sensor has two hardware components: one is the electric board and other is the probe with two copper pads that detects water content by calculating conductivity between them. Electric board has two analog (A0) and digital (D0) output signal pins. LEDs for indicating power input to   Figure 5. It has 32-bit CPU and ARM Cortex M3 architecture. KEIL µVision5 IDE is used to program STM32 board. These boards are cheap and the hardware is open source. STM32F103C8T6 is the microcontroller present on top of it. The board has 8 MHz crystal for CPU clock and 32 KHz for RTC clock. Microcontroller can operate in sleep mode which is suitable for battery related applications. Red color LED is used for power indication and Green color LED is connected to GPIO pin PC13. Aurdino board is shown in Figure 6. It has fourteen digital input or output pins and PWM signals can be produced by six digital input or output pins among them. Also there are six analog input pins which could be configured as digital input or output pins. The pins discussed before are on top of the board with 2.54mm female header. It is open source hardware with microcontroller used especially for project purpose licensed under GNU General Public License (GPL). USB serial communication interface used for loading project program from personal computer. Fig. 7. Solenoid Valve Solenoid valve is shown in Figure 7. SKU (stock keeping unit is unique numerical identifying number) of this valve is 2W-400-50-12V. Its position is normally closed, port size is 1-1/12" Female NPT (National Pipe Thread), it operates with 12V DC, Body material is Brass, components are of stainless steel, it can work in temperature range of 10 o C to 120 o C, flow rate is of 29 CV (valve coefficient representing capability of valve to flow a fluid), it consumes power of 40 Watts and 3.25 Ampere of current, coils inside valves are connected to lead wires, its response time is less than one second, its weight is of 4 lbs (pound) 14 oz (ounceone sixteenth of pound), height is of 6 inch and length is 4.33 inch port to port, width is 3.35 inches.

F. Solenoid valve
G. Hercules SETUP Utility Hercules SETUP utility is shown in Figure 8. It is a serial port terminal i.e. RS-232 or RS-485 terminal, UDP/IP terminal and TCP/IP terminal. It is freeware and includes many functions in one utility. It can be installed in computer with windows 7, 8 and 10. Serial port terminal works with the virtual serial ports such as COM3. UDP mode in this utility finds devices on the network and can function only on a local segment of a network. In serial mode communication port is selected with default baud rate 9600, data size of 8 bits. Moisture data is sent through GSM using AT commands. It is done by STM32 microcontroller.
V. RESULTS AND DISCUSSION Aurdino Uno (slave) send moisture sensor data to STM32 using Modbus protocol and it is displayed on LCD. In regular interval of time other moisture values are also displayed. The values displayed represent the digital value which is converted from 0-1023 range to 0-255 to reduce complexity of sending large amount of data. Moisture content in the soil depends on the intensity of sunlight in a day, type of soil and plant. In this project for trial, red soil is taken in a pot and garden graphs are shown in Figure 9 and Figure 10. The same can be implemented inside poly house for growing different crops. Moisture sensor valves are noticed in hourly basis using LCD display are tabulated and plotted as shown in Table II  VI. CONCLUSION Automated irrigation system is implemented using STM32 microcontroller as master device and Aurdino as a slave device. Communication is established between master and slave using industry level protocol i.e., Modbus RTU protocol which is based on request and reply protocol. Irrigation is performed according to water requirement. Moisture sensor data is uploaded to ThingSpeak website using GSM Module for remote monitoring from farmer as well as company service provider. This project allows conservation of water with reduction of farmer intervention for irrigation. Also message regarding fault in system is sent to service provider to get quick service.