Skip to content
Rick Waldron edited this page Nov 10, 2015 · 27 revisions

The Temperature class constructs objects that represent a single Temperature sensor attached to the physical board.

Johnny-Five currently supports several kinds of Temperatures:

This list will continue to be updated as more devices are confirmed.

Parameters

  • General Options

    Property Type Value/Description Default Required
    controller string ANALOG, LM35, TMP36, DS18B20, MPU6050, GROVE, BMP180, MPL115A2, MPL3115A2, HTU21D. The Name of the controller to use. “ANALOG” no
    pin string or int Analog Pin. Use with analog sensor. Yes1
    toCelsius function function toCelsius(raw) {} A raw-to-celsius transform override no
    freq Number Milliseconds. The rate in milliseconds to emit the data event 25ms no

1 Yes for analog devices. No for digital devices (MPU6050 or DS18B20)

Shape

{ 
  id: A user definable id value. Defaults to a generated uid
  pin: The pins defined for X, Y, and Z.
  celsius: The temperature in celsius degrees. READONLY
  fahrenheit: The temperature in fahrenheit degrees. READONLY
  kelvin: The temperature in kelvin degrees. READONLY
  C: A convenience alias for celsius.
  F: A convenience alias for fahrenheit.
  K: A convenience alias for kelvin.
}

Component Initialization

Analog

// Create an analog Temperature object:
new five.Temperature({
  pin: "A0",
  toCelsius: function(raw) { // optional
    return (raw / sensivity) + offset;
  }
});

LM35

new five.Temperature({
  controller: "LM35",
  pin: "A0"
});

LM35

TMP36

new five.Temperature({
  controller: "TMP36",
  pin: "A0"
});

TMP36

TMP102

new five.Temperature({
  controller: "TMP102"
});

TMP102

DS18B20

new five.Temperature({
  controller: "DS18B20",
  pin: "A0"
});

DS18B20

MPU6050

// Create an MPU-6050 Temperature object:
//
//  - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
//  - specify the MPU6050 controller
new five.Temperature({
  controller: "MPU6050"
});

MPU6050

MPL115A2

new five.Temperature({
  controller: "MPL115A2"
});

MPL115A2

MPL3115A2

new five.Temperature({
  controller: "MPL3115A2"
});

MPL3115A2

BMP180

new five.Temperature({
  controller: "BMP180"
});

BMP180

HTU21D

new five.Temperature({
  controller: "HTU21D"
});

HTU21D

HTU21D

HTU21D

HTU21D

Usage

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

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

  var temperature = new five.Temperature({
    pin: "A0"
  });

  temperature.on("change", function() {
    console.log("celsius: %d", this.C);
    console.log("fahrenheit: %d", this.F);
    console.log("kelvin: %d", this.K);
  });
});

API

There are no special API functions for this class.

Events

  • change The "change" event is emitted whenever the value of the temperature changes.

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

Clone this wiki locally