Smart Farm Irrigation: Model Predictive Control for Economic Optimal Irrigation in Agriculture

: The growth of the global population, together with climate change and water scarcity, has made the shift towards efﬁcient and sustainable agriculture increasingly important. Undoubtedly, the recent development of low-cost IoT-based sensors and actuators offers great opportunities in this direction since these devices can be easily deployed to implement advanced monitoring and irrigation control techniques at a farm scale, saving energy and water and decreasing costs. This paper proposes an economic and periodic predictive controller taking advantage of the irrigation periodicity. The goal of the controller is to ﬁnd an irrigation technique that optimizes water and energy consumption while ensuring adequate levels of soil moisture for crops, achieving the maximum crop yield. For this purpose, the developed predictive controller makes use of soil moisture data at different depths, and it formulates a constrained optimization problem that considers energy and water costs, crop transpiration, and an accurate dynamical nonlinear model of the water dynamics in the soil, reﬂecting the reality. This controller strategy is compared with a classical irrigation strategy adopted by a human expert in a speciﬁc case study, demonstrating that it is possible to obtain signiﬁcant reductions in water and energy consumption without compromising crop yields. This work has been an initial step towards implementing automatic irrigation based on multivariable inputs obtained from IoT-based devices. The presented predictive controller has high potential to improve not only water use efﬁciency but also energy costs, without reducing crop yields. Further studies will reveal further details of their beneﬁts for the economic optimization of irrigation scheduling. and P.M.; methodology, M.P. and G.C.; M.P.; M.P. G.C.; analysis, D.L.; investigation, writing—original and


