HIH-4030 Humidity Sensor Hookup Guide

Pages
Contributors: TheDarkSaint
Favorited Favorite 2

Using the SparkFun HIH-4030 Arduino Library

We've written an Arduino library for the HIH-4030, which takes care of all your user specifications and calculating of formula found in the datasheet. Grab the most recent version of the library from our SparkFun_HIH4030_Arduino_Library GitHub repository:

If you need any help with the installation process, check out the How to Install an Arduino Library tutorial. If you download the library's ZIP file, you can use Arduino's "Add ZIP Library..." feature to install the source and example files.

Adding Library

Using the HIH4030_HumiditySensor_Example

Once you've downloaded the library, open the HIH4030_HumiditySensor_Example by navigating to File > Examples > SparkFun Humidity Sensor Breakout - HIH4030 > HIH4030_HumiditySensor_Example:

Open Example Program

You'll also want to make sure your board and port are correctly set in the Arduino IDE window before uploading the code:

Board, Port and Upload

Once the upload is complete, you can click over to the Serial Monitor. Make sure the baud rate is set to 9600 bps, and you should begin to see the Tempearture, Sensor Voltage, Relative Humidity and True Relative Humidity scroll across the screen:

Serial Monitor Output

Customizing Settings in Code

Initialization

To begin, make sure you include the SparkFun_HIH4030.h library. If using a temperature sensor, you'll need to include Wire.h the Arduino I2C library:

language:c
#include <SparkFunDS1307RTC.h>
#include <Wire.h>

Temperature Sensor Settings

The code by default is using a static value for the temperature reading.

language:c
// Are You Using a Temperature Sensor? 1 = YES / 0 = NO
int tempSensor = 0;

You can change the temp variable from 25 degrees Celsius to any desired value to see how it affects the Relative Humidity (RH%).

Static Temperature Value

It's important to remember that True Relative Humidity (RH%) requires a known temperature for accurate measurement. As an example, the previous section, Hardware Hookup, demonstrated how to wire both the SparkFun Humidity Sensor Breakout - HIH-4030 and Digital Temperature Sensor Breakout - TMP102. However, you can also use other Temperature Sensors available on the SparkFun storefront: One-Wire Ambient Temperature Sensor - MAX31820, Temperature Sensor - TMP36, One Wire Digital Temperature Sensor - DS18B20, SparkFun Infrared Temperature Breakout - TMP006.

If you are utilizing a Temperature Sensor, you'll want to modify the following code from the default 0 to a 1:

alt text

Humidity Sensor Settings

Two things that need to be defined for the SparkFun_HIH4030 Library is the Analog I/O Pin the HIH-4030 Sensor OUT is connected to and the voltage being supplied to the HIH-4030 Sensor. If your setup reflects the Hardware Hookup section, you can leave the values as is.

language:c
// Analog IO Pin Connected to OUT
#define HIH4030_OUT A0

// Supply Voltage - Typically 5 V
#define HIH4030_SUPPLY 5

Looking Inside the SparkFun_HIH4030 Library

vout( ) function

Since the output of the HIH-4030 Humidity Sensor is nearly linear, the analogRead() function is used and mapped to the correct range. This is where the value you defined for the Supply Voltage in your HIH4030_HumiditySensor_Example code comes into play.

language:cpp
// Read value from the sensor and convert to voltage value
float HIH4030::vout() {
    return (float)(analogRead(pin)) * supply / 1023;
}

getSensorRH( ) function

From the HIH-4030 Datasheet, a Voltage output equation is given on page 2.

VOUT Equation

With the previous vout() function and defined supply voltage, sensor RH can be calculated.

language:cpp
// Convert sensor reading into Relative Humidity (RH%) 
//  using equation from Datasheet
// VOUT = (VSUPPLY)(0.0062(SENSOR RH) + 0.16), 
//  typical at 25 degrees Celsius

float HIH4030::getSensorRH() {
    return ((vout() / (.0062 * supply)) - 25.81);
}

getTrueRH( ) function

The True Relative Humidity euqation is also given on page 2 of the HIH-4030 Datasheet which includes temperature compensation.

True RH Equation

Aforementioned, True Relative Humidity required a known temperature for accurate measurement. The getTrueRH(float temperature) function will take the value of either your static temperature or sensor measurement, whichever is applicable, and calculate True RH.

language:cpp
// Get True Relative Humidity (RH%) compensated 
//  with Static Temperature or Measured Temperature
// TRUE RH = (SENSOR RH)/(1.0546 - 0.00216T), T in degrees Celsius

float HIH4030::getTrueRH(float temperature) {
    return getSensorRH() / (1.0546 - (0.00216 * temperature));
}