Source: https://mokxi.com/parts/htu21d
Updated: 2026-11-18

Part

# Temperature and humidity, HTU21D

Temperature and humidity over I2C at 0x40 on the GY-21, hold and no-hold commands, a CRC on each reading, for Adafruit_HTU21DF.h.

See every part

- 4 pins
- 2 settings
- In 1 project

Drawn live by the editor's own code, at the size you see it.

At a glance

## The Temperature and humidity, HTU21D in brief

What it is, and every setting the properties panel gives it.

The HTU21D is a temperature and humidity sensor from TE Connectivity, often seen on a GY-21 breakout board. It talks over I2C at the fixed address 0x40, and every reading comes back as two data bytes plus a CRC checksum. You ask for one reading at a time, wait while it measures, then read the bytes. The resolution is your choice, trading bits for speed. Mokxi simulates the part with two sliders, temperature in degrees Celsius and humidity in percent relative humidity, that you can move while the circuit runs. The next measurement reports the new values. The model also checks the CRC and returns NAN if a reading fails, and begin() fails with no answer at 0x40 if SDA, SCL or power are not connected. Clock stretching in Hold Master mode is not modeled, and the heater bit switches and reads back but does not warm the reading. One HTU21D per I2C bus, unless you add a switch like the TCA9548A.

Family

Sensors

Pins

4

temperature

22

humidity

45

Pins

## 4 pins

Named as the editor names them, so a wire lands where you expect it.

Pin

What it does

VIN

Supply, 3.3 or 5 V on the GY-21 (the chip itself runs from 1.5 to 3.6 V, and the board's regulator feeds it 3.3 V).

GND

Ground.

SCL

I2C clock. The board carries the pull-ups and level shifters.

SDA

I2C data.

How to use it

## How to use the HTU21D temperature sensor with an Arduino

The built-in project HTU21D temperature and humidity has this part wired to an Arduino Uno. A GY-21 HTU21D board sits on the Uno's I2C pins and is read with the Adafruit_HTU21DF library. The project runs beside these words and opens in the editor as it is drawn here. Wiring: VIN to 5V, GND to GND, SDA to A4, SCL to A5.

The sketch asks for a temperature and a humidity reading every second and prints both on the serial monitor. With the default settings, temperature 22 and humidity 45, the serial monitor shows: "HTU21D found at 0x40" and then "temperature 21.99 C, humidity 45.0 %RH".

Move the sliders while it runs. After changing the settings to temperature 30 and humidity 70, the serial monitor shows: "HTU21D found at 0x40" and then "temperature 30.00 C, humidity 70.0 %RH". Only the numbers changed. The sensor was found the same way both times.

Things to try from the sketch: unplug SDA, and begin() gets no answer at 0x40, so the sketch says so. Then work out the dew point from the two readings.

Part pin

Goes to

VIN

Arduino Uno R3 pin 5V

GND

Arduino Uno R3 pin GND

SDA

Arduino Uno R3 pin A4

SCL

Arduino Uno R3 pin A5

Click to open it in the editor

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

sketch.ino · Arduino Uno R3

Common errors

## Common Temperature and humidity, HTU21D errors and fixes

What goes wrong

The fix

begin() finds no sensor and prints a message.

Check SDA, SCL and power. The sensor answers only at address 0x40, so SDA and SCL must be wired right.

A reading comes back as NAN.

The CRC check failed or the wiring is loose. Make sure SDA, SCL, VIN and GND are all connected.

Read during a measurement is refused in No Hold mode.

Wait for the measurement to finish before reading. The sensor gives no ACK until it is done.

Only one HTU21D works on the bus.

The address is fixed at 0x40. Use an I2C switch such as the TCA9548A to add more sensors.

Questions

## Questions and answers

### what is the htu21d i2c address

It is fixed at 0x40. That means one HTU21D per I2C bus, unless you add an I2C switch like the TCA9548A.

### can i power the gy-21 board with 5 volts

Yes. The board has its own 3.3 V regulator and pull-ups, so 5 V on VIN is fine.

### which arduino library works with the htu21d

Use Adafruit's library. Mokxi ships it as Adafruit_HTU21DF.h. Call begin(), then readTemperature() and readHumidity().

### can i change temperature and humidity while the simulation runs

Yes. The temperature and humidity sliders change them while the circuit runs, and the next measurement reports the new values.

How it is modeled

## What is true about the Temperature and humidity, HTU21D, here

In its help article’s own words: what the simulation gets right, and where it stops.

### Not modeled

Clock stretching in Hold Master mode: no simulated board waits for it, so 0xE3 and
0xE5 behave like their No Hold twins and a read during the measurement is refused.
The heater's warming (the bit switches and reads back, but the reading stays the
slider's), the diagnostic open and short circuit codes, and the accuracy figures (the
real part is typically within 0.3 °C and 2 %RH). The datasheet does not say whether a
result can be read twice; here it is read once.

From HTU21D temperature and humidity sensor, in full.

Projects

## See the Temperature and humidity, HTU21D in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

## The boards it is shown on

This board has a built-in project with the Temperature and humidity, HTU21D in it.

- Arduino Uno R3

Keep going

## Keep going

- I2C Scanner for Arduino and ESP32, and Fixes
- Temperature and humidity, DHT22
- Temperature and humidity, SHT31
- Humidity sensor, AHT20

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Temperature and humidity, HTU21D

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.

Start building free Open the editor