Introduction
Globally, agriculture is the largest consumer of water, accounting for approximately 70% of total water consumption, up to 80% in some areas [1]. Deficient water management is a huge concern, not only due to the depletion of the vital resource but also because over-irrigation results in the higher use of energy, loss of competitiveness, a reduction in crop productivity, and pollution of aquifers by fertilizers [2]. Consequently, policymakers in Europe are creating strategies to increase the sustainability of food production along with a complete value change, stressing the need for efficient management of water resources (see, for instance, the Farm to Fork Strategy [3] of the European Green Deal [4]).
Even in countries with a high degree of irrigation modernization, irrigation scheduling is based on the experience of farmers and/or technical advisors [5]. The variety of factors (weather, soil, crop, irrigation system, etc.) to take into account requires farmers' dedication, perseverance, and expertise in implementing an optimized irrigation strategy [6]. In this context, the paradigm of precision sustainable irrigation now seems inexorably linked to digital tools and irrigation automation in order to alleviate the time and expertise requirements for farmers.
Recent advances in the Internet of Things (IoT) are based on the farm scale to increase crop productivity and water use efficiency while lowering energy costs and reducing the environmental footprint. The better performance of automated irrigation scheduling may be attributed to its faster response to changes in soil-plant-weather conditions, as well as its ability to self-tune the irrigation requirements according to the precise conditions of each plot. In addition, some studies concluded that no single sensor on its own will indicate the optimal amount of water applied, while mathematical methods, such as the control model, could help to identify and implement optimal irrigation management [7].
Automatized irrigation scheduling, based on the FAO's water balance model and/or moisture sensors, has received significant research attention in the last few decades [8]. The approach of the FAO's soil water balance is the most common method for calculating irrigation requirements, where the water inputs in the soil-plant system are compared with the outputs [9].
Based on science-driven techniques, simple and elaborated approaches have been used for optimizing irrigation through automatic irrigation controllers [6]. One of the simplest approaches is to set in the irrigation automata a conservative general irrigation program, an automated system that switches on/off the irrigation system whenever the soil moisture is below/above predetermined thresholds [10]. Another simple approach used in automated irrigation involves soil moisture sensors or tensiometers centered on initiating/terminating the irrigation when the measurements provided by the sensors rise above or fall below pre-established thresholds [11]. A more elaborate approach is to determine irrigation doses via the water balance, but using feedback from plant or soil sensors [8]. This combination of water balance and sensors demonstrates the ability to calculate irrigation doses via the water balance with a site-specific adaptive response to sensors [6].
However, the optimization of the energy used in irrigation has not been included in this type of irrigation automation approach, despite the importance of this aspect. Energy consumption in pressurized irrigation systems has been shown to have increased dramatically in recent years in countries such as Spain, which may lead to the highest production costs for farmers [12]. Refs. [13,14] reported the energy costs in Spain in approximately 40% of total water costs on average, reaching peaks of 65%. Under this scenario of water scarcity and an increase in energy demand, it is, therefore, necessary to include energy costs when implementing optimal irrigation scheduling.
Different types of automatic control algorithms have been applied to improve irrigation management. Ref. [8] proposed a very simple tuning mechanism to increase a coefficient in the water balance model by a fixed amount when the crop water status is interpreted as too low, and vice versa. Proportional integrative derivative (PID) control is a widely used method in control engineering that has been applied both in irrigation canal control [15] and farm irrigation [16] with success. Model predictive control (MPC) has been also successfully applied both in irrigation canal control [17] and irrigation plots [18]. In particular, MPC techniques are very flexible control measures and can optimize the predicted future system behavior, solving constraints and applying optimal control at every sample time [19].
Ref. [20] implement a controller irrigation strategy for cotton farms, considering a heterogeneous field and defining different management zones. The performance of the controller is tested using OZCOT (a simulation model for cotton crop management), and it is compared to the results obtained with sensor-based (relay) techniques. A different approach is taken in [21], where the water dynamics in the soil are described using a linear parameter varying model, and a zone-based MPC with asymmetric zone tracking penalties is proposed. One drawback of the works referenced above is the use of simple water balance models with only one root layer to describe the dynamics of soil moisture, which may lead to problems in capturing the nonlinear dynamics of the water in the soil. According to our knowledge, there is no work in the literature regarding the predictive control (MPC) and optimization at farm scale of both water and energy consumption. From an energy viewpoint, the existing works have focused only on the optimization of the energy use in pressurized irrigation networks, taking into account both the investment and operational costs [22,23].
In this work, a predictive controller has been applied to a case study of a strawberry plot to predict and manage where and how much irrigate in order to minimize the applied water volume and energy costs without compromising crop yields. For more precise and efficient implementation of the predictive controller, we also considered the irrigation uniformity.
The main contributions of this paper include: 1. A controller design, tested in a case study, reducing both irrigation and electricity costs at farm scale without compromising crop yield. The controller is composed of two layers. The first one is real-time optimization (RTO) with a nonlinear model, and its function is to compute the best economic trajectory, taking into account the periodic behavior of the main system variables, the constraints related to the soil moisture, and the water and electricity costs. The second layer is based on the MPC for tracking developed in [24], which guarantees convergence and recursive feasibility even when the parameters of the cost function change with time.
It adaptation makes it possible to take into account the uniformity of irrigation, as analyzed in [25], avoiding decreasing crop yield. 2. Comparison between the proposed controller (RTO + MPC) strategy and a classical irrigation strategy, taking into account the water and energy costs.
The paper is structured as follows: Section 2 presents the system structure. Section 3 introduces the nonlinear dynamical model that characterizes the dynamics of soil water, taking into account the relationship between soil moisture and transpiration to determine the crop yield. Section 4 formulates the proposed controller (RTO + MPC) and its associated variables, constraints and objectives. Section 5 presents the simulation results over a real case study of strawberries in the province of Huelva (Spain). Finally, Section 6 draws the main conclusions of this paper.

System Structure
The main goal for optimizing irrigation is saving water, fertilizer and energy, minimizing costs without decreasing yield. Traditionally, irrigation decisions are made by farmers or field technicians. Figure 1 shows the scheme of the traditional irrigation strategy considering the use of soil sensors. The technician/farmer analyzes the information, such as crop and soil characteristics, the meteorological data and the soil sensor data, collected from the crop field to formulate an irrigation scheduling plan. This irrigation scheduling plan is executed manually or through irrigation controllers. Based on this concept, our proposed controller considers the water soil dynamics using an agro-hydrological model with constraints on the upper and bottom soil moisture levels. Once a day (every 24 h), the RTO obtains the soil moisture value from the sensor, adjusting the optimal signal to the energy costs, and changes the reference (best irrigation schedule), which will be sent to the MPC so that it can follow it. The MPC obtains the sensor data every 15 min and creates a trajectory, seeking to reach the RTO signal, saving water and energy without compromising the crop yield. Figure 2 shows the proposed controller scheme.

