#define echoPin 7
#define trigPin 8
int ledRed = 3;
int ledYellow = 2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(ledRed, OUTPUT);
  pinMode(ledYellow, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  long jarak, ketinggianAir, duration;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  jarak = (duration/2) / 28.5;
  ketinggianAir = 18.5 - jarak;
  Serial.println("Ketinggian Air = ");
  Serial.print(ketinggianAir);
  Serial.println(" cm");
  if (ketinggianAir < 5){
    digitalWrite(ledYellow, HIGH);
    digitalWrite(ledRed, LOW);
    Serial.println("Air tersedia");
  }else if (ketinggianAir > 5) {
    digitalWrite(ledYellow, LOW);
    digitalWrite(ledRed, HIGH);
    Serial.println("Air habis");
  }
  delay(2000);

}