Arduino Due and HDC1008 example

66

The HDC1000 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The device measures humidity based on a novel capacitive sensor. The humidity and temperature sensors are factory calibrated.

The sensing element of the HDC1000 is placed on the bottom part of the device, which makes the HDC1000 more robust against dirt, dust, and other environmental contaminants. The HDC1000 is functional within the full –40°C to +125°C temperature range.

Key Features

Relative Humidity (RH) Operating Range 0% to 100%
14 Bit Measurement Resolution
Relative Humidity Accuracy ±3%
Temperature Accuracy ±0.2°C
Supply Voltage 3 V to 5 V
I2C Interface

 

Schematic

 

Code

#include<Wire.h>
 
// HDC1008 I2C address is 0x40(64)
#define hdcAddr 0x40
 
void setup()
{
  Wire.begin();
  Serial.begin(9600);
 
  // Starts I2C communication
  Wire.beginTransmission(hdcAddr);
  // Select configuration register
  Wire.write(0x02);
  // Temperature, humidity enabled, resolultion = 14-bits, heater on
  Wire.write(0x30);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(300);
}
 
void loop()
{
  unsigned int data[2];
 
  Wire.beginTransmission(hdcAddr);
  // Send temp measurement command
  Wire.write(0x00);
  Wire.endTransmission();
  delay(500);
 
  // Request 2 bytes of data
  Wire.requestFrom(hdcAddr, 2);
 
  // Read 2 bytes of data for temperature
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
 
  int temp = (data[0] * 256) + data[1];
  float celsTemp = (temp / 65536.0) * 165.0 - 40;
  float fahrTemp = celsTemp * 1.8 + 32;
 
 
  Wire.beginTransmission(hdcAddr);
  // Send humidity measurement command
  Wire.write(0x01);
  Wire.endTransmission();
  delay(500);
 
  // Request 2 bytes of data
  Wire.requestFrom(hdcAddr, 2);
  // Read 2 bytes of data to get humidity
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
 
  // Convert the data
  float humidity = (data[0] * 256) + data[1];
  humidity = (humidity / 65536.0) * 100.0;
 
  Serial.print("Humidity : ");
  Serial.print(humidity);
  Serial.println(" %RH");
  Serial.print("Celsius : ");
  Serial.print(celsTemp);
  Serial.println(" C");
  Serial.print("Fahrenheit : ");
  Serial.print(fahrTemp);
  Serial.println(" F");
  delay(500);
}

Output

Open the serial monitor and you should see something like this

Humidity : 43.26 %RH
Celsius : 28.07 C
Fahrenheit : 82.52 F
Humidity : 46.03 %RH
Celsius : 28.70 C
Fahrenheit : 83.67 F
Humidity : 48.71 %RH
Celsius : 29.38 C
Fahrenheit : 84.88 F
Humidity : 51.26 %RH
Celsius : 29.74 C
Fahrenheit : 85.53 F

 

Links
HDC1008 Digital Humidity and Temperature Sensor Breakout Board

Share