Implementation of Fuzzy Logic to Automatic Flower Irrigation Device Using Matlab

— Fuzzy logic is a logic that has values of fuzziness or ambiguity between true and false. Values in fuzzy logic typically range from 0 to 1. The theory of fuzzy logic is widely used for control systems in various fields. An automatic flower irrigation system is an automated watering device that can be operated with fuzzy logic. In this research, there are two main parameters: temperature and humidity. For the temperature parameter, five linguistic variables are used: cold, cool, normal, warm, and hot. Meanwhile, for soil moisture, three linguistic variables are used: dry, moist, and wet. The results of this research are the maximum setting points obtained according to the rules that have been defined. In this study, the maximum setting point is achieved with a high temperature and low humidity. The difference in output between the Mamdani and Sugeno methods is not very significant. The Mamdani method produces real number values, while the Sugeno method produces integer values. This difference is due to several factors, one of which is the difference in the use of formulas in the defuzzification process of each method.


Introduction
Fuzzy logic or fuzzy logic is a part of artificial intelligence that is often used.Fuzzy logic is a logic that has a degree of vagueness or fuzziness between true and false [1].Fuzzy logic is defined as a type of logic that is dual-valued and related to uncertainty and partial truth [2].The theory of fuzzy logic is commonly used to build systems based on control systems in various fields such as a watering system.Fuzzy logic has been widely used in various fields, including fraud management systems in telecommunications systems [3], cooling system to improve photovoltaic efficiency [4], predictions seeing the use of transformer substations [5], forecasting of electricity consumption [6], and stress diagnosis system [7].
A watering tool is a device that can assist collectors, including housewives.An automatic watering tool can detect dry soil, allowing the device to control watering automatically when the soil lacks moisture [8].Several previous studies have been conducted for this issue, such as Budi Sugandi and Jeki Armentaria, who conducted tests with moisture testing results having an average error of 2.3% and temperature testing having an average error of 0.41 percent.The typical time generated by the plant watering tool is 33.1 seconds [9].Another study by Suyanto compared the fuzzy output of the Mamdani method and the Sugeno method, with Mamdani resulting in a watering duration of 55.38 seconds, while Sugeno produced an output duration of 60.97 seconds [10].https://doi.org/10.25077/aijaset.v4i2.117138 In this study, a proposed method is used to determine the maximum setting point generated by each method, both the Mamdani method and the Sugeno method.Using the same fuzzification and inference steps, it is investigated whether the methods will result in the same defuzzification in each method.This is done to determine which method is more efficient for an automatic watering device.

Materials and Methods
This research focuses on how fuzzy logic can be designed using Matlab, to determine the setting point for achieving maximum watering duration, and to understand the differences between the Mamdani and Sugeno methods in generating output.The block diagram design for determining fuzzy rules can be seen in Figure 1.

Figure 1. Flowchart of implementation of fuzzy inference for automatic flower irrigation system
The processes stages consist of input of variables (temperatures and soil moistures), level selecting of temperatures and soil moistures, fuzzification, inference system, defuzzication, level output selecting for pump, and water pump actuation for duration.Specifically, fuzzification and defuzzification will be discussed below.

a) Fuzzification
Fuzzification, also known as fuzzyfication, is a process of transforming non-fuzzy (crisp) sets into fuzzy sets, where non-fuzzy (crisp) inputs are mapped into fuzzy form according to the range of input discourse [11].The two parameters used in the fuzzification process are temperature (T) and humidity (R).The membership functions used are triangular and trapezoidal membership functions with the ranges for Temperature (T) is 15°C to 50°C and the ranges for Humidity (R) is 0% to 100%.The fuzzy rules used in this research consist of 15 rules, which can be seen as Table 1.In the inference method of this system, the results are obtained using the AND method (minimum function) and the OR method (maximum function).

Matlab Testing
The result of defuzzification will use the output generated using two methods, namely the Mamdani method and the Sugeno method.The Mamdani method uses the centroid as the output, while the Sugeno method uses "wtever" (whatever) as the output.The output of the fuzzy rules can be seen in Figure 4. Figure 4 is rules viewers.The rules viewer functions to display the results obtained according to the rules that have been configured.Figure 4(a) shows the result of the rule viewer using the Mamdani method, while Figure 4(b) shows the rule viewer using the Sugeno method.After completing the above steps, data can be collected and then analyzed.The obtained data is shown in Table 2.As seen in Table 2, with the same setting point of 22°C temperature and 34% humidity, the Mamdani method yields a watering duration of 3.62 seconds, while the Sugeno method calculates a watering duration of 4 seconds.From this, it can be observed that the Mamdani method produces output in real numbers, while the Sugeno method yields integer real numbers.However, the difference in output is not significantly significant.This could be due to the variation in the defuzzification formulas for each method.
Looking at Table 2, the outputs obtained using two methods, namely the Mamdani and Sugeno methods, differ even with the same setting points.However, the maximum output result (i.e., a watering duration of 12 seconds) is obtained at the same setting point, which is at 41°C temperature 141 and 22% humidity.Both methods achieve the maximum watering duration when the temperature setting point is at its maximum value, and the humidity setting point is at its minimum value.However, at the setting point of 16°C temperature and 75% humidity, the Sugeno method can command the device to stop watering, while the Mamdani method still commands the device to water, although only briefly for 1.77 seconds.Therefore, it can be concluded that the Sugeno method provides better control for this sprinkler control system (automatic plant watering) compared to the Mamdani method.

Device Testing
The device testing is carried out by checking each component one by one to determine if the components can function correctly outside of the script that will be executed.The testing of the components includes the sensor components, which consist of the temperature and soil humidity sensors, the microcontroller in the form of an ESP-32, and the power pump.The overall results of the device testing using the fuzzy method are as shown in Table 3.The comparison of results in Table 2 is different from the results in Table 3.The difference in results can be attributed to several factors, such as (1) differences in the usage of membership degree fuzzification between Matlab and Arduino IDE; (2) variations in rules that can lead to differences in results as well; and (3) discrepancies in the application of formulas in defuzzification that can result in variations in calculation outcomes.

Conclusion
In this research, two methods available in Matlab were used, namely the Mamdani method and the Sugeno method.Each method utilized the same input parameters and rules.During the study, the required set point to achieve maximum watering duration was found to be at a temperature of 41°C with a humidity level of 52%.With this set point, the Mamdani method resulted in a watering duration of 9.33 seconds, while the Sugeno method yielded a watering duration of 9 seconds.However, in the Matlab rules to achieve the maximum setting time of 12 seconds, it required a maximum temperature of 40°C and a minimum humidity of 0%.Consequently, the watering duration was 12 seconds.

Figure 2 Figure 3 .
Figure 2 and 3 represent the linguistic variables of the inputs and outputs.Figure 2(a) shows the linguistic variables of the temperature input.On the other hand, Figure 2(b) represents the linguistic variables of the soil humidity input.In Figure3(a), we have the linguistic variables of the output using the Mamdani method.The membership functions used in the Mamdani method are triangular.However, in Figure3(b), we see the linguistic variables of the output using the Sugeno method.The Sugeno method employs sigmoid membership functions.

Table 1 .
Rules for fuzzy inference system

Table 2 .
Collection of watering duration data

Table 3 .
Results of device testing with fuzzy script