Air Quality Sensor
Analog
input
Small RAM
2.0.1
#Description
This sensor reflects the air quality. It can respond to carbon monoxide, alcohol, acetone, thinner, formaldehyde, and other slightly toxic gases.
#Links
#Units
- Percent%
#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
| Option | Type | Required | Description |
|---|---|---|---|
invert | boolean | optional | — |
pin | AnalogPin | required | — |
minValue | number | optional | — |
maxValue | number | optional | — |
threshold | number | optional | — |
#Methods
get value→ number | undefinedfrom ComponentBaseGet 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)| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
pin | uint8_t | required |
evtChange | uint8_t | required |
threshold | int | 5 |
intervalMs | uint16_t | 5 |
minEmitIntervalMs | uint16_t | 20 |
quantizeStep | int | 0 |
invert | bool | false |
#Methods
value()→ intMost recent sampled value (may change even if not emitted yet)
emittedValue()→ intThe value that was last emitted with evtChange (use this in handlers!)
See the AnalogSensor reference for the full API.