Abstract
It is known that in crowded environments such as educational institutions and workplaces, keeping indoor air quality and climate within certain limits contributes to success and production. For this purpose, a system has been developed to ensure air quality well-being in working environments. In our study, the Arduino processor managed by the fuzzy logic control system (FLC) starts to work with the trigger of the motion sensor HC-SR501. The inputs of the FLC system are defined as LM-35 sensor for temperature, DHT-11 for humidity, MQ-135 for air quality, MQ-9 sensor for CO and explosive gas. The designed system evaluates the instantaneous data obtained from the fuzzy logic system rule base and decides which of the output air filter, heater and alarm systems will operate at what speed. In order to increase system efficiency, fuzzy logic input membership values are optimized by genetic algorithm.
Introduction
Ergonomics is generally described as the whole of studies that examine the adaptation of humans to machine and environment by investigating the physical and psychological characteristics of them. Contrary to this expression, the adaptation of the environment or machines to humans is also included in the subject of ergonomics. In this context, due to the growing technology, human and nature-oriented solutions come to the fore.The relationship between indoor air quality and success in educational institutions or production efficiency in industrial establishments has been the subject of many studies [15, 16]. Indoor air quality in crowded environments can deteriorate over time if not controlled. Individuals who have to work in areas with poor indoor air quality may experience both physical and psychological tensions and even psychological deterioration.
Literature review (tabular form)
Literature review (tabular form)
In this study, indoor air quality and climate were tried to be kept within the limit values of the internationally determined Air Quality Index (AQI) standards. The system is activated with motion sensors and based on the responses from the FLC system, the air cleaning and heating systems are operated gradually, contributing to the efficient use of energy resources. In addition, the system acts as a warning system by giving an alarm in the presence of suffocating gas CO and explosive gas in the environment. The Fuzzy Logic Control System (FLC) determines the operation of air cleaning, heating and alarm systems at appropriate rates with the instantaneous measurement data it receives from indoor air quality and climate sensors. To increase the efficiency of the FLC system, the fuzzy logic input membership values were optimized with the Genetic Algorithm (GA) and the results were evaluated.
Although PWM direct current 5 V voltage is used as the system output in most studies with Arduino, 220 V is used as the system output in our study and the outputs are operated gradually. With the activation of the system with the motion sensor, the system starts to work without the need for external intervention. First of all, 3 inputs (Temperature, Air Quality and Humidity variables) that make instant measurements on the created FLC system were defined and 2 variables (Ventilation and Heater) were determined as output. In order to increase the efficiency of the FLC system, the output values were handled one by one using the 2091 test data, and the input membership values were optimized by genetic algorithm using the learning data of the fuzzy logic system.
A significant decrease was observed in the RMSE error rate of the FLC system created with new membership values in the Fuzzy controller genetic learning structure presented in Fig. 1.

Fuzzy controller genetic learning structure.
It has been observed that the studies in which genetic algorithm is used together with fuzzy logic systems are generally used in optimization of objective function [7], determination of fuzzy rules [22], determination of input membership parameters and shape [9], and optimization of both input and output membership values [9].
Genetic algorithm
Genetic algorithms are general-purpose optimization algorithms based on natural selection and natural genetics with a probabilistic component to search for solutions in poorly understood, disordered space. John Holland developed the theoretical basis of GA and presented it in his book titled Adaptation in Natural and Artificial Systems [13].
The genetic algorithm was first used by Holland in the optimization of the objective function [7]. The variables to be optimized in the system are processed into the genetic algorithm as chromosomes [3]. Evolution is a process that runs on chromosomes. He explained that chromosomes encoding successful structures reproduce more frequently than those that do not succeed, as natural selection and the performance of the chromosome chain. It has been mentioned that recombination provides the formation of children with different chromosome chains by combining the chromosomes from two parents. With the mutation, the chromosomes of the children are differentiated from those of their parents, so that the solution does not remain local.
With computer algorithms, GAs emulate nature’s ability to solve difficult problems that evolution has made. GAs often require that the maximization (or minimization) problem be expressed as a cost (goal) function.
The Genetic Algorithm starts with a randomly generated gene pool, called the initial population, in which many solution sets are included. All the variables of the function are lined up side by side to form the chromosomes (individual), and each chromosome contains a possible solution for the problem [8]. By calculating the fitness value of each chromosome, it is determined how well the chromosome in question solves the problem. Among these chromosomes, the ones with the highest fitness value are kept, the others are destroyed. [7]. By using the selected chromosomes, a new population with a higher fitness value is created by the genetic processes called mutation, crossover and selection [19]. These genetic processes are iteratively repeated until the desired system performance is achieved with the fitness function, as shown in Fig. 2 [9].

. The flow chart of finding higher performance fuzzy membership functions with RGA (Real Coded Genet-ic Algorithm) [9].
Crossover is the formation of a new chromosome by dividing a chain from one or more randomly selected crossover points and merging it with another chain that has been split from the same crossover point. With this procedure, reaching the best chains that can give a higher fitness value is ensured.
A mutation is a random change of a bit in the chain to eliminate the risk of the solution staying at the local optimum [3].
GAs can solve a wide variety of linear, nonlinear, discontinuous, discrete, and complex problems thanks to proper coding of the system.
The penalty (error) value of individuals in the initial population is calculated by comparing the obtained solution with the value accepted as a reference. The penalty function for the individual is denoted by ci, where n is the number of genes;
It is necessary to know the probability value of each individual (Pi) in determining the methods to be used in individual selection where m is the number of individuals in the population;
And the cumulative probabilities (KPi) of individuals,
Roulette Wheel method: The surface of the roulette wheel is marked in proportion to the density of the fitness values of the arrays, then the fitness values of all individuals in the community are summed up and the probability of each individual being selected is the ratio of the fitness value of the individual to the total fitness value, as shown in Eq. (3). The selection process works as follows; Starting from the first individual, a random X number between “0” and “1” is generated for each individual. The individual satisfying the X < KPi condition is transferred to the new population. Thus, individuals with high (good) cumulative probability are transferred to the next generation as shown in Eq. (4). As a result, chains with better fit values will have a higher chance of being selected because they have more space on the wheel [8].
Tournament Method: A tournament is made by randomly choosing two chains from the whole generation at a time and whichever has the best fitness value wins. Each series participates in the tournament twice. Thus, the most successful ones can write their names on the results list twice, and the intermediate level once.
Steady-State Method: This method is used to ensure that a chain survives for more than one generation by relocating a limited number of chains in the population. For this purpose, a certain number of chains are selected from the existing population. New generations are produced from them. Produced new generations rejoin the population. However, in order not to exceed the maximum population, some individuals are expelled.
Sorted Selection: In this method, all chains are sorted in ascending order according to their fitness values. The chains with the highest fitness value leave more copies in the gene pool, while the worst sequences do not. The search speed of this method is high [8].
Various criteria have been defined to terminate the GA process; these are stated as the solution represented by the best individual, the most appropriate solution found for the problem, the total number of iterations, the determined time or the fitness value constant [12].
Fuzzy controller
Fuzzy membership functions refer to a set of rules describing a set of actions to be performed for a given set of inputs in fuzzy controllers. It is easiest to think of these rules as if-then statements in the form IFset of inputs THENoutputs. The “defuzzification” process of the application must take into account how much each rule has been applied. Usually the centroid method is used to calculate the effect of each rule on the output.
In general, performance measurements of optimizations are made according to the mathematical model of the problem, but one of the strengths of fuzzy controllers is that they do not need mathematical models. Their performance measurement is evaluated according to whether they provide the determined fitness value [22].
Applicability of genetic algorithms to fuzzy controllers
Previous studies on the application of genetic algorithms to fuzzy logic controllers mainly focused on two areas: learning fuzzy rules and learning membership functions. The robustness of a GA is that it covers a complex search space in a relatively short time while providing an optimal or near-optimal solution, making GAs a suitable choice for fuzzy controllers [22].
Recommended system model
The proposed system model architecture has five phases: sensor observations, fuzzification, inference, defuzzification, and mechanics. The block diagram of the proposed system is shown in Fig. 3.

Recommended system model.
As seen in Fig. 3, the system is activated with a motion sensor, and as a result of processing instant data from temperature, humidity and air quality sensors in the fuzzy logic rule system, the air cleaner and/or heater which are the outputs of the system operated gradually via dimmer relays.
In order not to cause system complexity and to increase system security, the audible alarm system is not included in the fuzzy logic system and the system is designed to work when the suffocating gas rate in the environment is in the 4 (Red) zone according to the Air Quality Index.
The fuzzy logic software created in the Matlab R2018b program was converted to the Arduino program by the Arduino FIST: MATLAB Fuzzy Inference System to Arduino C Converter program [19], and the system was made operational by performing operations such as library and pin definitions of the sensors and scaling of the sensor measurement results on the Arduino program.
As shown in Figs. 3 and 4, the fuzzy logic input membership values were optimized by genetic algorithm by using the previous 2091 input and output experience data in the designed system, and as a result, the system performance was increased with the new fuzzy membership values [10].

