Temperature and humidity, SHT31
Temperature and humidity over I2C at 0x44, a CRC on every word, 15 ms a reading.
- 4 pins
- 3 settings
- In 1 project
- In 1 lesson
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
4 pins
Named as the editor names them, so a wire lands where you expect 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.
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.
#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 Temperature and humidity, SHT31 errors and fixes
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.
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.
See the Temperature and humidity, SHT31 in a project
One built-in project uses it. It opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
This board has a built-in project with the Temperature and humidity, SHT31 in it.
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.
The rest of the bench
Every one of these is drawn and simulated the same way.
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.