# Proposed Fuzzy-NN Algorithm with LoRa Communication Protocol for Clustered Irrigation Systems
## 3 Irrigation Systems Algorithms
### Proposed FITRA Algorithm Supporting the OWS Architecture
Using the fuzzy process output, it calculates neural network weights based on fuzzy training datasets. Concluding, the FITRA algorithm includes two main states: (i) the initial fuzzy state; and (ii) the neural network (NN) state (see Figure 3). A detailed description of the algorithm follows:  
**FITRA Fuzzy state:** Initially the FITRA algorithm makes its \"on\" decisions using an MVA process with irrigation time partitioning based on two thresholds: _Athres_ and _Bthres_ (_Athres_ < _Bthres_ and _Bthres_ - _Athres_ > 250), set by the farmer, or calculated as \(2/3\times 1023=682\) and \(1/3\times 1023=341\) of the soil moisture sensors upper boundary value.If the average value of the sensors is under _Athres_ the actuator is set to \"off\". If the average value of the sensors is above _Bthres_ then the actuator is set to \"on\". If the sensor average value is between _Athres_ and _Bthres_, a fuzzy control process takes place of four fuzzy input states per sensor: (i) adequate moisture; (ii) normal moisture; (iii) fair moisture; (iv) minimal moisture. There are also four fuzzy output states for the actuator: (i) \"Off\": \(u\epsilon\) [\(-1\), \(-0.5\)]; (ii) \"A few drops\": \(u\epsilon\) [\(-0.5\), 0]; (iii) \"Conservative watering\": \(u\epsilon\) (0, 0.5] and (iv) \"Pour\": \(u\epsilon\) (0.5, 1]. The membership function for each one of the input states is calculated using the following Gaussian-like bell formula:  
Figure 3: FITRA algorithm operation block diagram. \[M\text{F}_{k}=e^{-4\left(\frac{x-c_{k}}{\sigma}\right)^{2}} \tag{2}\]  
where \(\sigma\) is the daily standard deviation of each sensor values, \(k=1.4\) are the four input fuzzy states and for each state the \(c_{k}\) coefficient value is calculated as follows:  
\[c_{k}=A\text{{thres}}+(k-1)\frac{|\text{{B}}\text{{thres}}-A\text{{thres}}|}{4} \tag{3}\]  
Based on the inputs the fuzzy process interpolates them using Sugeno fuzzy inference for each crisp input \(M\text{F}\) value based on the following Equation (4):  
\[u=aM\text{F}_{1}+bM\text{F}_{2}+cM\text{F}_{3}+d\text{{M}}\text{F}_{4} \tag{4}\]  
where \(a=1\), \(b=0.5\), \(c=-0.5\) and \(d=-1\), are the constant weights for each one of the fuzzy inputs. If the output value \(u>1\) or \(u<-1\) then the output value is set to \(u=1\) or \(u=-1\) accordingly. Because watering decision is not dependent on only one sensor value, but on a number of \(N\) sensor values, the aggregated output \(U\) is calculated based on Equation (5):  
\[U=\frac{\sum_{i=1}^{N}u_{i}}{N} \tag{5}\]  
If the output value \(U\) is \"off\" then the actuator remains to the \"off\" state. If the output value u is on the \"on\" or \"a few drops\" or \"conservative\" watering states, then from the \(U\) value Equation (5) the \"on\" watering time period \(T_{w}\) is calculated as follows (\(T_{wmin}=1\) min, \(T_{wmax}=10\) min set by the farmer):  
\[\text{{T}}w=\left\{ \begin{array}{c}|U|T_{wmin},out=fewdrops\\ |U|T_{wmax},out=conservative\\ T_{wmin}+|U|T_{wmax},out=pour\end{array} \right. \tag{6}\]  
**FITRA immediate interrupt state:** This state can either be enabled or disabled at the AS and requires a flow meter placed before the actuator. If the FITRA interrupt state is enabled then its state decisions have higher priority than of FITRA fuzzy or FITRA neural network (NN) states. That is, the FITRA interrupt state will interrupt the watering \"on\" decision and set an alert notification at the AS in one of the following cases:  
* Identification and reporting of erroneous \"on\" states due to actuator misuse or malfunction. * Identification and reporting of excess daily water consumption, when water consumed exceeds a certain high water consumption threshold Wthres. * Identification and reporting of leaks when there is water flowing and the valve is in the \"off\" state. For extreme weather condition irrigation interruption, FITRA uses the OWS temperature readings from the microcontroller one wire DS18B20 temperature sensor.