Arduino HDC2010 Read Data and Comfort Zone Alerts

Arduino HDC2010 Read Data and Comfort Zone Alerts

How to read HDC2010 temperature and humidity sensor data and comfort zone alerts Arduino using HDC2010 I2C breakout by itbrainpower.net.

  • 14 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

Ide web
Arduino IDE
use version >=1.8.5

About this project

Texas Instruments HDC2010 is a high accuracy digital temperature and humidity sensor. Main measurement characteristics:

  • relative humidity range 0% - 100%
  • humidity accuracy +-2% (factory calibrated)
  • temperature from -40C to +125C (functional) and -40C to +80C (operational)
  • typical temperature accuracy +-0.2C (factory calibrated)
  • embedded heating element to burn away condensation

More info on: HDC2010 datasheet.

In June 2019 we've released 6 new environmental and air quality sensors, including HDC2010 I2C sensor breakout and HDC2010 + CCS811 I2C combo sensors breakout, all being part of the s-Sense I2C sensor breakout family.

PN: SS-HDC2010#I2C SKU: ITBP-6005 HDC2010 I2C sensor breakout info

PN: SS-HDC2010+CCS811#I2C SKU: ITBP-6006 HDC2010+CCS811 I2C combo sensor breakout info

Next, let's kickstart with HDC2010 sensor I2C breakout - around 10-15 minutes. Same hardware and software approach may be used for CCS811 + HDC2010 bundle sensors I2C breakout.

Arduino HDC2010 sensor hardware integration (basic wiring)

First, identify if your Arduino it's 5V or 3.3V compliant! The HDC2010 I2C sensor breakout it's shipped in default auto 3-5V compliant configuration. Just wire as bellow:

HINT, for some ARDUINO boards:

  • SDA (Serial Data) --> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
  • SCK (Serial Clock) --> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

Bellow, sensor wiring examples, left to right, with Arduino UNO and xyz-mIoT

shield [AT SAMD21G, 3.3V compliant, with or without modems]:

Arduino HDC2010 read sensor data software

  • a. download HDC2010 Arduino library from: here.
  • b. unzip the library and install in Arduino libraries folder. Restart Arduino.
  • c. Make a folder named "ssense_HDC2010_example". Download and save the code bellow (right click & save as) - use ssense_HDC2010_example.ino as name: HDC2010 - read sensor data Arduino code or, use the ssense_HDC2010_example from Arduino "File-> Examples", under "ssense-HDC2010" library.
  • d. Compile and upload the code to your Arduino shield. The sensor data may be seen on Arduino Serial Monitor (set to 19200bps).

Advanced HDC2010 feature [windowed mode]

HDC2010 have some interesting features (read datasheet) - one of them being the temperature and humidity "comfort zone" monitoring.

In a nut shell, the HDC2010 firmware compare the temperature and humidity sampled data with defined comfort zone temperature and humidity upper and lower limits. If sampled data are outside the defined window one interrupt it's generated. Window threshold values and IRQ behavior are user programmable.

HDC2010 - windowed alerts mode Arduino code- written to be compatible with Arduino Zero and xyz-mIoT shields - do this job. As hardware preliminary, just wire the shields as shown in basic wiring, up-here, and add wire between sensor PAD9 [placed on sensor bottom] to D6 on Arduino Zero/xyz-mIoT shield.

This code it's available also in Arduino "File-> Examples", under "ssense-HDC2010" library.

