Part

Temperature and humidity, SHT31

Temperature and humidity over I2C at 0x44, a CRC on every word, 15 ms a reading.

See every part
  • 4 pins
  • 3 settings
  • In 1 project
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
At a glance

The Temperature and humidity, SHT31 in brief

What it is, and every setting the properties panel gives it.

The SHT31 is Sensirion’s digital temperature and humidity sensor, on breakouts such as the GY-SHT31-D. It is what weather stations and CO2 monitors move up to from a DHT22: it shares the I2C bus instead of needing a pin of its own, it answers at 0x44 or 0x45, and every two-byte word it returns carries a checksum, so a corrupted reading is caught rather than printed. There are no registers to set; every request is a sixteen-bit command. In Mokxi two sliders on the part set the temperature, from -40 to 125 °C, and the humidity. The model follows Sensirion’s command set: the soft reset and power-on times, single-shot measurements of up to 15 ms during which the sensor refuses to be read, periodic mode, the status register with its heater bit, and the CRC on every word. It does not warm itself with the heater or add the real part’s small errors.

Family
Sensors
Pins
4
address
68
temperature
22
humidity
45
Pins

4 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VIN
Supply, 2.15 V to 5.5 V.
GND
Ground.
SCL
I2C clock. The module carries the pull-ups.
SDA
I2C data.
How to use it

How to use the SHT31 humidity sensor with an Arduino

VIN to 5 V, GND to ground, SDA to A4 and SCL to A5; the board has the pull-ups. In the air quality monitor the SHT31 shares those two wires with an SGP30 gas sensor and an HT16K33 four-digit display, three devices on one bus, each at its own address. The SHT31 is at 0x44 with its ADDR strap left low.

sht31.begin(0x44) checks that it answers. readTemperature() and readHumidity() each start a measurement, wait for it and check the checksum, returning NAN if anything went wrong. The monitor does something extra: it feeds the SHT31’s humidity to the SGP30, which reads more accurately when it knows how wet the air is. Drag the two sliders on the SHT31 and the display’s temperature and humidity turns follow.

The monitor calls measure() and then getTemperatureCentis() and getHumidityCentis(), which give whole hundredths. Printing the library’s floats works on every board here, but on an Uno do your arithmetic in those whole numbers, as this sketch does.

Part pin
Board pin
VIN
5 V
GND
GND
SDA
A4
SCL
A5

The sensor runs from 2.15 to 5.5 V, so it wires to an ESP32 or a Pico’s 3.3 V and default I2C pins unchanged, and on those boards float arithmetic on the readings is fine.

Arduino Uno: air quality monitor with an SHT31 and an SGP30live0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Temperature and humidity in hundredths, from the air quality sketch
#include <Wire.h>
#include "Adafruit_SHT31.h"

Adafruit_SHT31 sht31 = Adafruit_SHT31();

void setup() {
  sht31.begin(0x44);
}

void loop() {
  if (sht31.measure()) {
    int32_t centiC = sht31.getTemperatureCentis();
    int32_t centiRh = sht31.getHumidityCentis();
  }
  delay(1000);
}
Common errors

Common Temperature and humidity, SHT31 errors and fixes

What goes wrong
The fix
A read straight after the measure command gets no answer.
The sensor refuses reads while it measures, up to 15 ms at high repeatability. The library waits for you; raw Wire code has to wait before requesting the six bytes.
begin() fails on a board that worked elsewhere.
The ADDR strap decides between 0x44 and 0x45. Match the address in begin() to the strap, or set the part’s address property to match your code.
A readings line shows nan.
The library returns NAN when a checksum fails or the sensor did not answer. Check the wiring and keep the I2C wires short.
Arithmetic on the readings will not link on an Uno.
Use getTemperatureCentis() and getHumidityCentis() after measure(); they return whole hundredths you can add, compare and scale.
Questions

Questions and answers

Is the SHT31 more accurate than a DHT22?

Typically yes: about plus or minus 2 %RH and 0.3 °C, with a checksum on every reading. It also shares the I2C bus instead of needing its own timing-critical pin.

What does the SHT31 heater do?

It warms the sensor to drive off condensation after very humid conditions. The command switches it on and the status register reports it; in the simulation it does not change the reading.

Can two SHT31 sensors share one bus?

Yes, two: one with ADDR low at 0x44 and one with it high at 0x45.

Are the SHT30 and SHT35 read the same way?

Yes. They use the same commands and the same library; they differ in accuracy grade.

How it is modeled

What is true about the Temperature and humidity, SHT31, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

The command set, the power-on and reset times, the three measurement durations and the NACK while measuring, periodic mode with Fetch and Break, the CRC on every word, the status register and its heater, reset and command bits, all from the SHT3x-DIS datasheet (version 7).

Not modeled

Clock stretching (the commands that ask for it are taken, and a read during the measurement is refused as in the no-stretch mode), the ALERT pin and its limits, the heater's actual warming, the accuracy figures (±2 %RH and ±0.3 °C typical) and the response time.

From SHT31 temperature and humidity sensor, in full.

Projects

See the Temperature and humidity, SHT31 in a project

One built-in project uses it. It opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

This board has a built-in project with the Temperature and humidity, SHT31 in it.

Libraries

Arduino libraries for the Temperature and humidity, SHT31

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Temperature and humidity, SHT31

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.