1 Introduction

In previous research, models were demonstrated for use in Internet of Things (IoT) approaches for controlling rice irrigation [1] and rice fertilization [2] in Rwanda, a country with low economic development. While this previous research demonstrated useful results, the methods used independently addressed single agricultural production variables, that is, irrigation or fertilization. This work expands on prior work by adapting fuzzy logic as a means to account for multiple interacting variables impacting fertilization requirements, such as coming into play in rice production. To increase agricultural yields, the Government of Rwanda encourages mechanization and fertilizer use [3, 4]. For example, with government support, Rwandan farmers increased fertilizer use from 4 to 32 \(kg\; ha^{-1}\) from 2007 to 2015 [5]. However, Rwanda has only one laboratory to test soil nutrients, causing delays in soil testing and dissemination of information. As a result, farmers in Rwanda lack knowledge of the soil nutrient status of their plots and, consequently, often make large errors in fertilization actions [6, 7]. When farmers add fertilizer without knowing the soil nutrient status, their actions can negatively impact soil pH and nutrient availability [8, 9]. In Rwanda, improper timing, amounts, and proportions of Nitrogen, Phosphorus, and Potassium (NPK) and urea fertilizers result in rice yields that generally fail to rise above an average of about 3000 \(kg\;ha^{-1}\)  [10]. One path to increasing rice yields in Rwanda is to help farmers improve fertilization decisions made at different times during the growing season. NPK fertilizers and urea provide critical nutrients for rice plants in different stages of growth [11]. For example, N deficiency during the early stages causes stunting and can prevent tillering. Flood irrigation of rice crops causes the loss of N through denitrification and leaching. When urea is used as a source of N and is not properly incorporated into the soil, it can be very rapidly volatilized at warm temperatures [11]. P is critical during later growth stages and when it is deficient, rice will not respond to other fertilizers [12]. Like N, deficiency of K will also stop tillering and in later stages reduce the number of mature grains [13]. For some practical examples, urea is very effective when applied during rice planting (stage 1) and tillering (stage 2) when N is most critical, while an NPK fertilizer is effective during panicle initiation and booting (stage 3) and reproduction (stage 4) when P and K can be limiting. However, rice farmers in Rwanda tend to apply their government allocation of urea (100 \(kg\; ha^{-1}\) ) and NPK (200 \(kg\; ha^{-1}\)) in planting and every time they weed, without knowing the actual requirements for their soil and without regard for the timing of nutrient needs during plant growth. These examples of the importance of timing of plant nutrients demonstrate how effective fertilization control during the growing season can increase the yield of the rice crop. Other factors also impact rice yields. To minimize labor, farmers typically dispose of rice crop residues such as straw by burning them in their fields instead of more effectively recycling the nutrients stored in the residues through decomposition, causing soil nutrient imbalances (C:N ratio, for example) in their fields. In Rwanda, erosion of the topsoil from the surrounding hills into the rice fields causes constant changes in the texture and nutrient profile of the soil in the fields [14]. Finally, farmers have a wide range of economic status, some can easily afford to purchase extra fertilizer while others lack resources to do so. For all of these reasons, rice farming in Rwanda would benefit from more precise application of fertilizers at the plot level, with better monitoring of soil conditions, such as can be obtained with an IoT system. A wide range of IoT applications have been described for the agricultural sector [15,16,17,18]. These IoT systems have been designed to monitor different agricultural parameters such as pH, soil electrical conductivity, water level, and temperature, for a variety of crops. Any IoT system requires an algorithm to perform the important role of translating sensor data into actionable information. A recent review of IoT applications for rice farming focused on the application of machine learning algorithms within IoT systems and identified many areas where more work is needed to make these IoT systems operational [19]. This work explores one such approach, fuzzy logic. Fuzzy approaches can be effective in agriculture system models because they are robust when imprecise and incomplete field data are used, acceptable inputs and outputs can be dissimilar and represented as ranges, and the linguistic rule base can incorporate local expert knowledge. Additionally, fuzzy systems allow for the aggregation of dissimilar input variables in a consistent and reproducible way. Many other researchers have described fuzzy systems applied to agriculture for predicting yields, managing nitrogen, and optimizing fertilization [20,21,22].

1.1 Objective

