Skip to content
My Account

Reference

SHT40 / SHT41 Temperature and Humidity Sensor Complete Guide

The SHT40, SHT41 and SHT45 temperature and humidity sensors from Sensirion: 1.08 V supply, 0.08 µA idle, I2C addresses, wiring, the complete command set, code and the traps that cause wrong readings.

  • 1.08 to 3.6 V
  • I2C
  • up to 1 MHz
  • 0.08 µA idle
No ratings yet, be the first.

The SHT40 and SHT41 are Sensirion’s fourth-generation digital temperature and humidity sensors, the successors of the SHT3x series. They are factory calibrated, talk I2C and come on small breakout boards from Adafruit, SparkFun and many generic sellers. The chip runs from 1.08 V, idles at 0.08 µA and measures in 1.3 to 6.9 ms, which makes it a very good choice for battery projects.

This guide covers the chip itself, the difference between the SHT40, SHT41 and the SHT45 that shares the same pins, the I2C addresses, wiring, the complete command set, code and the traps that cause wrong readings. For a specific purple or black breakout board with labeled pinout diagrams, see the SHT4X pinout guide.

All chip data comes from the Sensirion SHT4x datasheet (version 1, October 2020). Breakout boards differ from seller to seller, so check the labels on your own board.

SHT40, SHT41 and SHT45

The three chips have the same package, pins and commands. The difference is the factory accuracy class:

ChipHumidity (typ.)Temperature (typ.)Notes
SHT401.8 %RH0.2 °CBase accuracy, the cheapest
SHT411.8 %RH0.2 °CSame typical values, a tighter maximum tolerance than the SHT40
SHT451.5 %RH0.1 °CBest accuracy of the family

In practice the SHT40 and SHT41 are so close that most projects will not notice a difference: buy whichever your supplier stocks. The SHT4x has a built-in heater, but it is meant for removing condensed water and for creep-free measurements in very humid air, not as a self-test. The SHT3x has a heater too, which is meant for plausibility checks.

Source: Sensirion SHT4x datasheet, version 1 (October 2020).

Getting started

You can read your first temperature in about ten minutes.

1. What you needA breakout board with an SHT40 or SHT41, an ESP32 (or Arduino), four jumper wires and a breadboard.
2. Wire it upVCC to 3.3 V, GND to GND, SDA to GPIO21 and SCL to GPIO22 on a classic ESP32. Check the labels on your own board first.
3. Upload the sketchInstall the Adafruit SHT4x library, upload the example below and open the serial monitor at 115200 baud.

Specifications

The sensor chip (SHT4x)

Supply voltage1.08 to 3.6 V, 3.3 V typical
InterfaceI2C, fast mode plus (up to 1 MHz), with CRC checksum
I2C address0x44 for the SHT40-AD1B, SHT41-AD1B and SHT45-AD1B, 0x45 for the SHT40-BD1B
Humidity accuracy (typical)SHT40 and SHT41: 1.8 %RH. SHT45: 1.5 %RH
Temperature accuracy (typical)SHT40 and SHT41: 0.2 °C. SHT45: 0.1 °C
Repeatability, humidity0.25 %RH low, 0.15 %RH medium, 0.08 %RH high
Repeatability, temperature0.1 °C low, 0.07 °C medium, 0.04 °C high
Resolution0.01 %RH and 0.01 °C
Hysteresis1 %RH
Response time, 63 %6 s for humidity (25 °C, 1 m/s airflow), 2 s for temperature
Long-term driftHumidity typically less than 0.25 %RH per year, temperature less than 0.03 °C per year
Measurement time (typical)1.3 ms (low), 3.7 ms (medium), 6.9 ms (high repeatability). At most 1.7, 4.5 and 8.2 ms
Current0.08 µA idle, 350 µA while measuring, average 0.4 µA at one low-precision reading per second
Power-up time0.3 ms typical, 1 ms at most
Built-in heaterThree levels, about 20, 110 and 200 mW at 3.3 V, for 0.1 s or 1 s, duty cycle below 5 %
Recommended operating range5 to 60 °C and 20 to 80 %RH for the best accuracy
Operating and storage temperatureOperating −40 to 125 °C, storage −40 to 150 °C (10 to 50 °C recommended)
Absolute maximumVoltage on a pin VSS −0.3 V to VDD + 0.3 V, ESD 2 kV (human body model)

