SHT40 temperature and humidity sensor

The Sensirion SHT40 on an I2C breakout: temperature and humidity at 0x44, the SHT31's smaller and faster successor.

Aliases: SHT4x, SHT41, SHT45, Adafruit SHT40, Qwiic SHT40. It reads in 8 ms where the SHT31 takes 15, runs from a coin cell, and carries a small heater to burn off condensation. Every reading comes with a checksum.

Pins

Pin What it does
VIN Supply, 3 to 5 V on the board (the chip itself runs from 1.08 to 3.6 V).
GND Ground.
SCL I2C clock. The board carries the pull-ups.
SDA I2C data.

Properties

address is 0x44 (the SHT40-AD1B most boards carry), 0x45 or 0x46. temperature (degrees C, -40 to 125) and humidity (%RH, 0 to 100) are the weather; the two sliders change them while the circuit runs.

Reading it on an Arduino

With Adafruit's library, which Mokxi ships as Adafruit_SHT4x.h:

#include <Adafruit_SHT4x.h>
Adafruit_SHT4x sht4;

void setup() {
  Serial.begin(9600);
  if (!sht4.begin()) {
    Serial.println("No SHT4x");
    while (1) delay(10);
  }
  sht4.setPrecision(SHT4X_HIGH_PRECISION);
}

void loop() {
  sensors_event_t humidity, temp;
  sht4.getEvent(&humidity, &temp);
  Serial.print(temp.temperature);
  Serial.print(" C  ");
  Serial.print(humidity.relative_humidity);
  Serial.println(" %");
  delay(1000);
}

Sensirion's own library, SensirionI2cSht4x.h, has measureHighPrecision(t, rh) and its siblings, and returns an error code from each call.

How it talks

Every command is one byte, from the SHT4x datasheet:

  • Power on and soft reset (0x94) take up to 1 ms; until then the address is not acknowledged.
  • Measure 0xFD (high precision, 8.3 ms), 0xF6 (medium, 4.5 ms) or 0xE0 (low, 1.6 ms). While it measures, and once the result has been read, a read is refused.
  • Read six bytes: the temperature word, its CRC, the humidity word, its CRC (CRC-8, polynomial 0x31 from 0xFF).
  • Convert: T = -45 + 175 x S / 65535 and RH = -6 + 125 x S / 65535, clipped to 0 to 100 by the library.
  • Heater commands (0x39, 0x32, 0x2F, 0x24, 0x1E, 0x15) run it for 1 s or 0.1 s and then measure. Serial number is 0x89.

What it does not model

The heater's warming (the reading after a pulse is the slider's temperature), the general-call reset, and the accuracy figures.

Common mistakes

Reading straight after the command: the result is not there for up to 8.3 ms, and the sensor refuses the read until it is. Expecting the SHT31's two-byte commands: the SHT4x takes one byte.