HINT - to port previous code to other Arduino shields (let's say for Arduino UNO):

  • step1. identify one IO INTERRUPT capable pin - Arduino UNO you may like chose D2 or D3.
  • step2 -variant a. adapt the alertTHS() ISR function and attachInterrupt() call in a way to be compatible with your board or,
  • step2 -variant b. remove/comment the attachInterrupt() call in setup() and pull the alertTHS() function in loop(). In this case you may use any available digital IO.

TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

Code

ssense_HDC2010_comfort_zone_IRQ_example.inoArduino
!!! INTERRUPTS code it's compatible with Arduino Zero and xyz-mIoT shields !!!

Set HDC2010 windowed comfort zone mode and IRQ mode. Read and print HDC2010 [temperature and humidity] sensor data - pulling rate ~ 2 second. If temperature / humidity sampled value goes outside comfort zone, one exception will be sinalized via PAD9 of the HDC2010 breakout.

Just wire the sensor with your Arduino board in basic mode and add wire between sensor PAD9 <------> Arduino D6 (this is for INTERRUPT) .

Compile and upload code. Set Serial Monitor at 19200bps.
/* s-Sense I2C HDC2010 I2C sensor breakout example with comfort zone by IRQ - v1.0/20190524.
 *
 * 		IMPROTANT! IRQ should work for Arduino Zero and xyz-mIoT [AT SAMD21G in Arduino Zero like configuration]  
 *
 * This library it's compatible with:
 *    s-Sense HDC2010 I2C sensor breakout [PN: SS-HDC2010#I2C, SKU: ITBP-6005], info https://itbrainpower.net/sensors/HDC2010-TEMPERATURE-HUMIDITY-I2C-sensor-breakout 
 *    s-Sense CCS811 + HDC2010 I2C sensor breakout [PN: SS-HDC2010+CCS811#I2C, SKU: ITBP-6006], info https://itbrainpower.net/sensors/CCS811-HDC2010-CO2-TVOC-TEMPERATURE-HUMIDITY-I2C-sensor-breakout
 * 
 * HDC2010 temperature and humidity (pulling at 2 second and confort zone -interrupt based) reading example - based on HDC2010 library written 
 * by Brandon Fisher and provided by TI. Thank you Brandon! Great job! Read credits bellow and inside the class.
 * We've just add add some variables, functions and functionalities.
 * 
 *  Mandatory wiring:
 *    Common for 3.3V and 5V Arduino boards:
 *        sensor I2C SDA  <------> Arduino I2C SDA
 *        sensor I2C SCL  <------> Arduino I2C SCL
 *        sensor GND      <------> Arduino GND
 *    For Arduino 3.3V compatible:
 *        sensor Vin      <------> Arduino 3.3V
 *    For Arduino 5V compatible:
 *        sensor Vin      <------> Arduino 5V
 *        
 *  Optional wiring (only for INTERRUPT detection):
 *        sensor PAD9     <------> Arduino D6
 *   
 * Leave other sensor PADS not connected.
 *  
 * SPECIAL note for some ARDUINO boards:
 *        SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
 *        SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
 * 
 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
 * 
 * READ HDC2010 documentation! https://itbrainpower.net/downloadables/hdc2010.pdf
 * 
 * You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH s-Sense HDC2010 I2C sensors DEVICES USAGE. Modifications, derivates and redistribution 
 * of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms 
 * of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
 * 
 * This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE.
 *  
 *  
 * itbrainpower.net invests significant time in design phase of our IoT products and in associated software and support resources.
 * Support us by purchasing our environmental and air quality sensors from here https://itbrainpower.net/order#s-Sense
 *
 *
 *
 * Dragos Iosub, Bucharest 2019.
 * https://itbrainpower.net
 */

/*
 * HDC2010.ino
 * Created: August 1st 2017
 * This sketch is released AS-IS into the public domain, no guarantee or warranty is given.
 * This Code is not supported by Texas Instruments.
 * 
 * Description: This sketch configures the HDC2010 to monitor for a specific temperature 
 * and humidity range, with regular one second samples. The temperature and humidity readings
 * of the device are printed to a standard 16x2 LCD display. When the threshold values are
 * exceeded, the LCD will also have "ALT" printed in the bottom right corner. The schematic 
 * for this example is included alongside the HDC2010 Arduino Source Code.
 * 
 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the   
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
*/

#define SERIAL_SPEED  19200

#include <sSense-HDC2010.h>

HDC2010 ssenseHDC2010(HDC2010_I2C_ADDR);


float temperature = 0, humidity = 0;
int alarmTHS = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  DebugPort.begin(SERIAL_SPEED);
  delay(5000);
  DebugPort.println("s-Sense HDC2010 I2C sensor test w. confort zone.");
  DebugPort.println("this code was writen for Arduino Zero and xyz-mIoT [AT SAMD21G in Arduino Zero like configuration]");

  // Initialize HDC2010(THS) I2C communication
  ssenseHDC2010.begin();
    
  // Begin with a HDC2010(THS) reset
  ssenseHDC2010.reset();

  // Set up HDC2010(THS) temperature offset, if required
  //ssenseHDC2010.setTemperatureOffset(0b11010111);    //-6.64 degrees Celsius - determine and set your, see definitions and HDC2010 datasheet

  
  // Set up HDC2010(THS) comfort zone
  ssenseHDC2010.setHighTemp(28);         // High temperature of 28C
  ssenseHDC2010.setLowTemp(24);          // Low temperature of 22C
  ssenseHDC2010.setHighHumidity(85);     // High humidity of 55%
  ssenseHDC2010.setLowHumidity(20);      // Low humidity of 40%
  

  // Configure HDC2010(THS) interrupt mode
  ssenseHDC2010.enableInterrupt();                   // Enable the Interrupt/DRDY pin
  ssenseHDC2010.enableThresholdInterrupt();          // Enable Interrupt triggering based on comfort zone
  ssenseHDC2010.setInterruptPolarity(ACTIVE_HIGH);   // Set Interrupt pin to Active High
  ssenseHDC2010.setInterruptMode(COMPARATOR_MODE);   // Set Interrupt to return to inactive state when in bounds

  
  // Configure Measurements
  ssenseHDC2010.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  ssenseHDC2010.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  ssenseHDC2010.setTempRes(FOURTEEN_BIT);
  ssenseHDC2010.setHumidRes(FOURTEEN_BIT);

  
  // Configure HDC2010(THS) Interrupt Pin
  pinMode(HDC2010_IRQ_PIN, INPUT);                 // HDC2010_IRQ_PIN will be the interrupt input
  attachInterrupt(digitalPinToInterrupt(HDC2010_IRQ_PIN), alertTHS, CHANGE);  //ISR "alert" will be triggered by changes in HDC2010_IRQ_PIN

  
  delay(1000);

  //begin HDC2010 sensor measuring
  ssenseHDC2010.triggerMeasurement();
}

