The Motion class constructs an object that represents a single Motion Detection sensor.

Supported Motion sensors:

Parameters

  • pin A Number pin address for Motion sensor.

  • options An object of property parameters.

    PropertyTypeValue/DescriptionDefaultRequired
    pinNumber, StringAnalog or Digital Pin. Use for non-I2C sensorsYes (non-I2C)
    controllerStringPIR, HCSR501, GP2Y0D805Z0F, GP2Y0D810Z0F, GP2Y0D815Z0F. See aliasesPIRNo

    Controller Alias Table
    ControllerAlias
    HC-SR501PIR
    HCSR501PIR
    GP2Y0D805Z0F0D805
    GP2Y0D805Z0F805
    GP2Y0D810Z0F0D810
    GP2Y0D810Z0F810
    GP2Y0D815Z0F0D815
    GP2Y0D815Z0F815

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinThe pin address that the Sensor is attached toNo
valueSensor value.Yes
detectedMotionBoolean value.Yes
isCalibratedBoolean flag indicating calibration state.Yes

Component Initialization

Passive InfraRed Motion

This is the default controller.

// Pin only
new five.Motion(7);

// Options object with pin property
var motion = new five.Motion({
  pin: 7
});

Motion

GP2Y0D805Z0F


var motion = new five.Motion({
  controller: "GP2Y0D805Z0F"
});

Motion

GP2Y0D810Z0F and GP2Y0D815Z0F

var motion = new five.Motion({
  controller: "GP2Y0D810Z0F", 
  pin: "A0"
});

var motion = new five.Motion({
  controller: "GP2Y0D815Z0F", 
  pin: "A0"
});

Motion

Usage

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

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

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

  // "calibrated" occurs once, at the beginning of a session,
  motion.on("calibrated", function() {
    console.log("calibrated");
  });

  // "motionstart" events are fired when the "calibrated"
  // proximal area is disrupted, generally by some form of movement
  motion.on("motionstart", function() {
    console.log("motionstart");
  });

  // "motionend" events are fired following a "motionstart" event
  // when no movement has occurred in X ms
  motion.on("motionend", function() {
    console.log("motionend");
  });
});

Events

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

  • change The "change" event is fired whenever a change within the motion detection field is observed.

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

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

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

Examples

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub