Humidity Sensor Retail


The HIH-4030 Humidity Sensor breakout is a great way to measure humidity when getting started with projects like weather sensor networks. It draws very low current, and is hilariously simple to use. The output is a simple analog voltage, and when read with the ADC pin of a microcontroller, can be very easily translated into an accurate measure of relative humidity. The output of the sensor is linear, so with some simple math one can translate the voltage from the device into real-world percent relative humidity values.

Note: The one major factor that will effect the accuracy of the device is temperature. The graph on page three of the sensor datasheet shows that the sensor works best in between the temperatures of 0 and 50 degrees Celsius (32 to 122 degrees Fahrenheit), or if the humidity is low enough, -40 to 85 degrees Celsius (-40 to 185 degrees Fahrenheit). If the operating environment is too far outside of these parameters, the sensor is only specified to be accurate for less than 50 hours or less.

The sensor works best in an environment of 25 degrees Celsius when its input voltage is 5V. This gives the best linear response from the device.

Connecting and reading the sensor is simple. For this example we'll use an Arduino UNO for the controller and some M/F jumper wires and headers to make the connection. The Arduino UNO already comes with female headers soldered in place, so the first step is to solder headers to the sensor. If you need to learn basic soldering, make sure to read our Soldering 101 tutorial.

Now that the headers are on, we can easily connect the humidity sensor to the Arduino with the jumper wires. Connect the 5V and ground lines on the sensor to the 5V and ground lines on the Arduino, and then connect the OV (output voltage) line on the sensor to the A0 (analog 0 pin) on the Arduino.

The A0 pin is an ADC line, which in this case means that when it is read by the Arduino, it returns a value somewhere in between 0 and 1023, 0 corresponding to a voltage of 0V, and 1023 corresponding to a voltage of 5V. To read this line, we need a simple sketch. Connect the Arduino to the computer, open the Arduino IDE and load up this example sketch, reprinted below.

 

    // Simple sketch to demonstrate the HIH-4030 Humidity Sensor from SparkFun
// Outputs %RH based on voltage coming from sensor
// Written 01/28/11

float adcValue = 0;
float voltage = 0;
float percentRH = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  adcValue = analogRead(0); // Read voltage coming from sensor (adcValue will be between 0-1023)
  voltage = (adcValue/1023.0)*5.0; // Translate ADC value into a voltage value
  percentRH = (voltage-0.958)/0.0307; // Translate voltage into percent relative humidity
  
  // Print value
  Serial.print("%RH = ");
  Serial.println(percentRH,DEC); 
  
  // Delay for one second
  delay(1000);
}

 

This sketch will read the voltage coming from the sensor, translate the voltage into a percent relative humidity, and print it out. Upload the sketch to the board, and then open the Arduino serial terminal. Make sure the baud rate is set to 9600. The Arduino should start printing voltage and humidity values every second. Try blowing on the sensor (or just stick it in your mouth like I did) to see the relative humidity go up.

In order to take an analog value (what the sensor is outputting) and transform it into a percent relative humidity, we can use the graph values from page 4 of the HIH-4030 datasheet. Before that, however, we need to be able to translate the read Arduino value into a voltage. In order to do that, we can use the following equation:

Voltage = ((Arduino Value) / 1023) * 5

So, for example, if the Arduino value is 300, the voltage the sensor is outputting is 1.47 volts. Now that we have a voltage, we can use the following equation to translated this value into a relative humidity (%RH).

%RH = (Voltage – Zero Offset) / Slope

When we use the example zero offset and slope from the data sheet, along with the example voltage from above, we come up with

%RH = (1.47 – 0.958) / 0.0307

%RH = 16.7

All of these equations and operations is what the example Arduino sketch uses to calculate relative humidity. Please note that these sensors have a certain tolerance for error, so your Zero Offset and Slope values might not exactly match what is given in the datasheet.

Comments 1 comment

  • Member #634465 / about 10 years ago / 1

    I'm disappointed that the sensor does not come with the necessary calibration information. Buyers should beware that the result will be inaccurate unless you can determine the zero offset and slope yourself.