**3. Experimental and simulation results**

The analysis, design, and simulation of the programming algorithm for the fuzzy controller were carried out in a MATLAB™ Script, which was used to perform an analysis of its operation. **Figure 7** shows the simulation of the fuzzy controller in the MATLAB™ Script, **Figure 7(a)** shows the fuzzification of the "food" variable with a score of 15, **Figure 7(b)** shows the fuzzification of the "service" variable with a score of 35, and **Figure 7(c)** shows a defuzzification value or tip value of \$31.61. Fuzzy Logic Toolbox™ was used to determine the accuracy of the fuzzy controller, which was implemented using the proposed methodology in the different platforms mentioned above. Therefore, the results of Fuzzy Logic Toolbox™ are considered as the ideal results or correct results. The results of the fuzzy controller in the MATLAB™ Script (MS), Fuzzy Logic Toolbox™ (FLT), the Arduino UNO board (AUNO), the Arduino DUE board (ADUE), and the Nexys 4™ board (NX4) are shown in **Table 2**. The Mean Square Error (MSE) is used to as an analysis of the accuracy of the proposed

**Figure 7.** *Result of (a) fuzzification of the food variable, (b) fuzzification of the service variable, and (c) defuzzification value or tip value.*

*Methodology for the Implementation of a Fuzzy Controller on Arduino, MATLAB™… DOI: http://dx.doi.org/10.5772/intechopen.109760*


#### **Table 2.**

*Experimental results and simulation results of fuzzy controller.*

methodology, which is summarized in **Table 2**. It can be seen that the fuzzy controller implemented in the Arduino boards, Nexys 4™, and the MATLAB™ Script generate almost the same MSE in all the examples. Also, the results show that the fuzzy controller can estimate the optimal parameters and compensate the uncertainties and nonlinearity of the system. As we can see, the error is minimal in the different platforms. This is very important for the research presented here, which focuses on the retention of experience and its subsequent instead of the mathematical model and nonlinearities found in the system.

The MSE, which measures the error between two datasets, was used to determine the accuracy of the proposed fuzzy controller. Eq. (6) was used to determine the MSE, and the values of 0.0326, 0.0643, and 0.1125 were obtained for the Arduino UNO, Arduino DUE, and Nexys 4™ boards, respectively. A high degree of accuracy is obtained on the MATLAB™ and Arduino platforms, since their programming language allows the use of a wide variety of variable types (integers, floating point, bit, byte, etc.) and control statements (IF-THEN, FOR, WHILE, etc.). Finally, the precision of the Nexys 4™ board is lower, since this board does not allow the use of floating-point numbers or real numbers.

$$\text{MSE} = \frac{1}{\mathbf{n}} \sum\_{i=1}^{n} \left( \mathbf{dn}\_i - \mathbf{y}\_i \right)^2 \tag{6}$$

where n is the data number, dn is the desired value, and yn is the system result.

An analysis of the control surface or controllability of the process is carried out, which is obtained from the fuzzy controller results. The control surface shows the form, in which the process control will be performed. The control surface shows the mapping of the input and output variables of the controller. The control surfaces for the MATLAB™ Script, Fuzzy Logic Toolbox™, Arduino UNO board, Arduino DUE board, and Nexys 4™ board are shown in **Figure 8**. We can see when achieving a monotonic curve as **Figure 8** has, means that do not exist large changes and for this,

**Figure 8.** *Control surface of (a) Fuzzy Logic ToolboxTM, (b) MATLAB™ script, (c) Arduino boards, and (d) Nexys 4™ board.*

control action is smooth that means that the movement of the actuators works without stress, since an unsmooth control action can damage the actuators in the process. The control surface shows all the possible results of the controller; that is, the control surface shows all the results of the variable "tip" for all possible combinations of the variables "food" and "service."