This work has the hypothesis that an IoT system using a fuzzy algorithm can provide rice farmers with information that will allow them to reduce the amount of fertilizer in current practice while increasing the yield. The objective of this study is to create and demonstrate, through simulation, an IoT-based fuzzy fertilization decision-making algorithm that incorporates the knowledge of agricultural experts and expresses the context of soil properties, climate, and irrigation conditions in Rwanda. The formulation of the fuzzy algorithm is based on interviews with experts and existing knowledge of site conditions. The long-term goal is to develop a low-cost system which will control the fertilizer automatically at the plot level according to the inputs available from soil sensors and the growth stage of the rice. To provide fault tolerance in the commonly occurring case of network communication failure, an alternative algorithm pathway is designed. Finally, minimum fertilization recommendations are provided to farmers with few resources so that they have the opportunity to prevent crop loss under critical conditions.

2 Materials and methods

2.1 Study site

This work accounts for the context of rice farming at the Muvumba Valley Rice Plantation located in Nyagatare District, Eastern Province, Rwanda. Rice is grown at a variety of sites on the plantation, in different geographical settings, resulting in significantly different growing conditions. Overviews of the construction of the fuzzy models are provided, and the validation methods using simulations are described. Details are provided for the variables that will be measured as inputs for the fuzzy system, the rule base for the fuzzy system, and as well as two sub-algorithms used to form the decision outputs. This system is designed to work in parallel with the irrigation control system described in [1].

2.2 Overview of the fuzzy fertilization decision making system

A conceptual flowchart of an IoT fertilization system (Fig. 1) illustrates a possible design with the sensors as input to the fuzzy fertilization decision algorithm and its sub-algorithms. Overall, this flowchart follows that of [23], but with modification of functions and interactions. The decision process takes the sensor data and operates on those data using a fuzzy system created with rules derived from expert knowledge of rice farming fertilization requirements and expected yields in Rwanda. The output of the fertilization decision can then take either of two pathways (sub-algorithm 1 and 2) to calculate the fertilization amount, followed by an actuation pathway (sub-algorithm 3) to act on the fertilization recommendation and automatically deliver fertilizer doses through the irrigation system. When system communications are ascertained as fully functioning, cloud-based processing ensues through a fuzzy nutrient balance method (sub-algorithm 1,in Fig. 1) and data are stored. Basing this sub-algorithm and data in the cloud provides broader access via SMS or mobile app and more flexibility for deeper data analysis. The fuzzy sub-algorithm output is translated into recommended fertilization amounts [24] which are passed on to the locally embedded sub-algorithm 3 ( Fig. 1) for control actions. If there is a fault in system communications blocking cloud access, the pathway switches to the locally embedded sub-algorithm 2 ( Fig. 1). Sub-algorithm 2 applies an empirical estimation method to pass actionable information on to sub-algorithm 3, and the farmer is informed on the system status and recommended actions via SMS through a GSM connection. Because growth stages and soil nutrient changes occur at timescales of several weeks, these fertilizer decision communications need only operate on a time scale of about 1 week. The details of the creation of the fuzzy rule base in Table 1 are based on sub-algorithms 1 and 2 in Fig. 1.

Fig. 1
figure 1

Conceptual flowchart of an IoT based fuzzy Fertilization Decision-Making Algorithm. Sensor data feeds the fuzzy decision algorithm. The fuzzy output decision is translated back to fertilization amounts by either sub-algorithm 1 or 2 and the fertilizer amount is distributed by actuators controlled by sub-algorithm 3

2.3 System variables

It is assumed the appropriate sensors are commercially available, but deployed sparsely across the agricultural plots, rather than as a dense network [25, 26]. Sensors will directly or indirectly measure the six pertinent agricultural variables, namely soil pH, air temperature, water level, clay soil content, and NPK and urea nutrient content in the soil. These sensors will monitor the field conditions and send information to the fuzzy fertilization decision algorithm for analysis. The variables, measured with different accuracy and precision, are expected to have certain ranges (membership functions) that are expressed linguistically in fuzzy rules.

2.4 Fuzzy rule base formation

The six input variables are linked with the fuzzy rule base as IF THEN statements. Rules were formulated from related work and interviews with experts on current agricultural practices and conditions at Muvumba Valley rice plantation. These experts on Rwandan rice production included personnel at the Rwanda Agriculture Board and government agronomists working at Muvumba Valley. The interview questions were designed to elicit responses on practices and knowledge related to fertilizer application, fertilizer requirements for the stages of rice growth, and appropriate quantity and quality of fertilizer for different soil conditions. Fuzzy rules were formulated for the six sensor inputs leading to yield as the single output. Three linguistic variables, low, medium, and high, were used for the inputs and output, except for pH, which is expressed to a finer level of detail since nutrient status is strongly impacted by pH as it ranges from acid to alkaline. This number of variables could lead to many hundreds of permutations of rules. However, due to many permutations being similar, a subset of 183 rules was ultimately formulated. To arrive at this subset of rules, the impact of soil pH, soil clay content, temperature, and water level on the fate of the soil nutrient was considered. Residual soil nutrients, leaching of nutrients, denitrification, and volatilization of nutrients all depend on environmental conditions that are measured by the sensors. Example rules with their conditions leading to low, medium, and high yields are provided in Table 1.

