Sebuahhobi98

water level

Sep 19th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. int pinSensor = A5;
  2. float panjangSensor = 4.0 ;
  3. void setup() {
  4.   Serial.begin(9600);
  5.   Serial.println("Mengukur Ketinggian Air");
  6.   delay(500);
  7. }
  8. void loop() {
  9.   int nilai = analogRead(pinSensor);
  10.   if (nilai == 0) {
  11.     Serial.println("Air tidak terdeteksi");
  12.   } else {
  13.     float tinggiAir = nilai * panjangSensor / 1023;
  14.     Serial.print("Tinggi Air = ");
  15.     Serial.print(tinggiAir);
  16.     Serial.println(" cm");
  17.     Serial.println(nilai);
  18.    
  19.   }
  20.   delay(5000);
  21.   Serial.println();
  22. }
Add Comment
Please, Sign In to add comment