Model Description
The most common way to measure the soil moisture in cultivated plots is through the volumetric water content (VWC), which is the ratio of water volume to soil volume. This variable plays a crucial role in irrigation control. Available water (AW) is the range between the permanent wilting point (PWP), the soil moisture level at which plants cannot extract water from the soil, and below the field capacity (FC), the amount of water content held in soil after excess water has drained away. Moreover, there is a soil moisture range where the plant can grow without compromising the crop yield, named readily available water (RAW). Management allowed depletion (MAD) is the desired soil-water deficit at the time of irrigation [26]. The MAD used in the proposed model is the lower limit of RAW. Providing irrigation water at this limit, the crop does not suffer from water stress, which can reduce yields.
A crucial and yet overlooked aspect in the design of advanced controllers for irrigation systems is to consider an appropriate dynamical model to predict the soil water fluxes. Expert agronomists rely on information from several sources (soil, plant, and atmosphere), to properly manage the irrigation requirements of the crops [27].

Soil Water Dynamics
Here, we rely on an extended version of the model in [28], which consists of nonlinear partial differential equations, characterizing the hydrological cycle between the crop, the soil, and the atmosphere, further developed and tested by the authors of this paper in [29]. With this hydrological model, a predictive controller (RTO + MPC) can optimize irrigation using the soil as a water buffer, where the variations are caused by both inflows, irrigation, and precipitation and outflows, transpiration, and evaporation. We assume that the irrigation water enters the ground in the same way as precipitation, and only vertical hydrological dynamics are considered. The soil is divided into N + 1 layers: the surface layer, root zone (further divided into N − 1 layers), and drainage zone are shown in Figure 3. The equations to describe the water dynamics are as follows: where θ i is the volumetric water content of each layer (soil moisture), Q i,i+1 are the water flux between layers with the nonlinear dependence of θ i described in [28], , D i is the soil thickness of each layer, I rr is the irrigation depth, P t is the precipitation, Q N+1 is the flux out of the drainage zone, E and T are evaporation from the soil surface and transpiration from the vegetation canopy, respectively, and ρ w is the water density. The soil moisture at different levels is thus computed at each time step as influenced by precipitation, evaporation, transpiration, and drainage. The flux of the drainage zone is free by default [30] and this flux is important to know because drainage is water lost as a consequence of over-irrigation. To characterize the water flows between zones, Equation (36) in [31] can be used, which, after a finite difference discretization, yields: where K i is the hydraulic conductivity of each layer, ψ i is the matrix potential of each layer, θ sat is the soil porosity, K sat is the hydraulic conductivity at saturation, b is an empirical parameter related to soil texture, and the drainage out of the bottom layer is assumed to be K N+1 . The runoff occurs when surface soil water content θ 1 exceeds the porosity θ sat .

Crop Yield
Transpiration is the process of water movement through a plant and its evaporation from aerial parts, such as leaves, stems, and flowers. Water is absorbed by roots from the soil, and of all the water absorbed by plants, less than 5% remains in the plant for growth [32]; the crop consumes the most water in the process of transpiration.
According to [33], the water availability in the soil can often limit transpiration, reducing crop yields. The most common method to determine the water content in the soil is through soil moisture sensors.
For strawberry, the case study in this paper, the equation relating the soil moisture to transpiration was extracted from [34]: where T a is the actual crop transpiration and x p is the soil water content as a percentage.
Considering the relationship between soil moisture and transpiration, crop yield can be estimated, because, according to [35], only the transpiration portion directly influences the crop yield. The crop water production function presented in [36] is: where Y a is actual crop yield, Y m is the potential crop yield, T a is the actual transpiration, and T m is the potential transpiration. The potential crop yield is between 0 and 1, T m is governed by atmospheric conditions and crop characteristics [37], and K y is the slope of the linear relationship.
Water yield production functions are useful for irrigation scheduling, for the estimation of water requirements and maximum yield, and for the determination of irrigation application efficiency [38].

