Skip to main content

Temperature Sensor

Analog
input
Small RAM
0.1.0

#Description

The temperature sensor measures the temperature, which can be output in °C, °F, or K.

When working with the raw value, be aware that the value is not mapped linearly to °C, °F, or K. Please refer to the Grove Wiki to see how the value is transformed.

#Units

  • Percent%
  • Celsius°C
  • Fahrenheit°F
  • KelvinK

#Aliases

  • Thermistor

#Functions



#JavaScript / Node.js

Base class for analog input components that read continuous values (e.g. potentiometer, light sensor). Reads analog pins (A0–A5) and emits `change` events when the value shifts beyond a configurable threshold.

#Constructor options

OptionTypeRequiredDescription
invertbooleanoptional—
pinAnalogPinrequired—
minValuenumberoptional—
maxValuenumberoptional—
thresholdnumberoptional—

#Methods

get value→ number | undefinedfrom ComponentBase

Get the current value of the component.

#Example

JavaScript
import { Board, AnalogSensor } from "@blokdots/components";

const board = new Board("/dev/ttyACM0");
await board.open();

const analogSensor = new AnalogSensor({ board, pin: "A0" });

analogSensor.on("change", (value) => {
  console.log("AnalogSensor changed:", value);
});

See the AnalogSensor reference for the full API including all methods and events.



#C++ (Arduino)

Generic analog input with thresholded "change" events (potentiometer-style)

#Setup

C++
#include "blokdots.h"

AnalogSensor myComponent(eventBus, 5, MY_EVENT);

#Constructor

AnalogSensor(bus, pin, evtChange, threshold, intervalMs, minEmitIntervalMs, quantizeStep, invert)
ParameterTypeDefault
busEventBusrequired
pinuint8_trequired
evtChangeuint8_trequired
thresholdint5
intervalMsuint16_t5
minEmitIntervalMsuint16_t20
quantizeStepint0
invertboolfalse

#Methods

value()→ int

Most recent sampled value (may change even if not emitted yet)

emittedValue()→ int

The value that was last emitted with evtChange (use this in handlers!)

See the AnalogSensor reference for the full API.