unsigned long lastupdate = 0;
bool relay = false;

void setup() {
  Serial.begin(115200);
  pinMode(18, OUTPUT);
  pinMode(26, INPUT);
  pinMode(27, INPUT);
}

void loop() {
  int ph1_v = analogRead(26);
  int ph2_v = analogRead(27);

  int ph1 = map(ph1_v, 0, 4095, 0, 14);
  int ph2 = map(ph2_v, 0, 4095, 0, 14);

  Serial.println(ph1);
  // Serial.println(ph2);

  if (ph1 == ph2) {
    digitalWrite(18, HIGH);
  } else {
    digitalWrite(18, LOW);
  }

  if (ph1 < 6.5 || ph1 > 9) {
    if (relay == false) {
      relay = true;
      Serial.println("Valve On");
    }
  }
  if(relay == true){
    if (millis() - lastupdate > 10000) {
        relay = false;
        Serial.println("Valve Off");
        lastupdate = millis();
      }
  }

  delay(300);
}