How make fuzzy logic coding for arduino UNO?

Dear sir, i will make a coding of fuzzy logic with arduino UNO, this coding for aeroponic system,i have two input variabel, there are temperature and humidity, and the output is Duration of pump. So, the rules is 15 rules. Please help me for making a coding for arduino. Thx sir :slight_smile:

this is a rules of fuzzy:

  1. If (Humidity is Lembab) and (Temperatur is Dingin) then (Duration is C)

  2. If (Humidity is Lembab) and (Temperatur is Sedang) then (Duration is S)

3.If (Humidity is Lembab) and (Temperatur is Hangat) then (Duration is AS)

4.If (Humidity is AgakLembab) and (Temperatur is Dingin) then (Duration is

S)
5. If (Humidity is AgakLembab) and (Temperatur is Sedang) then (Duration is

AS)
6. If (Humidity is AgakLembab) and (Temperatur is Hangat) then (Duration is

SD)
7. If (Humidity is Normal) and (Temperatur is Dingin) then (Duration is AS)

  1. If (Humidity is Normal) and (Temperatur is Sedang) then (Duration is SD)

  2. If (Humidity is Normal) and (Temperatur is Hangat) then (Duration is AL)

  3. If (Humidity is AgakKering) and (Temperatur is Dingin) then (Duration

is SD)
11. If (Humidity is AgakKering) and (Temperatur is Sedang) then (Duration

is AL)
12. If (Humidity is AgakKering) and (Temperatur is Hangat) then (Duration

is LY)
13. If (Humidity is Kering) and (Temperatur is Dingin) then (Duration is

AL)
14. If (Humidity is Kering) and (Temperatur is Sedang) then (Duration is

LY)
15. If (Humidity is Kering) and (Temperatur is Hangat) then (Duration is L)

Are the input variables actual numeric values to be translated into those words or are they already received as those words?
Do you plan on receiving them as words through, say a serial port, or numbers?
Or do you just want to know the logic behind setting Duration?

Verry fuzzy!

How about a proportional control? More temperature = more duration.

I have no idea what the non-english words mean, but if they are the names of variables I don't see anything fuzzy in Reply #1. It should convert directly into Arduino IF statements.

On the other hand if the words represent actions (e.g. rising or turning) you will need to provide a translation.

...R

Google Translate recognizes the words as Indonesian:

Dingin = cold
Sedang = moderate
Hangat = warm

Lembab = damp
Agak Lembab = somewhat damp
Agak Kering = somewhat dry
Kering = dry

johnwasser:
Google Translate recognizes the words as Indonesian:

Those words don't seem to be fuzzy. Each one could be assigned a number.

...R

Oops. I forgot NORMAL humidity. That gives you three levels of temperature and five levels of dampness. You can use a two-dimensional array to pick the proper 'Duration' once you classify the two inputs.

Lembab
damp
AgakLembab
somewhat damp
Normal AgakKering
somewhat dry
Kering
dry
Dingin
cold
C S AS SD AL
Sedang
moderate
S AS SD AL LY
Hangat
warm
AS SD AL LY L

Thank you all for help me... :slight_smile: i was make a rules, and i was make a coding for arduino.. but there are some problem and error again. There are "expected initialized before "." token."
here a picture and here the coding... please help me sir why error like that :frowning: thx

// 
//   FILE:  dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//
#include <dht11.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht11 DHT;
#define DHT11_PIN 6

long val = 0;

void spraytime(int,int);
void fuzzy(void);

boolean DHT.temperature;
boolean DHT.humidity;

int relaypompa = 9;               // pin 9 Arduino dihubungkan dengan pin SIGNAL modul Relay
int relaykipas = 10;               // pin 10 Arduino dihubungkan dengan pin SIGNAL modul Relay

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
  
  lcd.begin(16, 2);
   /*Serial.begin(115200); // Open serial connection to report values to host
   Serial.println("Starting up");*/
   //set the cursor to column 0, line 1
   // (note: line 1 is the second row, since counting begins with 0):
   lcd.setCursor(0, 1);
   lcd.print("Starting up...");
   delay(2000);
   lcd.clear();
   
   pinMode(relaypompa, OUTPUT);        // pin 9 sebagai output
   pinMode(relaykipas, OUTPUT);        // pin 10 sebagai output
}