Source: Sensirion SHT4x datasheet, version 1 (October 2020), as published by SparkFun.

Dimensions

The chip is a DFN package of 1.5 × 1.5 mm and 0.54 mm high, with an opening of 0.6 mm diameter for the humidity sensor and four contacts at a pitch of 0.8 mm. Breakout boards come in many sizes, so measure your own before you design a case.

Source: package outline in the Sensirion SHT4x datasheet.

Pins

Chip pins

PinTypeFunction
VDDPower1.08 to 3.6 V
VSSPowerGround
SDAI2CData, needs a pull-up
SCLI2CClock, needs a pull-up

The chip has only four contacts, so there is no address, alert or reset pin. A breakout board brings these out as four header pins, usually called VCC (or VIN), GND, SDA and SCL, in an order that differs between makers. Some boards also have a 3.3 V output (a regulator on the board), which is why you must read the silkscreen on your own board.

Source: Sensirion SHT4x datasheet.

Wiring

Sensor pinESP32Arduino Uno / NanoRaspberry PiESP8266 (NodeMCU)
VIN3.3 V3.3 V3.3 V (pin 1)3.3 V
GNDGNDGNDGND (pin 6)GND
SCLGPIO22A5GPIO3 (pin 5)D1 (GPIO5)
SDAGPIO21A4GPIO2 (pin 3)D2 (GPIO4)

The chip takes 3.6 V at most, so the I2C pull-ups must go to 3.3 V as well. An Arduino Uno works at 5 V and needs a level shifter, or a 3.3 V board such as the Pro Mini 3.3 V. On an ESP32 you can pick other pins with Wire.begin(SDA, SCL). On a Raspberry Pi, enable I2C first with sudo raspi-config. For the pins of the ESP32 itself see the ESP32-WROOM-32D pinout.

Software setup

PlatformWhat to do
Arduino IDEOpen Tools, Manage Libraries and install Adafruit SHT4x Library (it also installs Adafruit BusIO and Adafruit Unified Sensor)
PlatformIOAdd lib_deps = adafruit/Adafruit SHT4x Library to platformio.ini
ESP-IDFWrite the few commands yourself with the I2C driver, see the section below
Raspberry PiEnable I2C and use a Python library for the SHT4x, or talk to the chip with the commands below

Start the I2C bus yourself with Wire.begin(21, 22) on an ESP32, then call begin(). The library uses address 0x44.

Read the sensor

#include <Wire.h>
#include "Adafruit_SHT4x.h"

Adafruit_SHT4x sht4 = Adafruit_SHT4x();

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!sht4.begin()) {
    Serial.println("Couldn't find SHT4x sensor!");
    while (1) delay(10);
  }
  sht4.setPrecision(SHT4X_HIGH_PRECISION);
}

void loop() {
  sensors_event_t humidity, temp;
  sht4.getEvent(&humidity, &temp);

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.print(" degC   Humidity: ");
  Serial.print(humidity.relative_humidity);
  Serial.println(" %RH");

  delay(2000);
}

I did not run this sketch on a board, it follows the Adafruit library example.

Talking to the chip yourself

The quickest measurement is one command and one read. The datasheet gives it as: write 0xFD to address 0x44, wait 10 ms, read 6 bytes. This version also checks both CRCs:

uint8_t crc8(const uint8_t *d, int n) {
  uint8_t c = 0xFF;                 // initialisation 0xFF
  for (int i = 0; i < n; i++) {
    c ^= d[i];
    for (int b = 0; b < 8; b++)
      c = (c & 0x80) ? (c << 1) ^ 0x31 : (c << 1);   // polynomial 0x31
  }
  return c;
}

