-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motion Detection NN0.2(1)
95 lines (91 loc) · 2.15 KB
/
Motion Detection NN0.2(1)
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
//Motion Detection Network
//of Motion-Based Infrared Sensors depended on
//light intensity controlled by Photoresistor(LDR)
//and work independent under more light
//by Serdar Erişen ([email protected]) - CC BY 3.0
//First generated 09/03/2018
//Update(1) 10/03/2018 NN0.1
int LDR = A0;
int LED1 = 2;
int LED2 = 3;
int PIR1 = 5;
int PIR2 = 6;
int PIR3 = 7;
int PIR4 = 8;
int RGBg = 11;
int RGBb = 12;
int RGBr = 13;
int pirState1;
int pirState2;
int pirState3;
int pirState4;
int ldrValue;
int MD1;
int MD2;
void setup() {
Serial.begin(9600);
pinMode(PIR1, INPUT);
pinMode(PIR2, INPUT);
pinMode(PIR3, INPUT);
pinMode(PIR4, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(RGBg, OUTPUT);
pinMode(RGBb, OUTPUT);
pinMode(RGBr, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(RGBr, LOW);
digitalWrite(RGBb, LOW);
digitalWrite(RGBg, LOW);
}
void loop(){
ldrValue = analogRead(LDR);
Serial.print("Analog reading = ");
Serial.println(ldrValue);
if (ldrValue < 340) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(RGBr, HIGH);
digitalWrite(RGBb, LOW);
digitalWrite(RGBg, LOW);
}
else {
pirState1 = digitalRead(PIR1);
pirState2 = digitalRead(PIR2);
pirState3 = digitalRead(PIR3);
pirState4 = digitalRead(PIR4);
if (pirState1==HIGH or pirState2==HIGH) {
int MD1 = 1;
digitalWrite(LED1, HIGH);
digitalWrite(RGBr, LOW);
digitalWrite(RGBb, HIGH);
digitalWrite(RGBg, LOW);
delay(1000);
Serial.print("MD1 = ");
Serial.println(MD1);
digitalWrite(LED1, LOW);
delay(500);
}
else if(pirState3==HIGH or pirState4==HIGH){
int MD2 = 1;
digitalWrite(LED2, HIGH);
digitalWrite(RGBr, LOW);
digitalWrite(RGBb, LOW);
digitalWrite(RGBg, HIGH);
delay(1000);
Serial.print("MD2 = ");
Serial.println(MD2);
digitalWrite(LED2, LOW);
delay(500);
}
else {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(RGBr, LOW);
digitalWrite(RGBb, LOW);
digitalWrite(RGBg, LOW);
int MD1 = 0; int MD2 = 0;
}
}
}