-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathpir.js
52 lines (39 loc) · 1.21 KB
/
pir.js
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
var arduino = require('../'),
board, pir;
board = new arduino.Board({
debug: false
}).setup();
pir = new arduino.PIR({
board: board,
pin: 7
});
// 'calibrated' event fired when PIR sensor is
// ready to detect movement/motion in observable range
//
// All events receive error and date arguments
pir.on('calibrated', function(err, date) {
console.log('calibrated');
// Current sensor data stored in properties
// of this PIR instance:
//
// this.state - current state of motion
// 0 No motion currently detected
// 1 Motion currently detected
// 'motionstart' event fired when motion occurs
// within the observable range of the PIR sensor
this.on('motionstart', function(err, date) {
console.log('motionstart', this.state);
console.log( date );
});
// 'motionend' event fired when motion has ceased
// within the observable range of the PIR sensor
this.on('motionend', function(err, date) {
console.log('motionend', this.state);
});
});
// To test, use the following:
// http://www.ladyada.net/images/sensors/pirardbb.gif
// http://bildr.org/blog/wp-content/uploads/2011/06/PIR-Arduino_hookup.png
//
// More information:
// http://www.ladyada.net/learn/sensors/pir.html