bool readSHT4x(float &t, float &h) {
  Wire.beginTransmission(0x44);
  Wire.write(0xFD);                          // high precision measurement
  if (Wire.endTransmission() != 0) return false;
  delay(10);                                 // 8.2 ms at most
  if (Wire.requestFrom(0x44, 6) != 6) return false;
  uint8_t b[6];
  for (int i = 0; i < 6; i++) b[i] = Wire.read();
  if (crc8(b, 2) != b[2] || crc8(b + 3, 2) != b[5]) return false;
  uint16_t st = (b[0] << 8) | b[1];
  uint16_t sh = (b[3] << 8) | b[4];
  t = -45.0f + 175.0f * st / 65535.0f;
  h = -6.0f + 125.0f * sh / 65535.0f;
  if (h > 100) h = 100;
  if (h < 0) h = 0;
  return true;
}

I checked the CRC routine against the example in the SHT4x datasheet (the two bytes 0xBE 0xEF give 0x92), but I did not run this sketch on a board.

Commands

CommandWhat it does
0xFDMeasure with high precision (6.9 ms typical)
0xF6Measure with medium precision (3.7 ms typical)
0xE0Measure with low precision (1.3 ms typical)
0x89Read the serial number (two 16-bit words, each with a CRC)
0x94Soft reset (the chip is idle again after 1 ms)
0x39Heater at the highest power, 200 mW, for 1 s, then a high precision measurement
0x32Heater at the highest power for 0.1 s, then a measurement
0x2FHeater at medium power, 110 mW, for 1 s, then a measurement
0x24Heater at medium power for 0.1 s, then a measurement
0x1EHeater at the lowest power, 20 mW, for 1 s, then a measurement
0x15Heater at the lowest power for 0.1 s, then a measurement
0x06 to address 0x00General call reset of every device on the bus

Conversion and checksum

With ST and SRH as the 16-bit values: T = −45 + 175 × ST / 65535 °C and RH = −6 + 125 × SRH / 65535 %RH. Note that the humidity formula differs from the SHT3x. The result can be a little below 0 or above 100 %RH, so cut it to 0 to 100. The CRC is 8 bits with polynomial 0x31 and start value 0xFF, and it covers the two data bytes before it. Wait at least 1 ms between two commands.

The heater

A heater command switches the heater on for 0.1 s or 1 s, then takes one high-precision measurement with the heater still on, and then switches the heater off. There is no command to switch it off by hand. The heater is designed for a duty cycle below 5 %. Use it to remove condensed water from the sensor surface or for creep-free measurements in very humid air, not for normal readings.

Source: Sensirion SHT4x datasheet, sections 4.4 to 4.8.

I2C address and scan

The address is fixed by the part number: 0x44 for the AD1B parts that nearly every breakout uses, and 0x45 for the SHT40-BD1B. If begin() fails, run an I2C scan: it lists every address that answers. Two sensors with the same address cannot share one bus, so use a second bus or an I2C multiplexer.

#include <Wire.h>
void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  for (uint8_t a = 1; a < 127; a++) {
    Wire.beginTransmission(a);
    if (Wire.endTransmission() == 0) Serial.printf("Found 0x%02Xn", a);
  }
}
void loop() {}

The chip has the logo SH4x and a short code printed on it, and the full part number is in the ordering code, for example SHT40-AD1B. On a breakout board the chip is too small to read without a magnifier, so ask the seller which part number is fitted.

Getting accurate readings

  • Keep the board away from heat. The ESP32, a regulator or a power resistor warm the board. A few tenths of a degree of self-heating change the temperature and the humidity reading.
  • Let air reach the chip. The response time is 6 s at 1 m/s of airflow and much slower in still air. Do not put the board in a closed box without holes.
  • Use low precision for slow readings. One low-precision reading per second averages 0.4 µA. For a room, one high-precision reading every few seconds is more than enough.
  • Sleep between readings. The chip is idle at 0.08 µA by itself, so on a battery project the microcontroller is what you have to put to sleep.
  • Stay in the recommended range. The best accuracy is at 5 to 60 °C and 20 to 80 %RH. Long exposure to more than 80 %RH can shift the reading by about 3 %RH, and it comes back slowly.
  • Mount it with the opening free. Do not cover the chip with glue, tape or a conformal coating.
  • Plan for drift. Typically less than 0.25 %RH per year in normal use.

