-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWater_detection_Idea_4.cpp
66 lines (59 loc) · 1.38 KB
/
Water_detection_Idea_4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//This is the exact same as water_detection_3 but with the LCD screen to display the messages
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 2, 3, 4, 5);
int check, lever;
int buzzerPin = 8, leverPin = A4, leakPin = A5;
#include <LiquidCrystal.h>
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
pinMode(leverPin,INPUT);
pinMode(leakPin,INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// digitalWrite(5,HIGH);
check = analogRead(leakPin);
lever = analogRead(leverPin);
Serial.print("Check:");
Serial.println(check);
Serial.print("Lever:");
Serial.println(lever);
if(check > 0 && lever == 0)
{
lcd.clear();
lcd.print("Leak detected");
tone(buzzerPin, 1000);
}
else if(check > 0 && lever > 0 && lever < 200)
{
lcd.clear();
lcd.print("Faucet Left Open");
tone(buzzerPin,4500,200);
tone(buzzerPin,6000,200);
}
else if(check == 0 && lever > 200)
{
lcd.clear();
lcd.print("Error, check");
lcd.setCursor(0, 1);
lcd.print("sensor & water");
lcd.setCursor(0, 0);
noTone(buzzerPin);
}
else if(check > 0 && lever > 200 )
{
lcd.clear();
lcd.print("Normal Operation");
noTone(buzzerPin);
}
else
{
lcd.clear();
lcd.print("Normal Operation");
noTone(buzzerPin);
}
delay(500);
}