cactus.io logo

How to Hookup HTU21D Humidity Temperature Sensor to Arduino Board

Images

Sparkfun Measurement Specialties HTU21D Humidity - Temperature Sensors
Adafruit Measurement Specialties HTU21D Humidity - Temperature Sensor
Note: Images shown on this page are not to scale.

Parts List

  • Arduino Board
  • Sparkfun HTU21D Sensor(PN SEN-12064) or Adafruit HTU21D Sensor (PN 1899)
  • Breadboard hookup wires
  • USB Cable to suite Arduino

Data Sheets


Hookup Sparkfun HTU21D breakout board to Freetronics Arduino Clone

This hookup board is available from Sparkfun and the part number is SEN-12064

The HTU21D only supports 3.3V for power. Connecting to 5V will damage the sensor. The Sparkfun breakout board only supports 3.3V

Connect Arduino to Sparkfun HTU21D Temperature Humidity Sensor

Hookup Adafruit HTU21D breakout board to Arduino

This hookup board is available from Adafruit and the part number is 1899

The Adafruit HTU21D breakout board has a 5V to 3.3V voltage regulator built into the board. This means that it can be connected to a 5V or 3.3V power source.

Connect Arduino to Adafruit HTU21D Temperature Humidity Sensor

Software

The sample sketch below requires the cactus.io HTU21D library. Download the library into the Arduino/Libraries folder. You will need to restart the Arduino IDE so that the DTU21D library is found by the IDE. Download the sketch file and load it in the IDE. You can then compile and upload the code to the Arduino board. The humidity, temperature and heat index are displayed on the console.

HTU21D Sample Sketch
Download as (Arduino Sketch) (Text File)
1
// Example sketch for HTU21D humidity - temperature sensor
2
3
#include <Wire.h>
4
#include "cactus_io_HTU21D.h"
7
8
// For details on how to hookup the DTU21D sensor to the Arduino then checkout this page
9
// http://cactus.io/hookups/sensors/temperature-humidity/dtu21d/hookup-arduino-to-dtu21d-temp-humidity-sensor
10
23
HTU21D htu;
23
19
void setup(){
20
Serial.begin(9600);
21
Serial.println("HTU21D Humidity - Temperature Sensor");
22
Serial.println("RH\tTemp (C)\tTemp (F)\tHeat Index (C)\tHeat Index (F)");
23
24
if (!htu.begin()) {
24
Serial.println("Couldn't find sensor!");
24
while (1);
24
}
25
}
26
27
void loop(){
26
30
htu.readSensor();
32
33
// Check if any reads failed and exit early (to try again).
34
if (isnan(htu.getHumidity()) || isnan(htu.getTemperature_C()) {
35
Serial.println("HTU21D sensor read failure!");
36
return;
37
}
38
39
Serial.print(htu.getHumidity()); Serial.print(" %\t");
40
Serial.print(htu.getTemperature_C()); Serial.print(" *C\t\t");
41
Serial.print(htu.getTemperature_F()); Serial.print(" *F\t\t");
42
Serial.print(htu.getHeatIndex_C()); Serial.print(" *C\t\t");
43
Serial.print(htu.getHeatIndex_F()); Serial.println(" *F");
44
47
delay(2000);
48
}

Sketch Output

Connect Arduino to HTU21D Humidity - Temperature Sensor

License