Skip to content
Rick Waldron edited this page Mar 2, 2015 · 18 revisions

The Relay class constructs objects that represent a single digital Relay attached to the physical board.

Parameters

  • pin A Number or String address for the pin.

  • options An object of property parameters.

    Property Type Value(s) Description Required
    pin Number, String Any Pin The Number or String address of the Relay pin yes
    type String “NO”, “NC” Normally Open or Normally Closed. Defaults to “NO” no

Shape

{ 
  id: A user definable id value. Defaults to a generated uid
  pin: The pin value.
  isOn: true|false. READONLY
  type: "NO" or "NC". READONLY
}

Component Initialization

Normally Open (default)

// Pin only
var relay = new five.Relay(10);

// Options object with pin property
var relay = new five.Relay({
  pin: 10
});

Relay

Normally Closed

// Options object with pin and type properties
var relay = new five.Relay({
  pin: 10, 
  type: "NC"
});

Relay

Usage

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

board.on("ready", function() {
  var relay = new five.Relay(10);

  // Control the relay in real time
  // from the REPL by typing commands, eg.
  //
  // relay.on();
  //
  // relay.off();
  //
  // OR...
  //
  // relay.open();
  //
  // relay.close();
  //
  this.repl.inject({
    relay: relay
  });
});

API

  • open() Open the circuit.

  • close() Close the circuit.

  • toggle() Toggle the circuit open/close.

Events

Relay objects are output only and therefore do not emit any events.

Clone this wiki locally