Table 1 Seven examples of the 183 fuzzy rules for evaluating soil conditions leading to low, medium, and high yields

2.5 Fuzzy nutrient balance method: Sub-algorithm 1

The same information used to formulate the rule base is used to create the fuzzy membership functions for sub-algorithm 1, a nutrient balance method. This nutrient balance method is the process used to make management decisions throughout the growing season to improve yields while minimizing fertilization. This method is intended to be the primary method used by the system when it is fully functional, with no communication faults. Triangular membership functions for the variables are used since the linguistic rule base has three levels of low, medium, and high. For example, Eq. 1 provides these functions for fertilizer requirements for each stage of growth, where f is the total fertilizer amount required during the growing season, x is the total available fertilizer within soil without amendment, r is the fertilizer requirement for each stage, and z is the fertilizer uptake by the rice. Top to bottom in Eq. 1, these sets describe conditions of insufficient soil fertility, added fertilizer but less than optimal, a minor excess of fertilizer that may yet be taken up by rice, and excess fertilizer that can lead to soil degradation. The other variables impacting fertilizer availability have similar triangular membership functions.

$$\begin{aligned} Y(f;x,z,r) = \begin{Bmatrix} 0 \quad f \le x \\ \frac{f-x}{z-x} \quad x \le f \le z \\ \frac{r-f}{r-z} \quad z \le f \le r \\ 0 \quad f \le r \end{Bmatrix} \end{aligned}$$
(1)

2.6 Fuzzy inference of minimum and maximum fertilizer

The fuzzy nutrient balance method identifies the optimal fertilization conditions to maximize the yield given the environmental constraints. However, some farmers do not have the resources to completely follow the optimal recommendations while others may over fertilize. To accommodate situations and provide feedback when a farmer might not be taking the recommended actions, the system will send alerts when crop loss is predicted and recommend a minimum fertilization action to take to prevent complete crop failure and maintain a reasonable yield. In this sense, the system considers the socio-economic conditions that may be present. This minimum recommendation is achieved through Eq. 2, which includes the pH fuzzy set, p, in addition to the fuzzy sets for residual soil nutrients and nutrient uptake, x and z. \(Y_p(f)\),\(Y_x(f)\), and \(Y_z(f)\) are their respective membership functions.

$$\begin{aligned} Y_z(f) = min \left[ Y_x(f),Y_p(f) \right] \quad f\epsilon f \end{aligned}$$
(2)

The system also informs the farmers if their actions have led to the maximum fertilizer for each stage to be met (Eq. 3), thereby providing a warning of added costs, potential degradation of soil properties, and reduced yields if more fertilizer is added.

$$\begin{aligned} Y_z(f) = max \left[ Y_x(f),Y_p(f) \right] \quad f\epsilon f \end{aligned}$$
(3)

2.7 Empirical estimation method: Sub-algorithm 2

If there is a fault in Internet communications (a common occurrence in Rwanda), the cloud-based nutrient balance method (sub-algorithm 1) will fail to send commands to sub-algorithm 3. In the case of an extended communication outage, the system will switch to sub-algorithm 2, an empirical estimation method which would be embedded in the field of a node manager. Sub-algorithm 2 will initialize as the last valid output of the nutrient balance method. The sensor data are still available for analysis with the fuzzy rule base, while the fertilizer demand for each stage is estimated from prior data, thus providing a means to estimate yield using Eq. 4. The measured fertilizer within the soil, x, is subtracted from the estimated fertilizer demand for each growth stage, r, to derive the fertilizer estimates to be sent to sub-algorithm 3. Estimated yield, Y, in Eq. 4 will depend on the fertilizer applied and measured fertilizer within the soil, while the combined effects of environmental conditions \(\alpha\) (pH, water level, clay soil content, and temperature) are derived with a fuzzy analysis.

$$\begin{aligned} Y=\alpha \bigg (\sum _{i=0}^{n}(r-x) \bigg )+ \sum _{i=0}^{n}(x) \end{aligned}$$
(4)

