Sensirion SHT40, SHT41, and SHT45 topic

Classes for the Sensirion SHT40, SHT41, and SHT45 I2C humidity and temperature sensors.

Introduction

SHT4x is a digital sensor platform for measuring relative humidity and temperature at different accuracy classes. The I2C interface provides several preconfigured I2C addresses and maintains an ultra-low power budget. The power-trimmed internal heater can be used at three heating levels thus enabling sensor operation in demanding environments.

  • The code for this library should work for 0x44 addressed SHT4x sensors - the SHT40, SHT41, and SHT45.
  • Depends on the Adafruit SHT4x Library.
  • Communicates via I2C
    • There are versions of the SHT40, SHT40-AD1B with the I2C address 0x44 and SHT40-BD1B with the I2C address 0x45. This library only supports the 0x44 addressed sensor!
    • The SHT41 and SHT45 only have one possible address, 0x44.
  • Only 1 can be connected to a single I2C bus at a time
  • Requires a 3.3 power source

Sensor Datasheet

Datasheet

Sensor Constructors

SensirionSHT4x::SensirionSHT4x(int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1) explicit

Construct a new SensirionSHT4x object using the primary hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the Sensirion SHT4x. Use -1 if it is continuously powered.

  • The SHT4x requires a 3.3V power source
useHeater Whether or not to run the internal heater of the SHT4x when shutting down the sensor; optional with a default value of true. The internal heater is designed to remove condensed water from the sensor - which will make the sensor stop responding to air humidity changes - and to allow creep-free operation in high humidity environments. The longest the internal heater can run at a time is 1s and the maximum duty load is 5%. Running only 1s per measurment cycle probably isn't enough to help with more than very minimal condensation, but it's probably the best we can easily do.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Because this is I2C and has only 1 possible address (0x44), we only need the power pin.


SensirionSHT4x::SensirionSHT4x(TwoWire* theI2C, int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1)

Construct a new SensirionSHT4x object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the Sensirion SHT4x. Use -1 if it is continuously powered.

  • The SHT4x requires a 3.3V power source
useHeater Whether or not to run the internal heater of the SHT4x when shutting down the sensor; optional with a default value of true. The internal heater is designed to remove condensed water from the sensor - which will make the sensor stop responding to air humidity changes - and to allow creep-free operation in high humidity environments. The longest the internal heater can run at a time is 1s and the maximum duty load is 5%. Running only 1s per measurment cycle probably isn't enough to help with more than very minimal condensation, but it's probably the best we can easily do.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

This is only applicable to SAMD boards that are able to have multiple hardware I2C ports in use via SERCOMs.


Example Code

The SHT40 is used in the menu a la carte example

