Humidity with HTU21D Sensor

Introduction

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

HTU21D Sensor

Components Needed

Circuit Setup

  1. Connect the VCC pin of the HTU21D sensor to 3.3V or 5V on the Arduino.
  2. 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.

HTU21D Circuit Setup

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