Skip to content
Rick Waldron edited this page Aug 5, 2013 · 5 revisions

The IR class constructs objects that represent a single (I2C or analog) Infrared sensor attached to the physical board. This class can produce several IR relevant device instances, including:

Parameters

  • pin A Number pin address for Motion sensor.
var motion = new five.IR.Motion(7);
// I2C proximity
var proximity = new five.IR.Proximity("GP2Y0D805Z0F");

// Analog proximity
var proximity = new five.IR.Proximity("A0");
  • options An object of property parameters.
Property Name Type Value(s) Description Required
pin Number, String "A0", "I1", 5 (Any pin on board) The Number or String address of the pin the sensor is attached to, ie. "A0" or "I1" yes
freq Number Milliseconds The frequency in ms of data events. Defaults to 25ms no
```js var motion = new five.IR.Motion({ pin: 7, freq: 25 }); ``` ```js var motion = new five.IR.Proximity({ pin: "A0", freq: 25 }); ```

Shape

{ 
  id: A user definable id value. Defaults to a generated uid
  pin: The pin address that the Sensor is attached to
  freq: The frequency in ms of data reads. Defaults to 25ms
  value: Digital state reading (0 or 1). READONLY
  isCalibrated: Boolean flag indicating calibration state of motion sensor 
}

Usage

var five = require("johnny-five"), 
    board = new five.Board();

board.on("ready", function() {

  // Create a new `motion` hardware instance.
  var motion = new five.IR.Motion(7);

  motion.on("motionstart", function() {
    console.log( "Something moved!" );
  });

  motion.on("motionend", function() {
    console.log( "All quiet now..." );
  });
});
var five = require("johnny-five"), 
    board = new five.Board();

board.on("ready", function() {
 
  // Uses default GP2Y0D805Z0F
  var prox = new five.IR.Proximity();

  motion.on("motionstart", function() {
    console.log( "Something moved!" );
  });

  motion.on("motionend", function() {
    console.log( "All quiet now..." );
  });
});

Events

  • data The "data" event is fired as frequently as the user defined freq will allow in milliseconds. ("data" replaced the "read" event)

  • motionstart The "motionstart" event is fired when motion occurs within the observable range of the PIR/IR.Motion/IR.Proximity sensor

  • motionend The "motionend" event is fired when motion has ceased within the observable range of the PIR/IR.Motion/IR.Proximity sensor.

  • calibrated The "calibrated" event is fired when PIR/IR.Motion sensor is ready to detect movement/motion in observable range. (PIR/IR.Motion ONLY)

Clone this wiki locally