The design and implementation methodology of the study.
The stages of the design and implementation methodology of the study presented in Fig. 4 are given below.
Offline Design Process: 4 fuzzy membership functions were defined for each of the Temperature, Air Quality and Humidity inputs, and then 43 = 64 rules were defined. The output is defined as a single Ventilation or Heater and 4 membership functions are defined for each. Input membership values for each output were optimized by genetic algorithm with 2091 test data. The fuzzy system with new membership values has been transferred to the Arduino system and the system has been made ready for operation. 1500 pieces of data were randomly selected from 2091 sample test data and an increase in system performance was observed with the genetic optimization performed with the defined 4*4*4 = 64 rules, since they each have 4 entry membership values.
Online Transaction Process: Data from indoor sensors via Arduino gradually drives the outputs with the new FLC. This section presents the experiments conducted in order to evaluate the algorithm proposed in this work.
The circuit design of the system created with the Arduino ATmega2560 is shown in Fig. 5. The system software started with the addition of sensor and dimmer libraries as shown in Fig. 6, input-output pins were defined, relay settings were made, fuzzy genetic code created in the Matlab program was included in the software [10], instant sensor data was taken from the serial port and the outputs were operated at the desired rate in accordance with the rule base.

Arduino circuit design.

Implementation of program software with Arduino 1.8.13.
In order to increase system security and not cause unnecessary confusion, the alarm system is not included in the fuzzy logic system, and it is set to give an audible warning when the suffocating gas rate in the environment reaches the 4th zone of the International Air Quality Limit Values presented in Table 3.
Considering the International standard values presented in Tables 2 and 3, the lower and upper limit values for indoor temperature, air quality and humidity to be used in our system were determined and presented in Table 4.
National and International Indoor Air Quality Standard Values
International Indoor Air Quality Limit Values AQI (Air Quality Index) 0∼500
Initial membership values for fuzzy logic inputs
The nomenclature of the 4 membership functions of temperature, air quality and humidity values, which are the inputs of the fuzzy logic system, are shown in Table 4. Since there are 4 membership values for 3 inputs in the FLC system, 4x4x4 = 64 rules are defined.
Fuzzy logic input membership values are determined as triangular and output values are determined as transpositive. The fuzzy logic output will be the input for the genetic optimization process. For this, firstly, the outputs shown as 4-parameter transpositive are converted to 3-parameter triangular representation is shown in Fig. 7. While measuring the system performance, fuzzy input membership values, which are shown as triangles, will also be converted to transpozial values [19].

Using fuzzy logic outputs as inputs in Genetic optimization.
In the genetic optimization process, LB and RB are defined for the parameters of each input membership function and also the deviation from the min and max boundary points is entered as dist. Fuzzy logic output data are randomly selected from the data set and treated as input data for the genetic optimization process. After adapting 4 parameter values to 3 parameter values, optimization starts with the parameters determined for genetic optimization and 3 parameter values belonging to 4 membership values of each fuzzy input are determined.
delta_num = delta_num + 1;
LB(delta_num) = -(fuzinfsys.input(i).mf(j).params(1)-fuzinfsys.input(i).range(1))-dist;
RB(delta_num) = (fuzinfsys.input(i).mf(j).params(2)- fuzinfsys.input(i).mf(j).params(1))/2;delta_num = delta_num + 1;
LB(delta_num) = -(fuzinfsys.input(i).mf(j).params(2)- fuzinfsys.input(i).mf(j).params(1))/2;
RB(delta_num) = (fuzinfsys.input(i).mf(j).params(4)- fuzinfsys.input(i).mf(j).params(2))/2;
delta_num = delta_num + 1;
LB(delta_num) = -(fuzinfsys.input(i).mf(j).params(4)- fuzinfsys.input(i).mf(j).params(2))/2;
RB(delta_num) = fuzinfsys.input(i).range(2)-fuzinfsys.input(i).mf(j).params(4)+dist;
Genetic optimization generated learning data by randomly selecting 1500 of 2091 datasets. For optimization, the size of the data population is set to 400, the number of iterations is set to 15, the time limit is unlimited, and the relevance limit is set to 0.04 [11].
Optimization of fuzzy membership values for ventilation
A fuzzy system is designed for Temperature, Air Quality and Humidity inputs and Ventilation output, and 64 rules defined for the system are listed in Table 5.
Rule base according to ventilation output
Rule base according to ventilation output
In Fig. 8, the situations where the output system is not desired to operate are shown with L(Low) and its parameters are determined as [0,0,0] so that the system works stably.