This method is used until cloud communications are re-established. Once the IoT system is again fully operational, the nutrient balance method resumes with initialization based on the last state of the empirical estimation method. The \(\alpha\) and r estimates for Eq. 4 can be updated as needed over time as more data are analyzed. Simulations were performed for the two pathways of sub-algorithms 1 and 2. The fuzzy system was modeled using the MATLAB®fuzzy simulation tool in Simulink®. All combinations of the three levels of linguistic variables (except for pH with 12 levels) leads to approximately 2,900 instances. Data inputs used historical data from Meteo Rwanda [27] for temperature from September 2019 to January 2020, and water level from our previous research [1], clay soil content from [26], pH from [28], and NPK and urea data provided by the agronomists responsible for the Muvumba rice plantation.

3 Results

3.1 Model testing

To provide a level of validation of the algorithms, simulation results for a variety of conditions were examined. For example, measured field water levels are not available for the farmers’ plots, while typical values for fertilizer and other variables are known. Thus, the validation simulations use a range of water levels corresponding to different irrigation amounts, with NPK and urea additions held constant, since many farmers apply the government recommendations of NPK and urea [5]. Table 2 shows these simulated yield results for seven representative cases for seasonal averages, with different water levels, constant NPK and urea additions, but variable pH, clay soil content, and temperature. The resulting yield values indicate the simulations are successfully incorporating all variables. Within each case (each column of Table 2), the yield is seen to respond to different levels of water. Comparisons across cases illustrate the importance of pH, clay soil content, and temperature. For example, cases 3 and 7 have significant differences in the average seasonal values for these three variables, leading to a large difference in yield between these cases when the water level is constant. In contrast, cases 5 and 6 have roughly similar average values for these three variables, leading to roughly similar yields for any given irrigation level.

Table 2 Simulated yields for different cases of pH, clay soil content, and temperature. For each case various irrigation levels were simulated, while NPK and urea are held constant at 200 \(kg\,\,ha^{-1}\) and 100 \(kg\,\,ha^{-1}\), respectively

Next, simulations were done to replicate known yields for specific farmers’ plots for the September 2019 to January 2020 growing season. The amounts of NPK and urea applied to these plots were known to be the government recommended amount. The pH, clay soil content, and temperature were known, so the only unknown was the water level. With the known input set, the average water level for the season was varied to find a good match to the actual yield. The range of average water levels producing matching yields spans from about 10 to 50 mm, similar to the range of water levels shown in Table 2. The reasonable range of water levels needed to produce yields matching the measured yields provides additional validation for the simulations. Some general trends observed are a lower range of yields for the more acidic soils and for conditions with very high or very low seasonal temperatures. The best matching simulated yields are compared to the measured yields in Fig. 2. The average measured yield is 2900 \(kg\;ha^{-1}\). This value can be compared to the prediction results described next.

Fig. 2
figure 2

Simulated and measured yields for similar plot conditions

3.2 Prediction results

This section describes the prediction results, that is, predicted yields across a wide range of inputs when either sub-algorithm 1 or 2 are being used to manage field conditions during the growing season. These predicted yields can be compared to the average measured yield of 2,900 \(kg\; ha^{-1}\) determined for the September 2019 to January 2020 growing season. Details of the four selected simulation outputs for the fully operational system (sub-algorithm 1) are presented in Fig. 3. These are some examples of yield (\(kg\; ha^{-1}\)*1000) depending on the environmental variables corresponding to the specific rules listed in Table 1. Figure 3a shows the conditions of Rule 1 translating into a yield of about 4100 \(kg\; ha^{-1}\). Figure 3b shows the conditions of Rule 117 translating into a yield of about 5,600 \(kg\;ha^{-1}\). Figure 3c indicates the conditions of Rule 176 translating into a yield of about 7200 \(kg\; ha^{-1}\). Figure 3d shows some optimal conditions such as in Rule 183, which can demonstrate the production of up to 8,000 \(kg\; ha^{-1}\). These graphical results illustrate how relatively minor changes in the interacting variables impact the yields.

Fig. 3
figure 3

Rice yields (\(kg\; ha^{-1}\)*1000) as a function of various soil and nutrient conditions. While these 3D visualizations can only show two inputs at a time, all input variables contributed to the result