1#include <sensors/SensirionSHT4x.h>
2
3// NOTE: Use -1 for any pins that don't apply or aren't being used.
4const int8_t SHT4xPower = sensorPowerPin; // Power pin
5const bool SHT4xUseHeater = true;
6
7// Create an Sensirion SHT4X sensor object
8SensirionSHT4x sht4x(SHT4xPower, SHT4xUseHeater);
9
10// Create humidity and temperature variable pointers for the SHT4X
11Variable* sht4xHumid =
12 new SensirionSHT4x_Humidity(&sht4x, "12345678-abcd-1234-ef00-1234567890ab");
13Variable* sht4xTemp =
14 new SensirionSHT4x_Temp(&sht4x, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class SensirionSHT4x
The Sensor sub-class for the Sensirion SHT4x.
class SensirionSHT4x_Humidity
The Variable sub-class used for the relative humidity output from an Sensirion SHT4x.
class SensirionSHT4x_Temp
The Variable sub-class used for the temperature output from an Sensirion SHTx0.

Sensor Variable Counts

The number of variables that can be returned by the SHT4x

#define SHT4X_NUM_VARIABLES = 2
Sensor::_numReturnedValues; the SHT4x can report 2 values.
#define SHT4X_INC_CALC_VARIABLES = 0
Sensor::_incCalcValues; we don't calculate any additional values.

Sensor Timing

The sensor timing for an Sensirion SHT4x

#define SHT4X_WARM_UP_TIME_MS = 1
Sensor::_warmUpTime_ms; SHT4x warms up in 0.3ms (typical) and soft-resets in 1ms (max).
#define SHT4X_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; SHT4x is assumed to be immediately stable.
#define SHT4X_MEASUREMENT_TIME_MS = 9
Sensor::_measurementTime_ms; SHT4x takes 8.2ms (max) to complete a measurement at the highest precision. At medium precision measurement time is 4.5ms (max) and it is 1.7ms (max) at low precision.

Humidity

The humidity variable from an Sensirion SHT4x

  • Range is 0 to 100% RH
  • Accuracy is ± 1.8 % RH (typical)

SensirionSHT4x_Humidity::SensirionSHT4x_Humidity(SensirionSHT4x* parentSense, const char* uuid = "", const char* varCode = "SHT4xHumidity") explicit

Construct a new SensirionSHT4x_Humidity object.

Parameters
parentSense The parent SensirionSHT4x providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "SHT4xHumidity".

#define SHT4X_HUMIDITY_RESOLUTION = 2
Decimals places in string representation; humidity should have 2 (0.01 % RH).
#define SHT4X_HUMIDITY_VAR_NUM = 0
Sensor variable number; humidity is stored in sensorValues[0].
#define SHT4X_HUMIDITY_VAR_NAME = "relativeHumidity"
Variable name in ODM2 controlled vocabulary; "relativeHumidity".
#define SHT4X_HUMIDITY_UNIT_NAME = "percent"
Variable unit name in ODM2 controlled vocabulary; "percent" (percent relative humidity)
#define SHT4X_HUMIDITY_DEFAULT_CODE = "SHT4xHumidity"
Default variable short code; "SHT4xHumidity".

Temperature

The temperature variable from an Sensirion SHT4x

  • Range is -40°C to +125°C
  • Accuracy is ±0.2°C

SensirionSHT4x_Temp::SensirionSHT4x_Temp(SensirionSHT4x* parentSense, const char* uuid = "", const char* varCode = "SHT4xTemp") explicit

Construct a new SensirionSHT4x_Temp object.

Parameters
parentSense The parent SensirionSHT4x providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "SHT4xTemp".

#define SHT4X_TEMP_RESOLUTION = 2
Decimals places in string representation; humidity should have 2 (0.01 °C).
#define SHT4X_TEMP_VAR_NUM = 1
Sensor variable number; temperature is stored in sensorValues[1].
#define SHT4X_TEMP_VAR_NAME = "temperature"
Variable name in ODM2 controlled vocabulary; "temperature".
#define SHT4X_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define SHT4X_TEMP_DEFAULT_CODE = "SHT4xTemp"
Default variable short code; "SHT4xTemp".

Define documentation

#define SHT4X_NUM_VARIABLES = 2

Sensor::_numReturnedValues; the SHT4x can report 2 values.


#define SHT4X_INC_CALC_VARIABLES = 0

Sensor::_incCalcValues; we don't calculate any additional values.


#define SHT4X_WARM_UP_TIME_MS = 1

Sensor::_warmUpTime_ms; SHT4x warms up in 0.3ms (typical) and soft-resets in 1ms (max).


#define SHT4X_STABILIZATION_TIME_MS = 0

Sensor::_stabilizationTime_ms; SHT4x is assumed to be immediately stable.


#define SHT4X_MEASUREMENT_TIME_MS = 9

Sensor::_measurementTime_ms; SHT4x takes 8.2ms (max) to complete a measurement at the highest precision. At medium precision measurement time is 4.5ms (max) and it is 1.7ms (max) at low precision.


#define SHT4X_HUMIDITY_RESOLUTION = 2

Decimals places in string representation; humidity should have 2 (0.01 % RH).


#define SHT4X_HUMIDITY_VAR_NUM = 0

Sensor variable number; humidity is stored in sensorValues[0].


#define SHT4X_HUMIDITY_VAR_NAME = "relativeHumidity"

Variable name in ODM2 controlled vocabulary; "relativeHumidity".


#define SHT4X_HUMIDITY_UNIT_NAME = "percent"

Variable unit name in ODM2 controlled vocabulary; "percent" (percent relative humidity)


#define SHT4X_HUMIDITY_DEFAULT_CODE = "SHT4xHumidity"

Default variable short code; "SHT4xHumidity".


#define SHT4X_TEMP_RESOLUTION = 2

Decimals places in string representation; humidity should have 2 (0.01 °C).


#define SHT4X_TEMP_VAR_NUM = 1

Sensor variable number; temperature is stored in sensorValues[1].


#define SHT4X_TEMP_VAR_NAME = "temperature"

Variable name in ODM2 controlled vocabulary; "temperature".


#define SHT4X_TEMP_UNIT_NAME = "degreeCelsius"

Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)


#define SHT4X_TEMP_DEFAULT_CODE = "SHT4xTemp"

Default variable short code; "SHT4xTemp".