-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautolif.ino
171 lines (151 loc) · 2.84 KB
/
autolif.ino
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
int DOPin = 2;
int greenLed=6;
int redLed =7;
int buzzer =9;
int led1=13;
int led2=12;
int kk11=13;
int kkk122=12;
int water = A0; //water Pin
int ldrPin = A1; // select the input pin for LDR
int ldrvalue = 0;
int pir=3; //pir pin
int pirState = LOW;
int ps = LOW;
int val = 0;
int count = 0;
int wl=0;
int prev=0;
int current=0;
char c;
String st;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(DOPin, INPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(pir, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(water, INPUT );
Serial.begin(9600);
}
void pirsen()
{
ldrvalue = analogRead(ldrPin);
Serial.println(ldrvalue);
if( ldrvalue > 50) //day
{
val = digitalRead(pir);
if (val == HIGH)
{
digitalWrite(greenLed, HIGH);
if (pirState == LOW)
{
Serial.println("Motion detected!");
pirState = HIGH; }
} else {
digitalWrite(greenLed, LOW); // turn LED OFF
if (pirState == HIGH)
{
Serial.println("Motion ended!");
pirState = LOW;
count++;
}
}
if ((count%2)!=0)
{
if (ps == LOW)
{
digitalWrite(led1, HIGH);
digitalWrite(led2,HIGH);
ps = HIGH;
}
}
else
{
if (ps == HIGH)
{
digitalWrite(led1, LOW);
digitalWrite(led2,LOW);
ps = LOW;
}
}
}
else if( ldrvalue <= 50 ) //night
{
val = digitalRead(pir);
if (val == HIGH)
{
digitalWrite(greenLed, HIGH);
if (pirState == LOW)
{
Serial.println("Infiltration");
tone(buzzer,1000);
delay(1000);
pirState = HIGH;
}
} else {
digitalWrite(greenLed, LOW); // turn LED OFF
if (pirState == HIGH)
{
Serial.println("Infiltration Done");
pirState = LOW;
}
}
}
}
void gassen()
{
if (digitalRead(DOPin) == LOW) //GAS
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer,1000,500);
Serial.println("Gas leak = ON");
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(1000);
}
void watersen()
{
if(analogRead(water)>=200)
{
tone(buzzer,1000,500);
Serial.println("Tank Full !!!");
}
delay(500);
}
void loop() {
pirsen();
gassen();
watersen();
while(Serial.available() > 0) //For Bluetooth
{
delay(10);
c = Serial.read();
if(c=='#')
{break;}
st+=c;
}
if(st.length() > 0)
{
if(st.equalsIgnoreCase("*All On"))
{
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
}
if(st.equalsIgnoreCase("*All Off"))
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
}
st="";
}
}