ens160-sensor
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

ens160-sensor

A Node.js I2C module for the Adafruit ENS160 MOX Gas Sensor, inspired on aht20-sensor.

Installation

npm install ens160-sensor

Example

const { default: ENS160 } = require('ens160-sensor');

ENS160.open()
  .then(async (sensor) => {
    await sensor.temperature_compensation(25); // 25C is the default
    await sensor.humidity_compensation(50); // 50% is the default

    while (true) {
      try {
        console.log(`AQI (1-5): ${await sensor.AQI()}`);
        console.log(`TVOC (ppb): ${await sensor.TVOC()}`);
        console.log(`eCO2 (ppm): ${await sensor.ECO2()}`);
        console.log(`Device Status: ${(await sensor.status()).status}`);
      } catch (err) {
        console.error("Failed to get sensor data.");
      }
      await sleep(1000);
    }
  })
  .catch((err) => {
    console.error("Failed to open bus.");
  });

const sleep = (duration) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, duration);
  });
};

Wiring

Wiring can be found here: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-ens160-mox-gas-sensor.pdf

Package Sidebar

Install

npm i ens160-sensor

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

47.2 kB

Total Files

9

Last publish

Collaborators

  • ludufre