Predictive Control Hierarchical Structure
Based on Figure 2, the structure of the proposed economic and periodic predictive controller is shown in Figure 4. The input for the tracking MPC is an optimized reference trajectory, which is obtained from a real-time optimizer layer (RTO). Once daily, this RTO obtains the soil moisture sensor value and considers a complex economic function, providing the best periodic trajectory, which must be tracked to obtain the best results in controlling a linear or nonlinear model. The tracking MPC layer makes use of a linearized version of the model Equations (1a), (1b) and (1c) to predict, during a time window equal to the system period (1 day), the evolution of the soil moisture, the water, and energy consumption. This layer must move the system to maintain the soil moisture as close as possible to the value given by the RTO. This periodic aspect helps to ensure the controller's stability since the system does not have to stabilize in an operating point but a periodic trajectory. However, following a classic receding horizon paradigm, only the first control action is applied and, after that, the system outputs (soil moisture) are measured again with the sensor and the MPC tracking problem is recursively solved. It is important to remark that the tracking layer tries to approach the optimal references. This second layer guarantees the recursive feasibility and stability even when changes in certain parameters of the reference (δ u ) occur; this layer follows the developments in [24]. This is an interesting controller that increases the reachability region compared to other classic tracking controllers.
The control objective in the second layer is usually to derive a control law δ u (k) = κ(x(k), w(k)) such that the evolution of the closed-loop system fulfils the constraints (usually, the maximum and minimum in the soil moisture and irrigation flow) and the periodic tracking converge asymptotically to the nearest signal to that computed by the RTO (δ u ).

Model Linearization
The nonlinear agro-hydrological model Equations (1a), (1b) and (1c) are too complex for MPC. To simplify the MPC work, a linear approximation is found to the nonlinear model at equilibrium points, where the crop has a maximum yield. A linear time-invariant (LTI) model is obtained from the linearization: Model Equations (5a) and (5b) have four constant matrices, where A is the system matrix, B is the control matrix, B d is the disturbance matrix, and C is the output matrix. Furthermore, k is the time index, the x(k) ∈ R 4 represents the states of the model, y(k) the output system, u(k) ∈ R 1 represents the control action, and w(k) ∈ R 2 the disturbances associated with this model. In this case, the states (and outputs) of the dynamical model are the soil moisture in every layer (output), of which the last layer is dismissed because it has the same behavior as layer 4 and this layer could be used to determine the water loss; the control action is the irrigation (input) and the disturbances are transpiration T and evaporation E.
The linearization was carried out using the System Identification in MATLAB, employing an algorithm called Prediction Error Minimization (PEM) and simulated input-output data. The comparison between some of the outputs (soil moistures) of the nonlinear model Equations (1a),(1b) and (1c), and the linearized model is shown in Figure 5, where the first and second layer show good identification, and the third and fourth figure apparently show a weaker fit with the nonlinear model, but the identification range is very small (0.001 cm 3 cm 3 ) in comparison with the range between PWP and saturation soil moisture [0.09 0.395] cm 3 cm 3 .

Economic and Periodic Model Predictive Control
In our economic and periodic MPC formulation for farm irrigation systems, both the soil moisture (x(k)) and irrigation depth (u(k)) are restricted within limits related to the crop water requirements and the irrigation system, respectively. Moreover, the system performance is a weighted combination of soil moisture, water consumption, and energy and water costs. These terms are captured by a quadratic economic cost function V p (k, x, u), which depends on both the system state and control inputs.
In this paper, we focus on the periodic operation of a closed-loop system with a fixed period Y of 24 h. The quasi-periodic behavior of the main dynamic variables involved at a farm scale (radiation, crop transpiration, electricity prices) enables us to take advantage of a periodic RTO and tracking layer to achieve better performance, taking into account that we are using a linear model instead of a nonlinear model.

