HIH-4030 Humidity Sensor Hookup Guide

Pages
Contributors: TheDarkSaint
Favorited Favorite 2

Introduction

The SparkFun HIH-4030 Humidity Sensor Breakout measures relative humidity (%RH) from Honeywell's HIH-4030 humidity sensor. The breakout allows you to connect the analog output of the sensor directly to an ADC on a microcontroller.

SparkFun Humidity Sensor Breakout - HIH-4030

SEN-09569
7

Voltage applied to the supply pins should be within 4-5.8 VDC, and optimally at 5V. The sensor will typically only consume about 200μA.

This tutorial serves as a introduction to the HIH-4030 and the SparkFun Humidity Sensor Breakout. It covers both the hardware and firmware requirements of the breakout to start receiving relative humidity (%RH) measurements as well as documenting example wiring, Arduino code and using the sensor in conjunction with a thermometer.

As we step through the Hookup Guide, you'll find it useful to have the HIH-4030 Datasheet on hand.

HIH-4030 Datasheet

Required Materials

To get the humidity sensor up and running, you'll need the following parts. Further in the tutorial, you'll learn how to incorporate a temperature sensor, specifically SparkFun's Digital Temperature Sensor Breakout - TMP-102, for properly determining relative humidity (%RH). Note that adding a temperature sensor is optional, but its use will be highlighted in this tutorial.

Suggested Reading

Before getting started with the HIH-4030, you should ensure you are familiar with the following topics:

Voltage, Current, Resistance, and Ohm's Law

Learn about Ohm's Law, one of the most fundamental equations in all electrical engineering.

Analog to Digital Conversion

The world is analog. Use analog to digital conversion to help digital devices interpret the world.

Logic Levels

Learn the difference between 3.3V and 5V devices and logic levels.

Analog vs. Digital

This tutorial covers the concept of analog and digital signals, as they relate to electronics.

Hardware Overview

The RH sensor uses a laser trimmed, thermoset polymer capacitive sensing element with on-chip integrated signal conditioning. The sensing element's multilayer construction provides excellent resistance to most application hazards such as condensation, dust, dirt, oils and common environmental chemicals.

Protective Tape Removal

The HIH-4030 comes with a protective tape on the cover (sensing face). This tape is kept in place during our soldering process here at SparkFun. When you receive your HIH-4030 Breakout, you'll want to remove the protective tape.

HIH-4030 Tape Removal

Protective Tape Removal

Reference: Installation Instructions for the HIH-4030/4031 Humidity Sensors
Useful tool to aid in this process: ESD Safe Tweezers

  • Use proper Electrostatic Discharge (ESD) protection
  • Use finger cots to ensure that no foreign debris falls into the filter, sensor cover or die
  • Remove protective tape according to the diagram below

  • alt text

    Pinout

    The three pin breakouts on the HIH-4030 Breakout board make it easy to measure relative humidity (%RH) as an analog voltage.

    HIH-4030 Pinout

    PinDescription
    GNDGround
    OUTVoltage Output
    5VSupply Voltage (5V)

    Voltage applied to the supply pins should be within 4-5.8VDC, optimally at 5V, making it perfect to power with your 5V / GND connections on your microcontroller shield like an Arduino or SparkFun Redboard. The data pin can be connected to an analog input of an Arduino, XBee, RaspberryPi, or any other IO device. The HIH-4030 has a low-power design. The sensor will typically only consume about 200μA.

    Humidity Sensor Re-Conditioning

    Humidity Sensors make use of a conductive polymer to measure relative humidity. If that polymer gets too dry (or over-saturated) the sensor won't function properly, but that can be reversed.

    Any humidity sensors on our designs are put through a re-conditioning procedure to ensure that they keep their factory calibration. If you expose your sensor to a really dry environment for a prolonged period of time (or saturate it in a very humid environment) you may have to run it through the same process.

    Hardware Hookup

    This product comes with the HIH-4030 soldered onto the breakout board. The pins of the 3-pin header are spaced by 0.1".

    alt text

    Before you can insert the HIH-4030 Breakout into a breadboard, you'll need to solder either wires or a 3-pin header to the GND, OUT, and 5V on-board connections. If you plan on breadboarding, we recommend straight male headers. Here, right angle headers were used, which is another viable option.

    HIH-4030 Breakout and Breadboard

    Example Circuit with HIH-4030 Only

    With the HIH-4030 Breakout, all you need is three wires between your microcontroller and the breakout board: Power, Ground, and Analog Output. This is a simplified circuit that should only be used to get your Humidity Sensor up and running. Here is an example hookup diagram demonstrating how to connect the board up to a SparkFun RedBoard:

    Wiring Diagram HIH-4030

    Example Circuit with TMP102 Temperature Sensor

    Determining Relative Humidity (RH%) requires knowing an accurate temperature. The previous circuit example does not utilize this feature, therefore, it will be necessary to to use your HIH-4030 Breakout in conjunction with a Temperature Sensor. For this Hookup Guide, we have used the TMP102 Breakout.

    SparkFun Digital Temperature Sensor Breakout - TMP102

    SparkFun Digital Temperature Sensor Breakout - TMP102

    SEN-13314
    $5.50
    6

    The TMP102 is a digital sensor that communicates over I2C, has a resolution of 0.0625°C, and is accurate up to 0.5°C. There is no on-board voltage regulator, so supplied voltage should be between 1.4 to 3.6V. Do not hook up the TMP102 VCC to 5V. You'll want to use 3.3V on your Arduino or SparkFun RedBoard for this connection. As an additional resource, refer to the TMP102 datasheet.

    You'll notice from the figure below, found on page three of the HIH-4030 sensor datasheet, the recommended operating temperature is between -40 and 85 °C (or -40 and 185 °F). If the operating zone lies outside either the recommended temperature or humidity extreme, the sensor is only specified to be accurate for 50 hours or less.

    Operating Environment

    Since this is an I2C device, the connections you'll be most concerned with is the SDA (Data) and SCL (Clock) pins on either an Arduino or SparkFun RedBoard. Here is an example hookup diagram demonstrating how to connect the HIH-4030 Breakout with a TMP102 Digital Temperature Sensor board up to a SparkFun RedBoard:

    Wiring Diagram HIH-4030 with TMP-102

    Click the image for a closer look.

    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));
    }
    

    Resources and Going Further

    For more on the HIH-4030 Humidity Sensor, check out the links below:

    Need some inspiration for your next project? Check out some of these related tutorials:

    Photon Remote Water Level Sensor

    Learn how to build a remote water level sensor for a water storage tank and how to automate a pump based off the readings!

    Humidity-sensing LED Flower

    How about that humidity? This tutorial shows how to add sensing capability to the 21st Century Fashion Kit's RGB flower project.

    Environmental Monitoring with the Tessel 2

    Build an air-conditioner monitoring device to collect environment information and store it in the cloud.