The results of simulations for sub-algorithm 1 specifically for high yield cases are summarized in Table 3. Thus, the reported minimum and maximum variable values define the ranges of the variables for each growth stage which lead to optimized rice yields. If the variables can be controlled by the farmer, then these are a target range for manipulation. If the variable cannot be controlled, such as temperature, the farmer can assess how conditions might impact their yield. Of particular importance are the minimum and maximum total growing season NPK requirements to produce good yields are 91.24 \(kg\;ha^{-1}\) and 113.7 \(kg\;ha^{-1}\), respectively. This optimal range of NPK is considerably less than the standard government allotment of NPK of 200 \(kg\;ha^{-1}\) that farmers typically apply during a growing season. The minimum and maximum total growing season urea requirements to produce good yields are 69.34 \(kg\;ha^{-1}\) and 86.67 \(kg\;ha^{-1 }\), respectively. Similar to NPK, this optimal range of urea is considerably less than the standard government allotment for urea of 100 \(kg\;ha^{-1}\). These simulation results are consistent with reports of over fertilization of Rwandan rice plantations in recent years [7]. Taken as a whole the simulated yields range from about 2721 \(kg\; ha^{-1}\) to 7257 \(kg\; ha^{-1}\), with an average of 4064 \(kg\; ha^{-1}\), which is a large improvement over the average measured yield of 2900 \(kg\; ha^{-1}\).

Table 3 Range of variables (Minimum and Maximum) according to rice growth stage that lead to optimized yield

Sub-algorithm 2 is intended to replace sub-algorithm 1 when communications fail. To test the output of subalgorithm 2, simulations were performed with the algorithm for the entire growing season from September 2019 to January 2020. Table 4 presents examples of simulation variables averaged over the whole growing season and the yield for different rules using the empirical estimation method of sub-algorithm 2. For the 183 rule conditions, the yields range from 2268 \(kg\;ha^{-1}\) to 6486\(kg\;ha^{-1}\) with an average of 3538 \(kg\;ha^{-1}\). Although not as effective as the nutrient balance method of sub-algorithm 1, this method produces simulated yields that are on average larger than the measured yields from the September 2019 to January 2020 season, as previously described.

Table 4 Average simulated seasonal variable values for pH, clay soil content, water level, temperature, NPK, and urea, for selected rule conditions and corresponding rice yield

Taken as a whole, the simulations described here demonstrate the potential of fuzzy algorithms to provide actionable information to improve rice yield. These system simulations demonstrate the ability of decision modeling to adequately monitor and invoke fertilization actions incorporating weather predictions, pH values, clay soil content, and irrigation status from field sensors. Upon creation of the system hardware, the farmer can receive the decision information, assess the reliability of the information, and remotely interact with fertilization controls based on their own expert knowledge combined with the system data and recommendations. The system is designed to make optimal recommendations, but also has flexibility in response to anticipated problems, such as Internet communication failure and under or over fertilization. The system demonstrated here could be adapted to other crops by adjusting the IoT sensor types and the fuzzy rule base. The system has the promise to lower the human effort for manual operation of irrigation and fertilizer control, and potentially increase the return on investment by more precise control of fertilization to decrease costs while boosting yield by as much as 1000 \(kg\;ha^{-1}\). Furthermore, data collected over time can be used for long-term analysis of conditions at plantations such as Muvumba Valley, and help agronomists respond to long-term trends such as climate change. While this simulation was done for flood fertilization, the system has the potential to be applied in the alternate wetting and drying irrigation method for rice where close control of fertilization actions is required to maintain efficient uptake of nutrients over time.

4 Discussion

In this study, a fuzzy algorithm was designed to monitor and control rice production at the Muvumba Valley Rice Plantation in Nyagatare District, Eastern Province of Rwanda. The rule base for the fuzzy algorithm was created from interviews with local agronomists and published data. The algorithm was created for future operation in an Internet of Things system, with three sub-algorithms to enable a flexible response to local conditions and the technical challenges typical of a low-income country. Simulation was used to test the operation of the system and assess the potential impact on rice yields compared to the measured yields. The system could reproduce the actual yields when the conditions were set to be the same as known conditions for weather, soil, and fertilizer application. The exact irrigation amounts were unknown, so the range of irrigation amounts was adjusted to arrive at the yields. However, these amounts of irrigation were well within the realistic range of values.

5 Conclusions

In this study, we have described simulations in which the system adjusts the timing and amounts of fertilizer and water use resulted in predicted yields approximately double the measured yields, despite the application of less fertilizer in total. Even in the case of a system fault, the alternative sub-algorithm 2 produces yields in excess of the measured yields. We conclude that the development of a low-cost IoT system and its algorithm to control and monitor rice production in Rwanda can reduce fertilizer use while improving yields.