Soil Moisture layer 4
Non linear model Linearized model The main goal of this control structure consists of managing the irrigation to achieve optimal economic performance, which optimizes the cost function, reducing the irrigation depth and the costs associated with the water and energy. This performance cost function V * p is used by a real-time optimization (RTO) layer to provide an optimal trajectory. The optimal trajectory to operate the system is derived from the solution of the following optimization problem(6a), (6b), (6c) and (6d) where the initial state is a free variable: where x are the states, and the set Z r is a closed polyhedron that encloses the abovementioned restrictions that affect the soil moisture and irrigation depth. The optimal state and input trajectories (bold letters denote trajectories of signals over the prediction horizon/period) are x and u , respectively. The optimal solution (x T , u T ) of problem (6a) (P P (x, w)) is used by the tracking optimization problem, which is denoted as P N (x, w). The objective of this problem is to move the real system to the nearest position to the optimal trajectory (x T , u T ). min x r 0 ,u r ,u V N (x, x, u, w; x r 0 , u r , x r , w) where x r and u r are reachable trajectories by the linear model of the controller used to avoid a problematic situation (loss of recursive feasibility, etc.) for the MPC controller. For more details, see [39]. The cost function of this controller, considering the respective matrices' weights (Q, R, W, S), is defined as follows: In general, the initial soil moisture is an argument for the tracking optimization problem, and considering that this controller presents a large reachability region and the size of the admissibility for the soil moisture, the possibility of the optimization problem becoming unfeasible is strongly reduced.
The constraints of the optimization variables are divided into four groups: constraint (7a) imposes that the initial state of the predicted trajectory is equal to the state of the system at time step k; constraints (7b) and (7c) provide the predicted state and input trajectories; constraint (7f) states that the predicted state must reach the artificial reference in Y steps; and constraints (7g)-(7i) provide the artificial reference state and input trajectories. The artificial inputs and states are the decision variables of the optimization problem. These trajectories are reachable trajectories by the model and must be near to the reference, or if possible, must converge to the reference if the reference provided by the RTO is reachable by the model.
It must be noted that we propose the use of a nominal controller, not a robust controller. We avoid unfeasibilities by using a soft constraint in the lower constraints of the soil moisture.

Economic Cost Function for Agriculture
The economic cost function is composed of four main terms. The first term weighs deviations of the soil moisture below the setpoint established as the minimum soil water content permissible (MAD). The second term uses a time-varying weight to minimize the energy cost related to irrigation water. The third term minimizes the use of water. Finally, the last term tries to maintain the minimum level of soil moisture that guarantees the potential (maximum) crop evapotranspiration.
where C energy is a time-varying electric cost, C water is a fixed cost associated with the water per m 3 , x op are the operational point values per layer established as the minimum soil water content permissible (MAD), and wp i are the corresponding weights.

