/
DoOpen.txt
89 lines (75 loc) · 3.66 KB
/
DoOpen.txt
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
/******************************************************************************
DoOpen: use the ifttt "DO" button to open a door.
A relay is connected to D3. When the DO button is activated, a cloud
message is sent to a Particle device which activates the relay for
the number of milliseconds that is specified in the function call argument
that is configured on the DO button (default is 3 seconds).
An electronic strike plate is then connected to the NO contacts of the
relay to activate the door strike.
The Particle "Relay Shield" is a good fit for this project. It
accomodates a Core or Photon and has 4 relays, of which one is used
to activate the electronic door strike. It also accepts 12 VDC via
a barrel jack and supplies the 12 VDC out some screw terminals, which
can be used as the power for the electronic door strike (12 VDC
models seem to be widely available).
To set up a DO button, download and install the IFTTT "DO" app from
the App Store or Play Store. Create a DO recipe with the action
as "call a function" on the Particle IFTTT channel and select the
"OpenDoor" cloud function on your Particle device. Add the time
for the relay to close (in milliseconds) as the optional function
argument (e.g. 2000 for 2 seconds). Name this DO button "open door"
or whatever is most meaningful to you).
by: Bob Glicksman
date: 7/27/2016
(c) 2016 by Bob Glicksman. All rights reserved.
******************************************************************************/
// Global Constants
const String VERSION = "1.0";
const int BLUE_LED = D7;
const int DOOR_RELAY = D3;
const long DEFAULT_OPEN_TIME = 3000; // trip the latch for 3 seconds
/******************************setup()****************************************/
void setup() {
pinMode(DOOR_RELAY, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
Particle.function("OpenDoor", openDoor);
Particle.variable("Version", VERSION);
// blink the D7 LED to show that program is running
pulsePin(BLUE_LED, 1000);
}
/***************************end of setup()************************************/
/*******************************loop()****************************************/
void loop() {
// do nothing. The cloud function "openDoor()" is used to
// implement all of the action.
}
/***************************end of loop()**************************************/
/****************************pulsePin()****************************************
pulsePin: pulse a pin HIGH for some time and then LOW
Arguments:
pinNum: the Core/Photon pin Number
pulseTime: the duration fo the pulse, in milliseconds
*******************************************************************************/
void pulsePin(int pinNum, long pulseTime) {
digitalWrite(pinNum, HIGH);
delay(pulseTime);
digitalWrite(pinNum, LOW);
return;
}
/*************************end of pulsePin()************************************/
/****************************openDoor()****************************************
openDoor: cloud accessible function to trip a relay to open a door
Arguments:
num: the time that the door open relay is activated, in milliseconds
*******************************************************************************/
int openDoor(String num) {
long duration = num.toInt();
if (duration > 0L) { // check for a valid number
pulsePin(DOOR_RELAY, duration);
return 0;
} else { // not a number will result in 0 being returned
pulsePin(DOOR_RELAY, DEFAULT_OPEN_TIME);
return -1;
}
}
/*************************end of openDoor()************************************/