void loop()
{
  int chk;
  Serial.print("DHT11, \t");
  chk = DHT.read(DHT11_PIN);    // READ DATA
  switch (chk)
  {
    case DHTLIB_OK:  
                Serial.print("OK,\t"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.print("Checksum error,\t"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.print("Time out error,\t"); 
                break;
    default: 
                Serial.print("Unknown error,\t"); 
                break;
  }
 //print to lcd
   lcd.setCursor(0, 1);
   lcd.print("Temp:       C");
   lcd.setCursor(7, 1);
   lcd.print(DHT.temperature,2);
   lcd.setCursor(0, 0);
   lcd.print("Humid:      %");
   lcd.setCursor(7, 0);
   lcd.print(DHT.humidity,2);
   
  delay(2000);
 }

      val = digitalRead(DHT.temperature);    // read the value from the sensor
      val = digitalRead(DHT.humidity);    // read the value from the sensor
    
    void spraytime(int count,int del)
    {
      digitalWrite(relaypompa, LOW);
      digitalWrite(relaykipas, LOW);
      delay(del);
      digitalWrite(relaypompa, HIGH);
      digitalWrite(relaykipas, HIGH);
      delay(del);
    } 
 
  void fuzzy(void)
  {
    if (DHT.temperature>=25&&DHT.temperature<=27)
      {   // Jika suhunya lebih dari atau sama dengan 30 derajat 
           if(DHT.humidity>=70%%DHT.humidity<=73)
           spraytime(1,420000);
           else if(DHT.humidity>=71&&DHT.humidity<=75)
           spraytime(1,360000);
           else if(DHT.humidity>=73&&DHT.humidity<=77)
           spraytime(1,300000);
           else if(DHT.humidity>=75&&DHT.humidity<=79)
           spraytime(1,180000);
           else if(DHT.humidity>=77&&DHT.humidity<=80)
           spraytime(1,120000);
     }
     else if(DHT.temperature>=26&&DHT.temperature<=29)
     {
           if(DHT.humidity>=70%%DHT.humidity<=73)
           spraytime(1,540000);
           else if(DHT.humidity>=71&&DHT.humidity<=75)
           spraytime(1,420000);
           else if(DHT.humidity>=73&&DHT.humidity<=77)
           spraytime(1,360000);
           else if(DHT.humidity>=75&&DHT.humidity<=79)
           spraytime(1,300000);
           else if(DHT.humidity>=77&&DHT.humidity<=80)
           spraytime(1,180000);
     }
     else if(DHT.temperature>=28&&DHT.temperature<=30)
     {
           if(DHT.humidity>=70%%DHT.humidity<=73)
           spraytime(1,600000);
           else if(DHT.humidity>=71&&DHT.humidity<=75)
           spraytime(1,540000);
           else if(DHT.humidity>=73&&DHT.humidity<=77)
           spraytime(1,420000);
           else if(DHT.humidity>=75&&DHT.humidity<=79)
           spraytime(1,360000);
           else if(DHT.humidity>=77&&DHT.humidity<=80)
           spraytime(1,300000);
     }
     delay(2000);
  }

Robin2:
Those words don't seem to be fuzzy. Each one could be assigned a number.

...R

yes, every membership function have range of number, there are my reply posting above.. thx sir :slight_smile:

johnwasser:
Oops. I forgot NORMAL humidity. That gives you three levels of temperature and five levels of dampness. You can use a two-dimensional array to pick the proper 'Duration' once you classify the two inputs.

Lembab
damp
AgakLembab
somewhat damp
Normal AgakKering
somewhat dry
Kering
dry
Dingin
cold
C S AS SD AL
Sedang
moderate
S AS SD AL LY
Hangat
warm
AS SD AL LY L

Yes sir, my result rules like that, thx :slight_smile:
help me for my reply post above, there are some problem again sir, why like that? :frowning:

Rd_Vergiansyah:
there are some problem and error again. There are "expected initialized before "." token."
here a picture and here the coding... please help me sir why error like that

My guess would be that the DHT11 library is not installed properly or is not being used properly. Did the library come with any example sketches? They would be in the menu File->Examples->dht11->

johnwasser:
My guess would be that the DHT11 library is not installed properly or is not being used properly. Did the library come with any example sketches? They would be in the menu File->Examples->dht11->

i have the library from this forum, about dht11 sensor with fuzzy logic on arduino, i copy and paste the code to my IDE and the result is like that. Yes the library with any examples sketches sir.

Rd_Vergiansyah:
yes, every membership function have range of number, there are my reply posting above.. thx sir :slight_smile:

Sorry, but I don't see that. Which reply are you referring to?

...R