Do you know the HDC1080 temperature and humidity sensor? it is an integrated sensor made by Texas Instruments, capable of measuring temperature and humidity while communicating via i2c to any microcontroller.
Its datasheet states that humidity can be measured between 0% and 100% of relative humidity (RH). Temperature range is from 0ºC all the way to +125ºC. Supply voltages are between 2.7V and 5.5V, consuming around 150-275 uA (micro amperes) – depends on operation temperature.
One can find HDC1080 on Aliexpress on my affiliate link, It costs (at the time of this writing) around US$2. Let’s then see how we can wire and connect it to ESP32 (or Arduino, your choice).
Wiring
As stated above this sensor connects to any microcontroller via i2c, a protocol that uses only two wires (data and clock). Of course one needs +3.3V and GND, so really four wires. We have seen other sensors that use i2c in the blog before, like this and this.
Assembling the kit on a breadboard will look like below:
One important thing is to close both jumpers on top of the sensor, since they represent the pull-up resistors necessary for i2c proper functioning. See the picture below.
Firmware/sketch/code
There is a nicely done library for the Arduino IDE, made to work with HDC1080. Open you Arduino IDE, go to “Sketch > Include library > Manage libraries..” and type “ClosedCube HDC1080”. Find the one made by ClosedCube and install it.
Let’s then use an example pre-made that comes with the library, go to “File > Examples > ClosedCube HDC1080 > hdc1080measurement”, it is reproduced below.
/**************************************************************************************
This is example for ClosedCube HDC1080 Humidity and Temperature Sensor breakout booard
Initial Date: 07-Jun-2017
Hardware connections for Arduino Uno:
VDD to 3.3V DC
SCL to A5
SDA to A4
GND to common ground
Written by AA for ClosedCube
MIT License
**************************************************************************************/
#include <Wire.h>
#include "ClosedCube_HDC1080.h"
ClosedCube_HDC1080 hdc1080;
void setup()
{
Serial.begin(9600);
Serial.println("ClosedCube HDC1080 Measurement Resolutions Arduino Test");
hdc1080.begin(0x40);
Serial.print("Manufacturer ID=0x");
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
/*printTandRH(HDC1080_RESOLUTION_8BIT, HDC1080_RESOLUTION_11BIT);
printTandRH(HDC1080_RESOLUTION_11BIT, HDC1080_RESOLUTION_11BIT);
printTandRH(HDC1080_RESOLUTION_14BIT, HDC1080_RESOLUTION_11BIT);
printTandRH(HDC1080_RESOLUTION_8BIT, HDC1080_RESOLUTION_14BIT);
printTandRH(HDC1080_RESOLUTION_11BIT, HDC1080_RESOLUTION_14BIT);
printTandRH(HDC1080_RESOLUTION_14BIT, HDC1080_RESOLUTION_14BIT);*/
}
void loop()
{
printTandRH(HDC1080_RESOLUTION_11BIT, HDC1080_RESOLUTION_11BIT);
delay(1000);
}
void printTandRH(HDC1080_MeasurementResolution humidity, HDC1080_MeasurementResolution temperature) {
hdc1080.setResolution(humidity, temperature);
HDC1080_Registers reg = hdc1080.readRegister();
//printRegister(reg);
Serial.print("T=");
Serial.print(hdc1080.readTemperature());
Serial.print("C, RH=");
Serial.print(hdc1080.readHumidity());
Serial.println("%");
}
void printRegister(HDC1080_Registers reg) {
Serial.print("Measurement Resolution: T=");
Serial.print(reg.TemperatureMeasurementResolution, BIN);
Serial.print(" (0=14 bit, 1=11 bit)");
Serial.print(" RH=");
Serial.print(reg.HumidityMeasurementResolution, BIN);
Serial.println(" (00=14 bit, 01=11 bit, 10=8 bit)");
}
I just modified it not to show its measurement resolution and other non-important things, just temperature and humidity. What’s important in the code above are the “hdc1080.readHumidity()” and ‘hdc1080.readTemperature()” functions, responsible for bringing us the intended values.
End result
I then made a video about the sensor testing, very instructive and informative. Enjoy and having any questions please comment in the Youtube video or down below in the comments section.
Leave a Reply