Relays just switch ON and OFF on delay(), not on millis() I use fuzzy logic for the running time of relays, but the relays just switch ON and OFF at the interval of the delay() I put at the end of loop.
This is my code:
void loop () {
  ph = -180/100.0;
  hasilec = -1.2;
  unsigned long now = millis();
  
  Serial.print(&quot;pH    &quot;);
  Serial.print(ph);
  Serial.print(&quot;  &quot;);
  Serial.print(&quot;EC &quot;);
  Serial.print(hasilec);
  Serial.println(&quot;&quot;);
  Serial.print(ph);
  Serial.print(&quot; &quot;);
  Serial.print(hasilec);
  Serial.print(&quot; &quot;);
  Serial.println(&quot; &quot;);

  fuzzy-&gt;setInput(2, hasilec);
  fuzzy-&gt;setInput(1, ph);  
  fuzzy-&gt;fuzzify();

  float pompa01 = fuzzy-&gt;defuzzify(1); //pHDOWN
  float pompa02 = fuzzy-&gt;defuzzify(2); //pHUP
  float pompa03 = fuzzy-&gt;defuzzify(3); //ABMIX
  
  long int pompa1 = pompa01 * 1000;
  long int pompa2 = pompa02 * 1000;
  long int pompa3 = pompa03 * 1000;
  
  Serial.println(&quot;Result= &quot;);
  Serial.println(&quot;&quot;);
  Serial.print(&quot; Pompa1 pHDOWN: &quot;);
  Serial.println(pompa1);
  Serial.print(&quot; pompa2 phUP  : &quot;);
  Serial.println(pompa2);
  Serial.print(&quot; pompa3 ABMIX : &quot;);
  Serial.println(pompa3);
  Serial.println(&quot;&quot;);
  Serial.println(&quot;&quot;);
  Serial.println(&quot;&quot;);
  
  pump_periods[0] = pompa1;
  pump_periods[1] = pompa2;
  pump_periods[2] = pompa3;
  
  
  for (int i = 0; i &lt; jml_pump; i++) {
    if (now - pump_last_actuations[i] &gt;= pump_periods[i]) {
      pump_states[i] = (pump_states[i] == LOW) ? HIGH : LOW;
      digitalWrite(pump_pins[i], pump_states[i]);
      pump_last_actuations[i] = now;
    }
  }   
  delay (20000);
}


The relay just switch ON and OFF on this delay delay (20000);.
What should I do?
Check the values of pompa1, pompa2, and pompa3 to see if they are always smaller than 20000 (I suspect they are).
The delay(20000) (why is it there anyway?) could well be messing up your timing of the toggling of the pump_states by always delaying longer than the values in pompa1, pompa2, and pompa3.
This would make the relays toggle every 20s (on every loop).