The Thermometer
class constructs objects that represents a single Thermometer/Temperature sensor attached to the physical board.
Johnny-Five currently supports several kinds of Thermometer/Temperature sensors:
- Analog (with user-supplied
toCelsius(raw)
function) - LM35
- TMP36
- TMP102
- DS18B20 (requires ConfigurableFirmata)
- MPU6050
- Grove Thermometer
- BMP180
- BMP280
- BME280
- MPL115A2
- MPL3115A2
- HTU21D
- HIH6130
- MCP9808
- SI7020
- SI7021
- MS5611
- TH02
- DHT11 (Via I2C Backpack)
- DHT21 (Via I2C Backpack)
- DHT22 (Via I2C Backpack)
- SHT31D
- LSM303C
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, MCP9808, SI7020, SI7021, LSM303C. 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 overrideno freq Number Milliseconds. The rate in milliseconds to emit the data event 25ms no enabled boolean Whether to start emitting events right away (>= v0.11) true
no
1 Yes for analog devices. No for digital devices (MPU6050 or DS18B20)
Shape
Property Name | Description | Read Only |
---|---|---|
id | A user definable id value. Defaults to a generated uid | No |
celsius | The temperature in celsius degrees. | Yes |
fahrenheit | The temperature in fahrenheit degrees. | Yes |
kelvin | The temperature in kelvin degrees. | Yes |
C | A convenience alias for celsius. | Yes |
F | A convenience alias for fahrenheit. | Yes |
K | A convenience alias for kelvin. | Yes |
freq | The rate in milliseconds to emit the data event. Disables the event if set to null . (>= v0.11) | No |
Component Initialization
Analog
// Create an analog Thermometer object:
new five.Thermometer({
pin: "A0",
toCelsius: function(raw) { // optional
return (raw / sensivity) + offset;
}
});
LM35
new five.Thermometer({
controller: "LM35",
pin: "A0"
});
TMP36
new five.Thermometer({
controller: "TMP36",
pin: "A0"
});
TMP102
new five.Thermometer({
controller: "TMP102"
});
DS18B20
new five.Thermometer({
controller: "DS18B20",
pin: "A0"
});
MPU6050
// Create an MPU-6050 Thermometer object:
//
// - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
// - specify the MPU6050 controller
new five.Thermometer({
controller: "MPU6050"
});
MPL115A2
new five.Thermometer({
controller: "MPL115A2"
});
MPL3115A2
new five.Thermometer({
controller: "MPL3115A2"
});
BMP180
new five.Thermometer({
controller: "BMP180"
});
HTU21D
new five.Thermometer({
controller: "HTU21D"
});
HIH6130
new five.Thermometer({
controller: "HIH6130"
});
MCP9808
new five.Thermometer({
controller: "MCP9808"
});
MS5611
new five.Thermometer({
controller: "MS5611"
});
TH02
new five.Thermometer({
controller: "TH02"
});
DHT11_I2C_NANO_BACKPACK
new five.Thermometer({
controller: "DHT11_I2C_NANO_BACKPACK"
});
DHT21_I2C_NANO_BACKPACK
new five.Thermometer({
controller: "DHT21_I2C_NANO_BACKPACK"
});
DHT22_I2C_NANO_BACKPACK
new five.Thermometer({
controller: "DHT22_I2C_NANO_BACKPACK"
});
SI7020
new five.Thermometer({
controller: "SI7020"
});
SI7021
new five.Thermometer({
controller: "SI7021"
});
LSM303C
// Create an LSM303C Thermometer object:
//
// - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
// - specify the LSM303C controller
new five.Thermometer({
controller: "LSM303C"
});
Usage
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var temperature = new five.Thermometer({
pin: "A0"
});
temperature.on("data", function() {
console.log("celsius: %d", this.C);
console.log("fahrenheit: %d", this.F);
console.log("kelvin: %d", this.K);
});
});
API
enable() Start emitting "data" and "change" events, at a rate determined by the user defined
freq
in milliseconds. No-op if Thermometer is already enabled. (>= v0.11)disable() Stop emitting "data" and "change" events. No-op if Thermometer is already disabled. (>= v0.11)
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)
Examples
- IMU - LSM303C
- IMU - MPU6050
- IMU - BNO055
- Multi - MPL115A2
- Multi - MPL3115A2
- Multi - BME280
- Multi - BMP180
- Multi - BMP085
- Multi - HTU21D
- Multi - SHT31D
- Multi - HIH6130
- Multi - DHT11_I2C_NANO_BACKPACK
- Multi - DHT21_I2C_NANO_BACKPACK
- Multi - DHT22_I2C_NANO_BACKPACK
- Multi - TH02
- Multi - SI7020
- Multi - SI7021
- Multi - MS5611
- Thermometer - TMP36
- Thermometer - TMP102
- Thermometer - LM35
- Thermometer - LM335
- Thermometer - DS18B20
- Thermometer - Dual DS18B20
- Thermometer - MAX31850
- Thermometer - MPU6050
- Thermometer - HTU21D
- Thermometer - SHT31D
- Thermometer - HIH6130
- Thermometer - MCP9808
- Barometer - MPL3115A2
- Altimeter - MPL3115A2
- Thermometer - MPL3115A2
- Thermometer - MPL115A2
- Thermometer - BMP180
- Thermometer - BMP085
- Thermometer - SI7020
- Thermometer - SI7021
- Thermometer - MS5611
- Thermometer - TH02
- Thermometer - DHT11_I2C_NANO_BACKPACK
- Thermometer - DHT21_I2C_NANO_BACKPACK
- Thermometer - DHT22_I2C_NANO_BACKPACK
- Intel Edison + Grove - Humidity & Temperature (TH02)
- Intel Edison + Grove - RGB LCD temperature display
- Grove - RGB LCD temperature display
- TinkerKit - Temperature