Case Study
We use a case study corresponding to a strawberry farm located in Almonte (Spain); the strawberry cultivar is Sabrina. The cultivars differ in yield and water consumption, determining different crop yields [40]. The farm soil is sandy and strawberry is cultivated under a plastic tunnel with an average size of 6.6 × 50 m. The strawberries were planted in trapezoidal raised beds measuring 0.60 m at the base, 0.50 m at the top, with a height of 0.50 m. Beds were separated by 1.1 m, so each tunnel had six beds and was covered with black plastic mulch. Two rows of plants were placed along the bed with subsurface drip irrigation tape in the center. Plants were spaced 0.25 m apart. A significant number of farmers apply water in pulses of 30-40 min [25,41]. The crops need more water at the end of the season, in June. During June, farmers apply water between 60 and 90 min a day. In this specific case, we consider the classical irrigation in pulses of 35 min twice a day: this is a total of 70 min. Water was supplied by drip irrigation using emitters spaced every 0.2 m, with a flow rate of 5 l h * m at a pressure of 1 MPa. The irrigation depth was ≈6.88 l m 2 . The classical irrigation described above and the controller irrigation system proposed in this paper are compared in terms of the quantity of water for irrigating crops, energy costs, and crop yield. The water price used in the case study is constant and equal to 0.35 Euros m 3 [42] and the electricity tariff per hour in Spain, presented in Table 1, was extracted from [43].
In all the simulation analyses, for both strategies, we use the nonlinear Equations (1a) and (1b) with the first four soil layers (except drainage layer), and the thickness of the layers (3, 12, 12, 12, centimeters) was considered. The term P t is assumed zero because the strawberries were cultivated under plastic (tunnel greenhouse).
Furthermore, note that the evapotranspiration ET c includes evaporation and transpiration. ET c is an important concept and is a common concern in hydrology, ecology, and meteorology [44]. According to [45], the transpiration T is the result of reference evapotranspiration (ET o ), which is multiplied by the crop coefficient K c . The crop coefficient K c for the Sabrina cultivar is above 0.85 in June [46]. As the beds were covered by black plastic sheets inside polytunnels, it was assumed that the crop evapotranspiration ET c was only due to plant transpiration, because there was no evaporation from the soil [47], so E is neglected for this application. Moreover, the simulations use real values for strawberries Y corresponding to a cloudless day in June. These values are shown in Figure 6d with Y for 3 days (4320 min).  According to Equation (3), the soil moisture can be expressed as soil water content as a percentage. Undertaking a transformation to cm 3 cm 3 , the following values for a sandy soil were assumed. Field capacity (FC) value was 0.16 cm 3 cm 3 , and the permanent wilting point (PWP) was 0.09 cm 3 cm 3 . The soil characterization values [48] are shown in Table 2. The crop yield analysis is crucial because water can be conserved by working within the RAW soil moisture range. Thus, the setpoint x op in Equations (10a) and (10b) established as the minimum soil water content permissible was assigned to 0.15. The authors established this as the MAD value, which is around 85% of available water (FC-PWP) in the case of strawberries cultivated in Huelva. In this range of readily available water (RAW), plants are neither waterlogged nor water-stressed [26].
For this analysis, we considered homogeneous soil and crops, and irrigation uniformity influenced by filling/emptying water dynamics.

Linear Model Used in the Controller Strategy
The field capacity plays a key role when using the soil as a water buffer or reservoir because, above it, the water excess is rapidly drained. A thorough simulation analysis of the nonlinear model Equations (1a), (1b) and (1c) make it possible to estimate the field capacity. To this end, simulations with wet layers free of crops were conducted, and the points at which free drainage becomes negligible were determined. These values (soil moisture x eq , irrigation u eq , transpiration T and evaporation E) were used as equilibrium points for the model linearization.
According to the LTI model Equations (5a) and (5b), the values for equilibrium points were the following: The model linearization around the FC with a sampling time of 15 min results in the following normalized system matrices presented in model Equations (5a) and (5b): The constraints and weights used in RTO and MPC are summarized in Table 3. The constraints are the lowest and highest value of the soil moisture (x min , x max ) and irrigation flow (u min , u max ) in which the controller can work. The weights (wp 1 , wp 2 , . . . wp 4 ) indicate the importance of each of the cost functions for agriculture presented in Section 4.4.
In the controller, specifically in the RTO function cost, we take into account the electricity and water cost, the transpiration, and the deviation of the actual soil moisture concerning the setpoint. The weight wp 1 penalizes the soil moisture deviation from the setpoint. wp 2 , wp 3 gives greater importance to the minimization of electricity and water costs and wp 4 gives importance to the transpiration. The wp 1 is very small because the priority is to minimize the irrigation, taking into account the electricity cost, water cost, and transpiration. The RTO gives a reference signal to the MPC and tries to track this signal, taking into account the soil moisture operational point. As detailed in Section 4, the proposed controller is composed of RTO + MPC. The RTO uses the linearized model to obtain the best signal that the MPC can follow. In Figure 6a, we present the RTO and proposed controller (RTO + MPC) signal: the proposed controller uses the linearized model for evaluation. With this, we can confirm that the controller perfectly follows the RTO signal and irrigation begins when the electricity prices are lower.
Both irrigation strategies, the classical and the proposed (RTO + MPC) controller strategy, were also evaluated using the real agro-hydrological model Equations (1a), (1b) and (1c). In Figure 6b, the results are slightly different because the real agro-hydrological model is highly nonlinear. It similarly achieves periodicity, important for irrigation systems.

