npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

scd4x-node

v1.0.1

Published

Node.js library for [Sensirion SCD40 and SCD41](https://www.sensirion.com/search/products?q=SCD4x), the CO2, temperature, and humidity sensors.

Readme

scd4x-node

Node.js library for Sensirion SCD40 and SCD41, the CO2, temperature, and humidity sensors.

The library exposes all of the commands supported by the SCD40 and SCD41, as documented in the official Datasheet.

Uses i2c-bus for connection to the sensor.

Usage

yarn add scd4x-node
const {SCD4x} = require('scd4x-node');

(async () => {
  const scd4x = await SCD4x.connect();

  try {
    await scd4x.startPeriodicMeasurement();
    // data is available 5s after starting periodic measurement
    await new Promise(resolve => setTimeout(resolve, 5000));
  } catch(e) {
    console.log('Periodic measurement already turned on')
  }

  const measurement = await scd4x.readMeasurement();
  console.log(`CO2 Concentration: ${measurement.co2Concentration} ppm`);
  console.log(`Temperature: ${measurement.temperature} °C`);
  console.log(`Humidity: ${measurement.relativeHumidity} %`);

  await scd4x.disconnect();
})();

API Documentation

Class SCD4x

public static connect(busNumber: number = DEFAULT_I2C_BUS_NUMBER): Promise<SCD4x>

Connects to the SCD4x on the given I2C bus. Default bus number is 1.

startPeriodicMeasurement(): Promise<void>

Start periodic measurement, signal update interval is 5 seconds.

readMeasurement(): Promise<Measurement>

Read a measurement of CO2 concentration, temperature, and humidity.

stopPeriodicMeasurement(): Promise<void>

Stops continuous measurement.

setTemperatureOffset(offset: number): Promise<void>

Set temperature offset to improve accuracy of temperature and relative humidity measurements. To save the setting permanently, call also persistSettings.

getTemperatureOffset(): Promise<number>

Returns the temperature offset.

setSensorAltitude(altitude: number): Promise<void>

Reading and writing of the sensor altitude must be done while the SCD4x is in idle mode. Typically, the sensor altitude is set once after device installation.

getSensorAltitude(): Promise<number>

Returns the altitude compensation value in meters.

setAmbientPressure(pressure: number): Promise<void>

Can be sent during periodic measurements to enable continuous pressure compensation. Overrides any pressure compensation based on sensor altitude.

performForcedRecalibration(co2ppm: number): Promise<number>

To successfully conduct an accurate forced recalibration, the following steps need to be carried out:

  1. Operate the SCD4x in the operation mode later used in normal sensor operation (periodic measurement, low power periodic measurement or single shot) for > 3 minutes in an environment with homogenous and constant CO2 concentration.
  2. Call stopPeriodicMeasurement.
  3. Call performForcedRecalibration and optionally read out the FRC correction (i.e. the magnitude of the correction).

setAutomaticSelfCalibrationEnabled(enable: boolean): Promise<void>

Activates or deactivates automatic self-calibration.

isAutomaticSelfCalibrationEnabled(): Promise<boolean>

Indicates whether automatic self-calibration is active.

startLowPowerPeriodicMeasurement(): Promise<void>

Start low power periodic measurement. Signal update interval is approximately 30 seconds.

isDataReady(): Promise<boolean>

Indicates whether a measurement can be read from the sensor's buffer.

persistSettings(): Promise<void>

Stores current configuration in the EEPROM of the SCD4x, making it persistent across power-cycling.

getSerialNumber(): Promise<number>

Returns the unique 48-bit serial number identifying the chip and verifying the presence of the sensor.

passesSelfTest(): Promise<boolean>

Performs a self test to check sensor functionality.

performFactoryReset(): Promise<void>

Resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.

reinit(): Promise<void>

Reinitializes the sensor by reloading user settings from EEPROM.

measureSingleShot(): Promise<void>

Perform an on-demand measurement of CO2 concentration, relative humidity and temperature.

measureSingleShotRhtOnly(): Promise<void>

Perform an on-demand measurement of relative humidity and temperature only. CO2 output is returned as 0 ppm.

disconnect(): Promise<void>

Close the I2C bus.