Fuzzy Logic Controller on microcontroller in steering Air Conditioner – part I

I’d like present Fuzzy Logic Controller working on raw  microcontroller (without any OS) from practical point of view in steering Air Conditioner. Why raw microcontroller? Because I love challenges and implementation is much more sophisticated then in case of singleboard (e.g. raspberry) or computers, where we have installed operating system. In case of microcontroller engineer has only C language (low-level programming) and simple loop instruction. 

In first part I will focus on technical issues and tests fuzzy controller for different values (generted from random functions) – becouse we want to check and tests all possible combinations of input variables in defuzzification process. It was difficult to apply DHT11 sensor to generate random values, becouse it bases on real time detection of temperature and humidity. In part II (next separate article) I will present tests with connected fan and DHT11 sensor (increasing temperature). In  presented solution I don’t use Matlab or other similar solutions to generate C codes. This is my own source code created by me from the begining. I’m not going to focus on fuzzy logic or electronic theory becouse there is a lot of books or documentations on websites.

Testing defuzzification methods in part I bases on generating every 10 sec new random input values and validating output value. Please pay attention on following issue: You can find on websites a lot of samples regarding with CENTROID function – also doctoral elaborations –  where extreme defined output values for extreme input values will be never reached – You can verify it by yourself tests. Why? because when You will use CENTROID function this is normal situation – and here we need a small scientific trick. In my presesented solution for input  extreme values, output extreme values are always reached. Few people know the solution to this problem and are rarely discussed in publications or books. Properly practical working commercial solutions are patented and not presented to public. Personally, I know of several professors who were able to answer this problem

Fuzzy Logic Control 
• Over 50 000 patents involve Fuzzy Logic Control
• Over $10 000M in product sales using Fuzzy Logic Control
• Profits estimated in billions ($$$) using Fuzzy Logic Control

Prototype scheme:

1. Transistor MOSFET IRF530N –  The Arduino doesn’t supply 12 Volts. So we have to use some sort of an electronic switch. A MOSFET is a kind of transistor, that can handle the needed current/voltage needed. It’s a N-channel Mosfet. That means you can control the connectivity of the negative pole of the power source to the fan by applying a positive voltage.
2. DHT11 – temperature & humidity sensor
3. Microcontroller Arduino Uno  – microcontroller has only 32k of ROM and 2k of RAM – this is hardware limitation that I had to cope in case of software. Additionally, from programming point of view, on microcontroller you cannot use the heap, that is, allocate objects. So raw C language and low-level programming seems best solution. 
4. Fan – we can use different kinds of fan and also in case of size of device, size doesn’t matter. Presented FLC can also steering more then 1 fan.
5. The rest of the electronic components in the diagram

Fuzzy Logic Architecture:

Membership functions:
Input variable: temperature, humidity
Output variable: fan speed


Membership Output variable:

Fuzzy Method & Model: (MAX-MIN) and (Mamdani Minimum) for inference and composition, (CENTER OF AREA) to defuzzification in a continuous universe. 

Inference:  FLC using 16 defined rules (not presented in this article and not published to public)

Conclusion: According to scientific elaborations using another methods like Tsukamoto or Sugeno methods energy savings is 55 % – ~75%(for applied tests).
From the three methods(Mamdani, Sugeno, Tsukamoto) were compared, the best method in terms of reduction of electrical energy consumption is Tsukamoto method with average savings of 74% (for applied tests).

Main board monitoring by serial port:

Logs from microcontroller: 

In log file You can monitoring membership of input values on fuzzy sets, output value, and MOST IMPORTANT: Fired Rules (one or more)

Logs file – click here to download file

Prototype of fuzzy logic driver:

other preview

Fuzzy Logic Controller in steering of fan speed based on reading temperature and humidity from sensor DHT 11 (watch below movie):

Movies from tests: Testing defuzzification methods. Every 10 sec generating new random input values and validating output value (watch below movies):

January 29th, 2020