Results Using the Real (Nonlinear) Agro-Hydrological Model to Simulate Soil Moisture Evolution
We compare two irrigation strategies, classical irrigation and the proposed RTO + MPC irrigation strategy. Both scenarios take into account the evolution of the electricity price and transpiration, as depicted in Figure 6c,d.
Both strategies were evaluated using simulations with a duration of 3 days (4320 min) during the month of June, and in order to simplify the simulation, we assumed that the energy consumption was 0.4 kWh m 3 . Figure 6b shows the amount of applied water for the classical irrigation and proposed controller strategy (RTO + MPC) together with the references provided by RTO. The proposed controller tries to trigger irrigation when electricity prices are lower-see Figure 6c-without compromising crop yield-see Figure 6a,b.
The soil moisture evolution per layer in the described classical irrigation and proposed controller (RTO + MPC) strategy is shown in Figures 7 and 8 3 cm 3 . Therefore, soil moisture layers are above the operational point at almost any time cm 3 cm 3 . The soil moisture signal is given by the controller strategy (MPC + RTO) to track the signal given by the RTO and stay above the MAD in the four layers ( Figure 9). Soil moisture in layers 1 and 2 was above FC at a certain time, which is normal, since the soil water flows from the first layers and seeps down into the lower soil layers. This downward movement fulfils deeper layers. However, even in the last layer (layer 4), the soil moisture does not drop below the MAD level (0.15 cm 3 cm 3 ).Therefore, within these soil moisture ranges and considering the Equations (3), (4a) and (4b), the crop yield was maximum for both the classical and proposed controller (RTO + MPC) strategies.  Furthermore, a simulation of 30 days during the whole month of June was also conducted, with the same conditions as the 3-day simulation and taking advantage of the periodicity of the controller. A summary of the obtained results over 30 days is presented in Table 4.
Crop water requirements during the whole month were around 157.5 l m 2 . Therefore, the total water applied to the crop was higher than 157.5 l m 2 so as not to reduce the crop yield in both irrigation strategies (Table 4). For the classical and proposed (RTO + MPC) irrigation strategies, irrigation application efficiency was 76.2% and 94.3%, respectively. Thus, the proposed controller (RTO + MPC) strategy was more efficient than the classical irrigation strategy. Likewise, the proposed controller (RTO + MPC) strategy reduced the energy cost by more than 50% in comparison to the classical irrigation strategy, without compromising the crop yield.
Based on the results obtained in these simulations, it can be considered that the predictive control proposed in this work (RTO+ MPC) is an efficient tool for optimal irrigation management. The use of this type of predictive controller in irrigation scheduling broadens the possibilities of optimizing irrigation, considering multiple management variables in real time. In this sense, we encourage the research and technical community to use this type of predictive controller in future scenarios of multiple IoT devices for monitoring the different variables in the soil-plant-atmosphere-irrigation system.

Conclusions
A predictive controller has been developed for optimal irrigation management at a farm scale. The proposed controller strategy incorporates a multi-layer agro-hydrological model and an economic cost function. The economic cost function is composed of four terms, deviation of the soil moisture from an operational point, minimization of energy costs, minimization of water costs, and the last term to maintain the potential crop evapotranspiration to guarantee the maximum yield.
The proposed predictive controller (RTO + MPC) was compared with a classical irrigation strategy in a real scenario, showing a significant reduction in water consumption and energy costs without compromising crop production.
Because of the results obtained in this work, the authors wish to emphasize that in order to implement an irrigation control system based on soil moisture, it is important to consider the real (nonlinear) water dynamics in the soil to ensure that the results are representative of reality. This work has been an initial step towards implementing automatic irrigation based on multivariable inputs obtained from IoT-based devices. The presented predictive controller has high potential to improve not only water use efficiency but also energy costs, without reducing crop yields. Further studies will reveal further details of their benefits for the economic optimization of irrigation scheduling.