Real gotchas

  • The chip takes 3.6 V at most. It is rated for 1.08 to 3.6 V, not 5 V. Use 3.3 V unless your breakout has a regulator and level shifting, as many Adafruit and SparkFun boards do.
  • Check the pin order of your breakout. Boards from different makers have the four pins in a different order. A reversed VCC and GND can destroy the chip.
  • The address is fixed. It is 0x44 for the AD1B parts and 0x45 for the SHT40-BD1B, and there is no pin to change it. Two sensors with the same address cannot share one bus.
  • No ALERT and no reset pin. If you want a hardware alarm output, use an SHT3x.
  • Wait between commands. At least 1 ms between two I2C commands, and up to 8.2 ms for a high-precision measurement. A library does this for you.
  • Heater self-heating. A heater command adds up to 200 mW. Keep the duty cycle below 5 % and never use it for normal readings.
  • The board heats the sensor. Mount it away from the ESP32 and any regulator, or the temperature reads too high.
  • Cut the humidity to 0 to 100 %. The formula can return values a little outside that range.

SHT4x compared with the SHT3x

SHT4xSHT3x
Supply1.08 to 3.6 V2.15 to 5.5 V
Idle current0.08 µA0.2 µA (single shot)
Humidity accuracy (typical)SHT40/41: 1.8 %RH, SHT45: 1.5 %RHSHT30/31: 2 %RH, SHT35: 1.5 %RH
Temperature accuracy (typical)0.2 °C, SHT45 0.1 °C0.2 °C, SHT35 0.1 °C
Measurement time (high, typical)6.9 ms12.5 ms
AddressFixed by the part number0x44 or 0x45, selectable
ALERT pinNoYes
nRESET pinNoYes
Package4-pin DFN, 1.5 × 1.5 mmDFN-8, 2.5 × 2.5 mm

The SHT4x is the better choice for batteries and small designs. Take the SHT3x if you want to run from 5 V, need a selectable address or an alert output. See also the SHT40/SHT41 guide and the SHT sensor series guide.

Source: the Sensirion datasheets SHT4x (version 1) and SHT3x-DIS (version 7).

What to build with it

  • A battery or solar sensor node that sleeps for minutes and sends a reading over Wi-Fi.
  • A room thermometer and hygrometer that logs to a web page or to MQTT.
  • A HomeKit temperature and humidity sensor on an ESP32, see ESP32 HomeKit development.
  • A bathroom fan controller that switches on at a rising humidity, see the HomeKit bathroom ventilation controller.
  • A weather station with the sensor in a ventilated radiation shield.

Safety notes

Before you wire anything up

  • Use 3.3 V on the supply pin. The chip is rated for 3.6 V at most.
  • Check the pin order on your own breakout before you apply power.
  • Never connect the board to mains voltage. Keep the sensor on a low-voltage supply.
  • Disconnect the power before you change the wiring.
  • This sensor measures air, it is not a safety device. Do not use it as the only protection against fire, condensation or frost damage.

Conclusion

The SHT40 and SHT41 give you the same Sensirion accuracy as the SHT3x series with a far smaller power budget: 0.08 µA idle, a 1.08 V minimum supply and a measurement in a few milliseconds. Stay at 3.3 V, check the pin order of your own breakout, and keep it away from heat. If you need an alert output, a selectable address or a 5 V supply, take an SHT3x. Either family pairs cleanly with an ESP32 over I2C.

All chip data is from the Sensirion SHT4x datasheet, version 1.

Advertisement
All guides

More guides

Keep building.

From ESP32 HomeKit accessories to Arduino and ATtiny reference guides, there’s more where this came from.

All guides