Alat pengukur ketinggian air dengan Ultrasonic

Alat pengukur ketinggian air dengan Ultrasonic

pengukur ketinggain air

Alat dan Bahan

  1. ARDUINO UNO BOARD 
  2. LED merah, kuning, ijo, dan biru
  3. sensor Ultrasonic
  4. kaber jumper
  5. breadboard

 

skema pengukur ketinggain air

Code program

const int trig = 2, echo = 3;
long duration, Distanceincm;
void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
}

void loop() {
  digitalWrite(trig, HIGH);
  delay(15);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  // modul ultrasonic diletakkan 20cm diatas tangki  1m.
  Distanceincm = (duration / 58) - 20;
  if (Distanceincm < 25) {  // Above three quarter
    digitalWrite(11, HIGH);
  }
  else {
    digitalWrite(11, LOW);  // Below three quarter
  }
  //
  if (Distanceincm < 50) {  // Above half level
    digitalWrite(10, HIGH);
  }
  else {
    digitalWrite(10, LOW);  // Below half level
  }
  if (Distanceincm < 75) {
    digitalWrite(9, HIGH);  // Above quarter level
  }
  else {
    digitalWrite(9, LOW);   // Below quarter level
  }
  //Below quarter level, only LED at pin 8 will be ON.
}

Leave a Reply

Your email address will not be published. Required fields are marked *