Introduction
This experiment demonstrates how to measure humidity using the HTU21D sensor.

Components Needed
- HTU21D Humidity Sensor
- Arduino
- Jumper Wires
Circuit Setup
- Connect the VCC pin of the HTU21D sensor to 3.3V or 5V on the Arduino.
- Connect the SDA and SCL pins to the corresponding pins on the Arduino for I2C communication.
The sensor will communicate with the Arduino via the I2C protocol.

Code for Humidity Measurement
Upload the following code to your Arduino to measure humidity:
#include
#include
HTU21D mySensor;
void setup() {
Serial.begin(9600);
mySensor.begin();
}
void loop() {
float humidity = mySensor.readHumidity();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
delay(1000);
}
Explanation
The HTU21D sensor uses I2C communication to send humidity readings to the Arduino, which are then printed on the Serial Monitor.
Troubleshooting
- If the sensor is not responding, check the I2C wiring and ensure the correct library is installed.
- If readings seem inaccurate, check the sensor’s calibration and environment for errors.