-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final_Code.ino
157 lines (146 loc) · 2.94 KB
/
Final_Code.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
#include <IRremote.h>
#define trigPin 13
#define echoPin 12
#define motor 7
#define buzzer 6
#define RECV_PIN 5
int x=0;
long l;
IRrecv irrecv(RECV_PIN);
decode_results results;
long base = 0x800;// base value for a another TV Remote
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
//Water Sensor code
int sensor=analogRead(A0);
if (sensor>325)
{
digitalWrite(motor, HIGH);
}
else
{
digitalWrite(motor, LOW);
}
//Ultrasonic Sensor code
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if(distance>=90)
{
for(x=100-distance;x>=0;x--)
{
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(110);
}
}else if(distance<90 & distance>=80)
{
for(x=100-distance;x>=10;x--)
{
digitalWrite(buzzer, HIGH);
delay(90);
digitalWrite(buzzer, LOW);
delay(100);
}
}else if(distance<80 & distance>=70)
{
for(x=100-distance;x>=20;x--)
{
digitalWrite(buzzer, HIGH);
delay(80);
digitalWrite(buzzer, LOW);
delay(90);
}
}else if(distance<70 & distance>=60)
{
for(x=100-distance;x>=30;x--)
{
digitalWrite(buzzer, HIGH);
delay(70);
digitalWrite(buzzer, LOW);
delay(80);
}
}else if(distance<60 & distance>=50)
{
for(x=100-distance;x>=40;x--)
{
digitalWrite(buzzer, HIGH);
delay(60);
digitalWrite(buzzer, LOW);
delay(70);
}
}else if(distance<50 & distance>=40)
{
for(x=100-distance;x>=50;x--)
{
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
delay(60);
}
}else if(distance<40 & distance>=30)
{
for(x=100-distance;x>=60;x--)
{
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
delay(50);
}
}else if(distance<30 & distance>=20)
{
for(x=100-distance;x>=70;x--)
{
digitalWrite(buzzer, HIGH);
delay(30);
digitalWrite(buzzer, LOW);
delay(40);
}
}else if(distance<20 & distance>=10)
{
for(x=100-distance;x>=80;x--)
{
digitalWrite(buzzer, HIGH);
delay(20);
digitalWrite(buzzer, LOW);
delay(30);
}
}else if(distance<10)
{
for(x=100-distance;x>=90;x--)
{
digitalWrite(buzzer, HIGH);
delay(10);
digitalWrite(buzzer, LOW);
delay(20);
}
}
delay(5);
//IR sensor code
flag=irrecv.decode(&results);
if (flag)
{
l = results.value;
if (l==12)
{
digitalWrite(buzzer, HIGH);// reduce the code to base zero.
delay(50);
}
delay(100);
irrecv.resume(); // Receive the next value
}
}