Tag Archives: hh10d

Humidity Sensor HH10D

Sometime back, I ordered a HH10D, humidity sensor from sparkfun with the idea of integrating this sensor with an Arduino Pro (3.3V). This is a relatively cheap relative humidity sensor with an accuracy of about 3% sufficient for measuring  humidity at home.


The sensor is pretty straightforward to use, once you figure out the mistakes in its data sheet. The sensor stores some calibration constants (sensitivity and an offset value) in an EEPROM packaged with sensor. The data from the EEPROM can be read using I2C (Arduino Wire Library). After that the sensor just returns frequency that can be measured and the RH can be calculated using the formula in the datasheet.

Couple of things to note about the datasheet:
– Device address is 81
– Though the device is marked as an I2C, the I2C communication is only required to read the constants from the EEPROM.

Once the constants have been read the sensor can be directly used without ever needing to connect the I2C lines. Another tricky thing with the sensor is an accurate way of measuring the frequency! A simple pulseIn approach will give wildly fluctuating results due to errors in measuring the frequency. To overcome this, there are a couple of suggestions that I discovered on the web:

РUsing the FreqCounter library. This library uses the internal timers to measure the frequency accurately. You can download and get more details of this library from: http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/
– Averaging the frequency measurements with pulseIn

Though the FreqCounter library is more accurate, there is something to be said for the flexibility and ease of the second method.

I have wrapped both the approaches along with all the functionalities of the sensor in a class (HH10D). The class makes it easy to choose either method and allows customizations for measurements. The code is well documented, so please feel free to check it out at: http://www.mediafire.com/?0k9efr0g38bng

UPDATE: Library for Arduino 1.0 and higher can be downloaded from https://www.box.com/s/ody8705fmjtc3zimfakt

Below is a sample program using the library!

#include "WProgram.h"
#include "FreqCounter.h" // Optional (not required by this code)
#include "Wire.h" // Required once to get the constants
#include "HH10D.h"  //HH10D library

using namespace std;

HH10D humid(6); //Not using FreqCounter library

void setup()
    humid.setup();   // Reads the constants from the EEPROM
    humid.setSampleSize(2048); // Number of samples to average the humidity value

void loop()
    // Get RH
    float rh = humid.getRH();

int main(void)
	for (;;)
	return 0;