void loop() {
  // read temperature and humidity
  temperature = ssenseHDC2010.readTemp();
  humidity = ssenseHDC2010.readHumidity();

  DebugPort.print("TEMP(C): ");
  DebugPort.println(temperature);

  DebugPort.print("%RH: ");
  DebugPort.println(humidity);

  // Wait 2 second for the next reading
  delay(2000);
}

// ISR to print alert on "CONFORT ZONE"
void alertTHS(void) {
  //Load the current state of the THS Alert Pin to the alarmTHS variable
  alarmTHS = digitalRead(HDC2010_IRQ_PIN);

  //If the alert pin was high, print ALT
  if (alarmTHS)
    {
      DebugPort.println("OUTSIDE");
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    }
  //Otherwise overwrite "ALT" with spaces
  else
    {
      DebugPort.println("INSIDE");
      digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (LOW is the voltage level)
    }
}
ssense_HDC2010_example.inoArduino
Read and print HDC2010 [temperature and humidity] sensor data - pulling rate ~ 2 second.

Just wire the sensor with your Arduino board. Select your board, compile and upload code. Set Serial Monitor at 19200bps.
/* s-Sense I2C HDC2010 I2C sensor breakout example - v1.0/20190524.
 * 
 * This library it's compatible with:
 *    s-Sense HDC2010 I2C sensor breakout [PN: SS-HDC2010#I2C, SKU: ITBP-6005], info https://itbrainpower.net/sensors/HDC2010-TEMPERATURE-HUMIDITY-I2C-sensor-breakout 
 *    s-Sense CCS811 + HDC2010 I2C sensor breakout [PN: SS-HDC2010+CCS811#I2C, SKU: ITBP-6006], info https://itbrainpower.net/sensors/CCS811-HDC2010-CO2-TVOC-TEMPERATURE-HUMIDITY-I2C-sensor-breakout
 * 
 * HDC2010 temperature and humidity (pulling at 2 second) reading example - based on HDC2010 library written 
 * by Brandon Fisher and provided by TI. Thank you Brandon! Great job! Read credits bellow and inside the class.
 * We've just add add some variables, functions and functionalities.
 * 
 *  Mandatory wiring:
 *    Common for 3.3V and 5V Arduino boards:
 *        sensor I2C SDA  <------> Arduino I2C SDA
 *        sensor I2C SCL  <------> Arduino I2C SCL
 *        sensor GND      <------> Arduino GND
 *    For Arduino 3.3V compatible:
 *        sensor Vin      <------> Arduino 3.3V
 *    For Arduino 5V compatible:
 *        sensor Vin      <------> Arduino 5V
 *        
 * Leave other sensor PADS not connected.
 *  
 * SPECIAL note for some ARDUINO boards:
 *        SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
 *        SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
 * 
 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
 * 
 * READ HDC2010 documentation! https://itbrainpower.net/downloadables/hdc2010.pdf
 * 
 * You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH s-Sense HDC2010 I2C sensors DEVICES USAGE. Modifications, derivates and redistribution 
 * of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms 
 * of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
 * 
 * This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE.
 *  
 *  
 * itbrainpower.net invests significant time in design phase of our IoT products and in associated software and support resources.
 * Support us by purchasing our environmental and air quality sensors from here https://itbrainpower.net/order#s-Sense
 *
 *
 *
 * Dragos Iosub, Bucharest 2019.
 * https://itbrainpower.net
 */

