-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAutomaticDoor.ino
90 lines (69 loc) · 2.04 KB
/
AutomaticDoor.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
/By Sieuwe Elferink
//config
////////////////
const int MotorDelay = 3100; //change this value to make the door open more or less
const int TimeDelay = 4000; // change this value to change the time between the door opening and closing
const int ActivationDistance = 50; //change this value to change the distance from your hand to the sensor to activate the door.
///////////////
const int trigPin = 4;
const int echoPin = 3;
const int trigPin2 = 10;
const int echoPin2 = 11;
const int ComPin = 5; //Pin for communicating with the CortanaRoom application. Check the CortanaRoom reposetory for more info!
long duration, duration2;
int distanceCm, distanceCm2;
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(ComPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distanceCm2 = duration2 * 0.034 / 2;
Serial.print(distanceCm);
Serial.print(" ");
Serial.println(distanceCm2);
if (distanceCm <= ActivationDistance) {
digitalWrite(ComPin, HIGH);
digitalWrite(8, HIGH);
delay(MotorDelay);
digitalWrite(8, LOW);
delay(TimeDelay);
digitalWrite(9, HIGH);
delay(MotorDelay);
digitalWrite(9, LOW);
delay(2000);
digitalWrite(ComPin, LOW);
}
if (distanceCm2 <= ActivationDistance) {
digitalWrite(ComPin, HIGH);
digitalWrite(8, HIGH);
delay(MotorDelay);
digitalWrite(8, LOW);
delay(TimeDelay);
digitalWrite(9, HIGH);
delay(MotorDelay);
digitalWrite(9, LOW);
delay(2000);
digitalWrite(ComPin, LOW);
}
}