ESP32 and HDC1008 temperature sensor example

In this example we will be connecting an HDC1008 module to an ESP32 module, we used a Lolin32 from Wemos but other makes should work fine as well.

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.

hdc1008
hdc1008

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

Connection

The easiest way is to purchase some sort of breakout

Connect Vin to Wemos Lolin 3v3
Connect GND to Wemos Lolin ground
Connect SCL to Wemos Lolin SCL – 22
Connect SDA to Wemos Lolin SDA – 21

lolin32 and hdc1008
lolin32 and hdc1008

Code

The good folks at Adafruit have done the hard work and produced a library for this device – https://github.com/adafruit/Adafruit_HDC1000_Library  . If you are using Arduino IDE 1.6.5 or later you can easily import this library by going to Sketch -> Include Library -> Manage Libraries

Select Wemos Lolin32 in the board manager if you use that module like we did.

#include <Wire.h>
#include "Adafruit_HDC1000.h"

Adafruit_HDC1000 hdc = Adafruit_HDC1000();

void setup()
{
Serial.begin(9600);
Serial.println("HDC100x test");

if (!hdc.begin())
{
Serial.println("Couldn't find sensor!");
while (1);
}
}

void loop()
{
Serial.print("Temp: "); Serial.print(hdc.readTemperature());
Serial.print("\t\tHum: "); Serial.println(hdc.readHumidity());
delay(500);
}

Output

Open the serial monitor and you should see something like this

Temp: 20.20 Hum: 36.56
Temp: 20.20 Hum: 36.56
Temp: 20.24 Hum: 36.56
Temp: 20.30 Hum: 36.66
Temp: 23.94 Hum: 38.20
Temp: 26.15 Hum: 39.37
Temp: 27.02 Hum: 40.29
Temp: 27.59 Hum: 41.10
Temp: 27.88 Hum: 41.69
Temp: 26.21 Hum: 41.22
Temp: 25.80 Hum: 41.10

Links

Adafruit HDC1008 Temperature & Humidity Sensor Breakout Board

SHARE
Previous articleESP32 at instruction set and examples
Next articleESP32 and MCP9808 digital temperature sensor example