This is a breakout for the Adafruit HTU21D-F Temperature & Humidity Sensor Breakout Board

  • Author(s): ktown

Implementation Notes


Software and Dependencies:

class adafruit_htu21d.HTU21D(i2c_bus, address=64)

A driver for the HTU21D-F temperature and humidity sensor. :param i2c_bus: The I2C bus the device is connected to :param int address: (optional) The I2C address of the device. Defaults to 0x40

Quickstart: Importing and using the HTU21D-F

Here is an example of using the HTU21D class. First you will need to import the libraries to use the sensor

import board
from adafruit_htu21d import HTU21D

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = HTU21D(i2c)

Now you have access to the temperature and relative_humidity attributes

temperature = sensor.temperature
relative_humidity = sensor.relative_humidity

Starts a measurement. Starts a measurement of either HUMIDITY or TEMPERATURE depending on the what argument. Returns immediately, and the result of the measurement can be retrieved with the temperature and relative_humidity properties. This way it will take much less time. This can be useful if you want to start the measurement, but don’t want the call to block until the measurement is ready – for instance, when you are doing other things at the same time.


The measured relative humidity in percent.


The temperature and relative humidity resolution

Have one of the following values: [1]

value RH res % T res C
0 0.04 (12bit) 0.01 (14bit)
1 0.7 (8bit) 0.04 (12bit)
2 0.17 (10bit) 0.02 (13bit)
3 0.08 (11bit) 0.08 (11bit)
[1]HTU21D(F) RH/T Sensor IC Datasheet. TE connectivity. 2017. p13

The measured temperature in degrees Celsius.