Untitled
raw download clone
CPP
views 16
,
size 958 b
#include<LiquidCrystal.h>
int WaterLevel = 0;
LiquidCrystal lcd(13,12,11,10,9,8);

void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, INPUT);
}

void loop()
{
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
  delayMicroseconds(2);
  digitalWrite(4, HIGH);
  delayMicroseconds(5);
  digitalWrite(4, LOW);
  long duration, cm;  
  pinMode(4,INPUT);
  duration = pulseIn(4,HIGH);
  WaterLevel = microsecondsToCentimeters(duration);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Water: ");
  lcd.setCursor(7,0);
  lcd.print(WaterLevel);
  if (WaterLevel > 200) {
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
  }
  else{
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    tone(5,600,70);
    delay(700);
  }
  digitalWrite(5, LOW);
}

long microsecondsToCentimeters(long microseconds) {
  return microseconds/29/2;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.