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

See also:


  • pin A Number or String address for the pin.

  • options An object of property parameters.

    pinNumber, StringAny Pin. The Number or String address of the Relay pinyes
    typeString“NO”, “NC”. Normally Open or Normally Closed.“NO”no


Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinThe pin value.No
isOntrue or false.Yes
type"NO" or "NC".Yes

Component Initialization

Normally Open (default)

// Pin only
new five.Relay(10);

// Options object with pin property
// Defaults to Normally Open: "NO"
new five.Relay({
  pin: 10

Relay Open

Normally Closed

// Options object with pin and type properties
new five.Relay({
  pin: 10, 
  type: "NC"



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();
  // OR...
  // relay.close();
    relay: relay


  • open() Open the circuit.

  • close() Close the circuit.

  • toggle() Toggle the circuit open/close.


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


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