

The Adafruit HTU21D-F (Part ID: 1899) is a digital sensor designed to measure temperature and humidity with high accuracy and low power consumption. This compact and reliable sensor is ideal for environmental monitoring, weather stations, IoT applications, and HVAC systems. Its I2C interface makes it easy to integrate into microcontroller-based projects, including Arduino and Raspberry Pi systems.








The HTU21D-F sensor offers precise measurements and is designed for low-power operation. Below are its key technical details:
| Parameter | Value |
|---|---|
| Supply Voltage | 3.3V to 5V |
| Operating Current | 0.15 mA (typical) |
| Temperature Range | -40°C to +125°C |
| Temperature Accuracy | ±0.3°C |
| Humidity Range | 0% to 100% RH |
| Humidity Accuracy | ±2% RH |
| Communication Protocol | I2C |
| I2C Address | 0x40 |
| Dimensions | 15mm x 15mm x 2mm |
The HTU21D-F sensor has four pins, as described in the table below:
| Pin | Name | Description |
|---|---|---|
| 1 | VIN | Power supply input (3.3V to 5V) |
| 2 | GND | Ground connection |
| 3 | SCL | I2C clock line |
| 4 | SDA | I2C data line |
To use the HTU21D-F sensor with an Arduino UNO, follow these steps:
Below is an example Arduino sketch to read temperature and humidity data from the HTU21D-F sensor. This code uses the Adafruit HTU21D-F library, which can be installed via the Arduino Library Manager.
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
// Create an instance of the HTU21D-F sensor
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
Serial.println("HTU21D-F Temperature & Humidity Sensor Test");
// Initialize the sensor
if (!htu.begin()) {
Serial.println("Couldn't find sensor! Check wiring.");
while (1); // Halt execution if sensor initialization fails
}
}
void loop() {
// Read temperature and humidity values
float temp = htu.readTemperature();
float humidity = htu.readHumidity();
// Print the values to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // Wait 2 seconds before the next reading
}
Sensor not detected by the Arduino:
Incorrect or fluctuating readings:
Library not found:
Q: Can the HTU21D-F sensor operate at 3.3V?
A: Yes, the sensor is compatible with both 3.3V and 5V power supplies.
Q: What is the typical response time of the sensor?
A: The sensor has a response time of approximately 5 seconds for humidity and less than 1 second for temperature.
Q: Can I use the HTU21D-F sensor with a Raspberry Pi?
A: Yes, the sensor can be used with a Raspberry Pi via the I2C interface. Ensure proper configuration of the I2C pins and install the necessary libraries.
Q: How do I protect the sensor in harsh environments?
A: Use a protective enclosure or filter to shield the sensor from dust, water, and contaminants while allowing air to pass through.
By following this documentation, you can effectively integrate the Adafruit HTU21D-F sensor into your projects for accurate temperature and humidity measurements.