I have now changed the name of the variable for the timing of the pump, and moves it to where i start it, but again it only turns off the pump if it read the output value again.
if (millis() - int_tim >= 6000) { // OBS_1 <- Den her tid skal ændres i forbindelse med test, men ikke til mindre end 2000
digitalWrite(vand, HIGH);
digitalWrite(fugtighed, HIGH);
if (millis() - int_tim >= 6250) { // OBS <- Den her tid skal være 250 ms større end OBS_1
output_vand = analogRead(vand_niveau);
output_vand = map(output_vand, 0, 400, 0, 100);
output_jord = analogRead(jord);
output_jord = map(output_jord, 1023, 400, 0, 100);
//Serial.print("Moisture : ");
//lcd.print("Fugt:");
//lcd.print(output_vand);
//lcd.print("%");
//lcd.setCursor(0, 1);
//lcd.print("Plante:");
//lcd.print(output_jord);
//lcd.print("%");
//Serial.print(output_vand);
//Serial.print("%");
//lcd.clear();
int_tim = millis();
digitalWrite(vand, LOW);
digitalWrite(fugtighed, LOW);
}
}
//unsigned long currentMillis = millis();
if (output_jord < 40 // Fugtighed I plante under 40% start motor
&& output_vand > 40) { // Fugtighed I reservoir over 40% start motor
analogWrite(motor_pwm, 200);
pumpStartTime = millis();
}
else {
analogWrite (motor_pwm, 0);
}
// If the pump is "ON" and 1000 ms have elapsed, turn off the pump
if (millis() - pumpStartTime >= 1000) {
analogWrite (motor_pwm, 0);
}