how to stop the relay after it is getting on and let the sensor get the result I want to provide a delay in the following iteration reading so that the sensor can read the condition after the pump starts.
void loop() {
  //-------------Fungsi Read sensor----------- 
  // sensorAll();

  hasilec = (ppmcensor - inputec);
  ph = (phcensor - inputph);
  
  //  hasilec = random(-200, 0) / 100.0;
  //  ph = random(-200, 200) / 100.0;

  //  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;);

  //  delay (500000);
  
  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
  
  Serial.println(&quot;Result= &quot;);
  Serial.println(&quot;&quot;);
  Serial.print(&quot; Pompa1 pHDOWN: &quot;);
  Serial.println(pompa01);
  Serial.print(&quot; pompa2 phUP  : &quot;);
  Serial.println(pompa02);
  Serial.print(&quot; pompa3 ABMIX : &quot;);
  Serial.println(pompa03);
  Serial.println(&quot;&quot;);
  Serial.println(&quot;&quot;);
  Serial.println(&quot;&quot;);
  
  delay (2000);
  
  long int pompa1 = pompa01 * 1000;
  long int pompa2 = pompa02 * 1000;
  long int pompa3 = pompa03 * 1000;
  
  pump_periods[0] = pompa1; //PHdown
  pump_periods[1] = pompa2; //PHup
  pump_periods[2] = pompa3; //ABMIX
  
  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;
    }    
  }   
}

If I put the delay after millis iteration it causes the pump to only turn on based on the delay, not the timer millis. What should I do?
If all the pumps have to work for pump_periods[i] time on every loop, and you will have a long delay() anyway, you could replace the for loop with:
for (int i = 0; i &lt; jml_pump; i++) { // For every pump:
  digitalWrite(pump_pins[i], 1);     // Start pump i
  delay(pump_periods[i]);            // Wait for pump_periods[i] ms
  digitalWrite(pump_pins[i], 0);     // Stop pump i
}
delay(120000);                       // Wait 2 minutes until mixed

This will block the loop, but you will have a long delay anyway. The pumps will work sequentially, and not at the same time.
Is that what you want?