Skip to content

ludufre/ens160-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A Node.js I2C module for the Adafruit ENS160 MOX Gas Sensor.

Resources

License

Stars

Watchers

Forks

Packages

No packages published