Barometer
#Description
This sensor is able to read the pressure in the air. You could use this, for example, to get the altitude in which your project is running.
#Links
#Units
- Celsius°C
- Fahrenheit°F
- KelvinK
- KilopascalkPa
- HectopascalhPa
- Metersm
- Feetft
#Aliases
- Air Pressure Sensor
#Functions
#JavaScript / Node.js
Barometerextends I2cComponentBaseBarometer component for reading pressure and temperature from BMP280 sensor. This is an I2C component that emits change events when values change.
#Value type
interface BarometerValue {
pressure: number; // in hPa
temperature: number; // in °C
altitude: number; // in m
}#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
frequency | number | optional | — | |
pin | I2CPinID | required | — | I2cComponentBase |
#Events
| Event | Parameters | Description |
|---|---|---|
change | value: BarometerValue | — |
#Methods
get pressure→ numberGet current pressure in hPa.
get temperature→ numberGet current temperature in °C.
get altitude→ numberGet current altitude in meters.
get i2cId→ I2CPinIDfrom I2cComponentBaseThe resolved I2C pin ID (e.g. "i2c-0"). Useful for logging or passing back to the Arduino sketch.
#Example
import { Board, Barometer } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const barometer = new Barometer({ board, pin: "example", frequency: 1000 });
barometer.on("change", (value) => {
console.log("Barometer changed:", value);
});#C++ (Arduino)
Barometric pressure + temperature sensor using Adafruit_BMP280 Emits ONE event when temp/pressure/altitude change significantly (atomic snapshot)
#Required libraries
#include <Adafruit_BMP280.h>— Adafruit BMP280 Library v2.6.8#include "SPL07-003.h"— Seeed Arduino SPA06#include <Wire.h>— Wire#include <SPI.h>— SPI
#Setup
#include "blokdots.h"
Barometer myComponent(eventBus, MY_EVENT);#Constructor
Barometer(bus, evtChange, i2cAddress, seaLevelhPa, tempThresholdC, pressureThresholdPa, altitudeThresholdM, sampleIntervalMs, minEmitIntervalMs)| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
evtChange | uint8_t | required |
i2cAddress | uint8_t | 0x77 |
seaLevelhPa | float | 1013.25f |
tempThresholdC | float | 0.2f |
pressureThresholdPa | float | 50.0f |
altitudeThresholdM | float | 0.5f |
sampleIntervalMs | uint16_t | 50 |
minEmitIntervalMs | uint16_t | 200 |
#Methods
temperatureC()→ floatpressurePa()→ floatpressurehPa()→ floataltitudeM()→ floatrawTemperatureC()→ floatOptional: most recent sample (may be newer than last event)
rawPressurePa()→ floatrawPressurehPa()→ floatrawAltitudeM()→ floataddress()→ uint8_tOptional debug helper (non-breaking addition)
setSeaLevelhPa(v)Optional: update sea level reference at runtime (no event emitted automatically)
| Parameter | Type | Default |
|---|---|---|
v | float | required |
emittedValue()→ const char*NOTE: Uses dtostrf — AVR snprintf does not support %f