Ventilation output values membership functions.
In Fig. 9, the initial and optimized states of the fuzzy inputs for Temperature, Air Quality and Humidity according to the Ventilation output are presented separately. To evaluate the system performance, RMSE errors were calculated for the first and final fuzzy design.

a) Optimization of the Temperature value according to ventilation. b) Optimization of Air Quality value according to ventilation. c) Optimization of Humidity value according to ventilation.
In the optimization performed according to the ventilation output, the best fitness value was obtained as 25.01 and the average value as 27.58 in the 12th generation. The RMSE error of the input membership values determined for the beginning was 60.02%, the RMSE error measured as a result of the optimization was found to be 25.21%. As a result of the optimization of the fuzzy input membership values for the ventilation output, an improvement of 58% was achieved.
A fuzzy system with Temperature, Air Quality and Humidity inputs is designed for the Heater output, and 64 rules defined for the system are listed in Table 6. The initial and optimized states of the fuzzy inputs for Temperature, Air Quality and Humidity according to the Heater output is presented in in Fig. 10. To evaluate the system performance, RMSE errors were calculated for the first and final fuzzy design. The RMSE error of the input membership values determined for the beginning was 51.80%, the RMSE error measured as a result of the optimization was found to be 23.22%. As a result of the optimization of the fuzzy input membership values for the heater output, an improvement of 55% was achieved.

a) Optimization of the Temperature value according to the heater. b) Optimization of the Air Quality value according to the heater. c) Optimization of the Humidity value according to the heater.
Rule base according to heater output
Some of the experimental results of our study are presented in Table 7. Accordingly, in the first 10 experimental studies, the results obtained as a result of genetic optimization performed separately according to ventilation and heater outputs were listed. In experimental studies 11-15, the test results of the new fuzzy system obtained by taking the average of the membership functions of the two fuzzy systems obtained as a result of previous genetic optimization were shown. In order not to increase the complexity of the fuzzy system, the buzzer automatically works when the CO-Flame sensor data is greater than 8 without being included in system.
Experimental results of the study
An improvement of 57% was achieved with the optimization of the fuzzy logic input membership values made according to the ventilation output and % 59 improvement was achieved in the optimization made according to the Heater output.
Simultaneous genetic optimization did not yield appropriate results for this problem in the system designed based on the two output systems whose rule base is presented in Table 8.
Rule base according to Ventilation and Heater Output
The RMSE error result of the new fuzzy system, obtained by taking the average of the membership functions of the two obtained fuzzy systems, decreased by 31%, thus an improvement in the system performance was observed.
As a further study, different control systems can be applied. Examples of these control systems are artificial intelligence systems. In addition, optimization algorithms such as particle swarm optimization, artificial ant colony optimization can be used to optimize fuzzy built-in membership values. In the study, instead of the simultaneous optimization of the two-output system, the optimization of each output was done separately. According to the results of the studies carried out separately according to the ventilation and heater outputs, RMSE error rates were reduced by 58% and 55%, respectively. When the performance of the new 2-output fuzzy system designed according to the arithmetic mean of the two new input membership values obtained as a result of separate optimizations is evaluated, it is seen that the RMSE error value is 31% less than the initial value. Similarly, studies can also be carried out to control the audible warning system by measuring the carbon monoxide level in addition to the ventilation and heater outputs with a multi-input multi-output fuzzy logic system.
When the studies designed for ergonomic comfort and safety purposes in the literature are examined, our study gains importance since it is a rare study that used Arduino and designed with Fuzzy Control systems optimized by genetic algorithm is actually implemented.
Conclusion
Optimization of input membership values with genetic algorithm was done separately for each output. As a further study, the input membership values can be optimized for multiple outputs at the same time.
Footnotes
Acknowledgments
M.Lüy, N.Barışçı and A.Başal for their support.
