The HTUs are highly accurate, digital relative humidity and temperature sensors known for their low power consumption, I²C interface, and factory calibration.
Key Features
If you'd like to support the development of the site with the price of a coffee — or a few — please do so here.
Here's a handy tip: you can quickly save this page as a PDF by clicking “export to PDF” in the menu on the right side of the screen.
Difference between HTU31D, HTU21D and HTU20D
The primary difference among the HTU20D, HTU21D, and HTU31D is an incremental improvement in accuracy, supply-voltage range, and power consumption as the model number increases. The sensors are largely interchangeable and use the same I²C communication protocol.
¹: The SHT20, HTU20, Si702, GY-20 are different manufacturers' versions of essentially the same I²C digital humidity and temperature sensor chip, designed to be hardware- and software-compatible. The GY-20 is a generic breakout board that uses one of these chips.
²: The SHT21, HTU21, Si7021, GY-21, GY-213V, HDC1080 are very similar digital humidity and temperature sensor chips from different manufacturers (Sensirion, Measurement Specialties, and Silicon Labs, respectively), while the GY-21 is a generic breakout board that uses one of these chips. They are largely interchangeable in hardware and software for most general-purpose applications.
³: The SHT31, HTU31, Si7031, and GY-31 are high-accuracy digital temperature and humidity sensor chips from different manufacturers (Sensirion, TE Connectivity, and Silicon Labs, respectively) that are designed to be largely interchangeable. The GY-31 is a generic name for a breakout board that typically uses the SHT31 chip.
To read the HTU31D, the most reliable method is to use the Adafruit HTU31D Library. Compared to the older HTU21D, this sensor handles a wider voltage range (3V–5.5V) and offers even better precision.
Wiring (I²C)
Arduino Example Code
Install the Adafruit HTU31D and Adafruit BusIO libraries via the Arduino Library Manager.
#include <Wire.h> #include "Adafruit_HTU31D.h" Adafruit_HTU31D htu = Adafruit_HTU31D(); void setup() { Serial.begin(115200); while (!Serial) delay(10); Serial.println("HTU31D test"); if (!htu.begin(0x40)) { // Use 0x41 if ADR pin is tied to High Serial.println("Couldn't find sensor!"); while (1); } } void loop() { sensors_event_t humidity, temp; // Get both temperature and humidity at once htu.getEvent(&humidity, &temp); Serial.print("Temp: "); Serial.print(temp.temperature); Serial.print(" C \t"); Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println(" %"); delay(1000); }
Advanced Features
The HTU31D includes a built-in heater to dry the sensor if it accumulates condensation. You can toggle it in your code:
Resolution Settings
You can optimize for speed or precision using htu.setResolutions(temp_res, hum_res).
This page has been accessed for: Today: 2, Until now: 4