-
Notifications
You must be signed in to change notification settings - Fork 0
/
void_loop.cpp
103 lines (93 loc) · 2.45 KB
/
void_loop.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
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
//looping conditon for checking status of system.
void loop()
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
//Ultrasonic sensor
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration = pulseIn(echoPin1, HIGH);
dist1 = Speed*duration/2;
if(dist1<200)
{
digitalWrite(led1,HIGH);
}
else
{
digitalWrite(led1, LOW);
}
digitalWrite(trigPin2, LOW);
delayMicroseconds(200);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(300);
digitalWrite(trigPin2, LOW);
duration = pulseIn(echoPin2, HIGH);
dist2 = Speed*duration/2;
if(dist2<10)
{
digitalWrite(led2,HIGH);
}
else
{
digitalWrite(led2, LOW);
}
//IR Sensor Code
int statusSensor = digitalRead (IRSensor);
if(statusSensor == 1)
{
digitalWrite(led3,HIGH);
delay(100); //Setting the delay time, 1 sec
digitalWrite(led3,LOW);
delay(100); //Setting the delay time, 1 sec
}
else
{
digitalWrite(led3,LOW);
}
//Water Sensor
waterVal= analogRead(waterSens);
if(waterVal<=600)
{
digitalWrite(led4,HIGH);
delay(100); //Setting the delay time, 1 sec
digitalWrite(led4,LOW);
delay(100); //Setting the delay time, 1 sec
}
else
{
digitalWrite(led4,LOW);
}
//PIR Sensor
val = digitalRead(PIRsensor); // read sensor value
if (val == HIGH)
{ // check if the sensor is HIGH
digitalWrite(led5, HIGH); // turn LED5 ON
delay(500); // delay 100 milliseconds
if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led5, LOW); // turn LED5 OFF
delay(500); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}