Reference
HTU21D
Temperature and humidity.
- Connects over
- I²C
- Address
- 0x40
- Made by
- Measurement Specialties / TE
- Datasheet
- cdn-shop.adafruit.com
Use it
hardware {
device htu21d: HTU21D
}
every 1s {
let value: float = htu21d.temperature()
log("htu21d", "temperature={value}")
}
On its own, the declaration puts the HTU21D on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x40. To choose the pins or the address, declare the bus and attach the device: device htu21d: HTU21D on i2c0 at 0x40 with i2c i2c0(sda: 21, scl: 22).
Methods
-
htu21d.temperature() -> float
Temperature in °C
-
htu21d.humidity() -> float
Humidity %
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V ONLY — 5V damages the chip |
GND | Ground |
SDA | Pull-up to 3.3V |
SCL | Pull-up to 3.3V |
Specifications
- Voltage
- 1.5V – 3.6V (NOT 5V tolerant)
- Current
- 150 μA measure, 60 nA sleep
- Temp
- −40°C to +125°C ±0.3°C
- Humidity
- 0 – 100% RH ±2%
Tips
- Address fixed at 0x40 — one per bus.
- Discontinued by manufacturer but widely available as clones; quality varies.
- On-board heater can help recover after condensation events.
Alternatives worth knowing:
- SHT31: Sensirion — drop-in upgrade, better accuracy.
- AHT20: Cheaper, 5V tolerant via internal regulator.
- BME280: Adds pressure on top.