Comfort Soft Sensor

Introduction: Comfort Soft Sensor

About: I am an engineer and a maker who loves technology challenges.

More and more open source home automation projects are appearing online. Instructable is not exception. What bothers me is that most provided solutions are not offering intelligent solutions. One of many things to control in smart home is atmospheric comfort. Atmospheric comfort is defined with temperature and relative humidity - temperature ranges from 20°C to 25°C and relative humidity is around 50%, and it varies across the globe.

Now we are determined to control atmospheric comfort. But how can we measure comfort? We can measure temperature and relative humidity and then we predict comfort. Ok. But how can we automate this process? We could use mathematical model to calculate it. Believe me, you don’t want to go that way, since modeling is pain in the ass!

There is simpler solution: artificial intelligence. We can implement so called soft sensor. Soft sensor can be any sensor that can indirectly measure certain value. Since we want to use artificial intelligence, we have two plausible solutions in our case: using fuzzy logic or using neural networks. Because we do not poses tons of data, we’ll be implementing soft sensor using fuzzy logic.

This Instructable can be used as short introduction into fuzzy logic and it shows that artificial intelligence is not necessarily something to avoid or be feared of. End result will be soft sensor of atmospheric comfort.

Note: Instructable is not meant for beginners but for intermediate and advanced users.

Step 1: What You'll Need?

We will need:

- Arduino UNO (any other will do as well)

- DHT11 temperature and humidity sensor

- wires

Step 2: Short on Fuzzy Logic

For beginning I have to write something about fuzzy logic.

Variables in digital (Boolean) logic can be TRUTH or FALSE or “1” and “0” respectively. So there are only two values: in the area (comfortable) or outside of certain area (uncomfortable). So solution to our problem with digital logic can provide us only with border values. But what if we could reach any value between 1 and 0? Yes my friends, fuzzy logic can do just that!

There are three stages in fuzzy logic: fuzzification, prediction and defuzzification. First something about fuzzification. Fuzzification is process with which we calculate affiliation of input variable to a certain fuzzy populace or membership function. There can be many different shapes of membership functions: trapeze, triangle, Gauss,… In prediction stage we are using pre-determined set of rules (those are set by designer) to predict what the output can be or to which membership function output variable affiliate whit what level. This numbers cannot be used as they sits. In the third stage, defuzzification, we can combine all the levels of affiliation to only one value. This process is also called sharpening of output value. Single output value can then be used in further processing. More about fuzzy logic.

Predictions is what makes fuzzy logic very useful when mathematical connections between variables cannot be determined numerically or algebraically. There are several fuzzy systems available for us to use:

- Mamdani system (linguistic output variables, defuzzification can be complex)

- Sugeno system (output variables are functions or singleton/constant, more suitable for implementing on microcontrollers)

Compariosn between Sugeno and Mamdani system.

Step 3: Designing Soft Sensor

There are many tools to help design fuzzy system. I am using Matlab, but Python with fuzzy system library can do the trick.

Soft sensor is designed in Matlab using Fuzzy Toolbox and then implemented on Arduino. We have designed Sugeno fuzzy system with singleton output variables. Fuzzy sets of input variables and output variable with membership functions are presented in pictures above. There are two input sets with three membership functions each: temperature and relative humidity. We’d decided to use triangular membership functions. Output set Comfort consist of three singleton membership functions: very uncomfortable (u1 = 0), uncomfortable (u2 = 0.5), comfortable (u3= 1). We have designed set of 9 rules to determine atmospheric comfort and are listed in pictures above. Defuzzification output will give us a number between 0 and 1 (because it can later be simply calculated to %). We tested designed system in Matlab, results are presented in pictures above.

Step 4: Hardware Setup

Hardware setup is nothing special. DHT11 is attached to Arduino UNO as it is presented on picture. Instead of DHT11 for measuring temperature and humidity we could use other sensors, like DHT22 or HDC1000. The only difference is in code and in attaching sensor to Arduino.

Step 5: Soft Sensor Code

Although a fuzzy logic library exists for Arduino, we decided to write our own code. Code is mainly copied from Matlab and it is well commented. Flow diagram is added above (in pictures) for easier understanding.

Step 6: Conclusion

Soft sensor is working as it was designed.

How it can be used to control comfort you say? In the end I am adding a block diagram of control loop (feed forward control). It consist of temperature and humidity controller in cascade to comfort controller. But this is a topic for another Instructable. Feel free to comment.

Be the First to Share

    Recommendations

    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Super-Size Speed Challenge

      Super-Size Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020

    3 Discussions

    0
    TomislavHabazin
    TomislavHabazin

    5 weeks ago

    Hello,
    I am interested how did you create model in Matlab simulink so you can generate code that is as simple as your code. I am also trying to write my own code, but have no idea how to define curves for rules. i would like to use Gauss instead of triangle shapes.

    0
    ryanescorial
    ryanescorial

    Question 1 year ago on Step 2

    Hi,

    How can I add a new input to be included in the fuzzy rules and defuzzification? Thanks in advance.

    0
    LucaR46
    LucaR46

    Question 2 years ago on Introduction

    Many thanks for this project, it literally saved me for a school project! :)

    One question: how do you translate the Matlab code into Arduino code? Because I have to do a fuzzy system with 2 output, and I cannot translate it!