/*
 * HDC2010.ino
 * Created: August 1st 2017
 * This sketch is released AS-IS into the public domain, no guarantee or warranty is given.
 * This Code is not supported by Texas Instruments.
 * 
 * Description: This sketch configures the HDC2010 to monitor for a specific temperature 
 * and humidity range, with regular one second samples. The temperature and humidity readings
 * of the device are printed to a standard 16x2 LCD display. When the threshold values are
 * exceeded, the LCD will also have "ALT" printed in the bottom right corner. The schematic 
 * for this example is included alongside the HDC2010 Arduino Source Code.
 * 
 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the   
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
*/

#define SERIAL_SPEED  19200

#include <sSense-HDC2010.h>

HDC2010 ssenseHDC2010(HDC2010_I2C_ADDR);


float temperature = 0, humidity = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  DebugPort.begin(SERIAL_SPEED);
  delay(5000);
  DebugPort.println("s-Sense HDC2010 I2C sensor.");

  // Initialize HDC2010(THS) I2C communication
  ssenseHDC2010.begin();
    
  // Begin with a HDC2010(THS) reset
  ssenseHDC2010.reset();

  // Set up HDC2010(THS) temperature offset, if required
  //ssenseHDC2010.setTemperatureOffset(0b11010111);    //-6.64 degrees Celsius - determine and set your, see definitions and HDC2010 datasheet
 
  // Configure Measurements
  ssenseHDC2010.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  ssenseHDC2010.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  ssenseHDC2010.setTempRes(FOURTEEN_BIT);
  ssenseHDC2010.setHumidRes(FOURTEEN_BIT);

  
  delay(1000);

  //begin HDC2010 sensor measuring
  ssenseHDC2010.triggerMeasurement();
}

void loop() {
  // read temperature and humidity
  temperature = ssenseHDC2010.readTemp();
  humidity = ssenseHDC2010.readHumidity();

  DebugPort.print("TEMP(C): ");
  DebugPort.println(temperature);

  DebugPort.print("%RH: ");
  DebugPort.println(humidity);

  // Wait 2 second for the next reading
  delay(2000);
}
Arduino HDC2010 libraryC/C++
Arduino library to access Texas Instruments [high accuracy temperature and humidity] sensor data - adapted for itbrainpower.net s-Sense HDC2010 sensor I2C breakout and itbrainpower.net s-Sense HDC2010 + CCS811 bundled sensor I2C breakout -compatible with 3.3V - 5V Arduino shields.

This code it's based on HDC2010 library originally written by Brandon Fisher and provided by TI. Thank you Brandon! Great job! Read credits bellow and inside the class. We've just add add some variables, functions and functionalities.

Extract and copy the class in Arduino Library folder - 'libraries' folder found in your Arduino Sketchbook. Take a look at "readme.md" and/or "readme.md" files.

Couple examples are available in Arduino "File-> Examples", under "ssense-HDC2010" library.
No preview (download only).

Schematics

HDC2010 sensor wiring example with Arduino UNO
5V compliant Arduino board - wire as shown in the image.
For 3.3V compliant Arduino board, wire Vin to Arduino 3.3V pad NOT to 5V!!!
Hdc2010 arduino wiring uno fhdffputke
HDC2010 sensor wiring example with xyz-mIoT shield [AT SAMD21G, 3.3V compliant]
3.3V compliant Arduino board - wire as shown in the image.
For 5V compliant Arduino board, wire Vin to Arduino 5V pad NOT to 3.3V!!!
Hdc2010 arduino wiring xyz miot wrlr1xhvmf
CCS811+HDC2010 breakout datasheet
s-Sense CCS811+HDC2010 I2C sensor breakout datasheet
HDC2010 breakout datasheet
s-Sense HDC2010 I2C sensor breakout datasheet

Comments

Similar projects you might like

Temperature Streaming with Arduino + Big Data Tools

Project showcase by Gabriel Rodriguez

  • 7,575 views
  • 1 comment
  • 33 respects

Publish Your Arduino Data to the Cloud

by Jaume Miralles

  • 7,138 views
  • 13 comments
  • 50 respects

Get Data from the Cloud to Your Arduino

by Jaume Miralles

  • 4,643 views
  • 5 comments
  • 23 respects

IoT Treat Dispenser For Pets

Project tutorial by Arduino “having11” Guy

  • 14,409 views
  • 0 comments
  • 49 respects

Using the RAK811 LoRa module with Arduino

Project tutorial by Naresh krish

  • 10,662 views
  • 4 comments
  • 11 respects
Add projectSign up / Login