

The HTU31D is a digital humidity and temperature sensor designed to deliver precise measurements of relative humidity and temperature. It operates using an I2C interface, making it easy to integrate into microcontroller-based systems. Known for its low power consumption and high accuracy, the HTU31D is ideal for applications such as weather monitoring, HVAC systems, industrial automation, and IoT devices.








The HTU31D sensor offers the following key technical details:
| Parameter | Value |
|---|---|
| Supply Voltage (VDD) | 2.4V to 5.5V |
| Average Current Consumption | 0.7 µA (at 1 Hz measurement rate) |
| Humidity Accuracy | ±2% RH (20% to 80% RH range) |
| Temperature Accuracy | ±0.2°C (0°C to 60°C range) |
| Operating Temperature Range | -40°C to +125°C |
| Communication Interface | I2C |
| I2C Address | 0x40 (default) |
| Measurement Resolution | 16-bit |
The HTU31D sensor has four pins, as described in the table below:
| Pin Name | Description |
|---|---|
| VDD | Power supply (2.4V to 5.5V) |
| GND | Ground |
| SDA | I2C data line |
| SCL | I2C clock line |
0x40. Ensure no other devices on the I2C bus share this address.Below is an example of how to interface the HTU31D with an Arduino UNO using the I2C protocol:
#include <Wire.h>
// HTU31D I2C address
#define HTU31D_ADDRESS 0x40
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Send a soft reset command to the HTU31D
Wire.beginTransmission(HTU31D_ADDRESS);
Wire.write(0x1E); // Soft reset command
Wire.endTransmission();
delay(15); // Wait for the reset to complete
}
void loop() {
float temperature, humidity;
// Request a measurement from the HTU31D
Wire.beginTransmission(HTU31D_ADDRESS);
Wire.write(0x00); // Trigger measurement command
Wire.endTransmission();
delay(50); // Wait for measurement to complete
// Read the measurement data (6 bytes: temp MSB, temp LSB, CRC, hum MSB, hum LSB, CRC)
Wire.requestFrom(HTU31D_ADDRESS, 6);
if (Wire.available() == 6) {
uint16_t tempRaw = (Wire.read() << 8) | Wire.read();
Wire.read(); // Skip temperature CRC
uint16_t humRaw = (Wire.read() << 8) | Wire.read();
Wire.read(); // Skip humidity CRC
// Convert raw data to temperature and humidity
temperature = -40.0 + 165.0 * (tempRaw / 65535.0);
humidity = 100.0 * (humRaw / 65535.0);
// Print the results
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Error: Failed to read data from HTU31D.");
}
delay(2000); // Wait 2 seconds before the next measurement
}
No Data from Sensor:
0x40) matches the one used in your code.Inaccurate Readings:
I2C Communication Errors:
Q: Can the HTU31D operate at 5V?
A: Yes, the HTU31D supports a supply voltage range of 2.4V to 5.5V.
Q: Do I need to calibrate the HTU31D?
A: No, the HTU31D is factory-calibrated and does not require additional calibration.
Q: What is the maximum I2C clock speed supported?
A: The HTU31D supports I2C clock speeds up to 1 MHz (Fast Mode Plus).
Q: How do I protect the sensor from contaminants?
A: Use a protective cover or enclosure that allows airflow but prevents dust, oils, or chemicals from reaching the sensor.
By following this documentation, you can effectively integrate the HTU31D into your projects for reliable humidity and temperature measurements.