HIH-4030 Humidity Sensor Hookup ?

Thread Starter

khalad

Joined Feb 9, 2017
55
hello guys,

I want to use this humidity sensor using arduino i followed the insurrections in the link below but i dont know if i am getting the correct reading i compare it with the reading in the outside but its different i did not use a temperature sensor i just used a fixed number ?

Can someone help me please , is there a way to know if my reading is correct or is this way not correct which i am using ?

https://learn.sparkfun.com/tutorials/hih-4030-humidity-sensor-hookup-guide


upload_2017-3-2_13-24-58.pngphoto5891175476649633874.jpg

C:
/* **************************************************************************************
* HIH4030_HumiditySensor_Example.ino
* E.Robert @ SparkFun Electronics
* original creation date: November 5, 2016
* [URL]https://github.com/sparkfun/SparkFun_HIH4030_Arduino_Library[/URL]
*
* Functions: Allows you to set supply voltage, define whether or not a temperature
*            sensor is being used, define static temperature value in absense of a
*            temperature sensor, and utilize the equations supplied by the manufacturer
*            to acquire accurate measurements of Relative Humidity (RH%).
*           
*            [URL]https://learn.sparkfun.com/tutorials/hih-4030-humidity-sensor-hookup-guide[/URL]
*           
*            Note: TMP102 Sensor is being used in this example as part of the
*                  SparkFun HIH-4030 Humidity Sensor Hookup Guide. However, other
*                  temperature sensors can also be used in this sketch by replacing
*                  the necessary code inside the getTemperature() function.
*
* Resources:
* Wire.h - Arduino I2C Library
* SparkFun_HIH4030.h - Arduino Library for SparkFun Humidity Sensor Breakout - HIH-4030
*
* Development environment specifics:
* Arduino 1.6.8
* SparkFun RedBoard
* SparkFun Real Time Clock Module (v14)
************************************************************************************** */

// Library Inclusions
#include <SparkFun_HIH4030.h>
#include <Wire.h>

// Example Variables
int tempAddress = 0x48;             // I2C: TMP102 Slave Address with ADD0 Grounded
float temp = 0;                     // Temperature Value either Static or Sensor Reading

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

// Analog IO Pin Connected to OUT
#define HIH4030_OUT A0

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

// Library Variables
HIH4030 sensorSpecs(HIH4030_OUT, HIH4030_SUPPLY);

void setup(void){
  Serial.begin(9600);               // Serial Port
  Wire.begin();                     // I2C: Utilized by TMP102 Temperature Sensor
}

/* Serial Output of Temperature C, Sensor Voltage V, SensorRH %, and TrueRH % */
void printData(HIH4030 sensor, float temperature){
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.print(" C ("); Serial.print((temperature * 9/5) + 32); Serial.println(" F)");
  Serial.print("Sensor Voltage = ");
  Serial.print(sensor.vout());
  Serial.println(" V");
  Serial.print("Relative Humidity = ");
  Serial.print(sensor.getSensorRH());
  Serial.println(" %");
  Serial.print("True Relative Humidity = ");
  Serial.print(sensor.getTrueRH(temperature));
  Serial.println(" %");
}

void loop(void){
  /*  IF tempSensor = 1 Utilizing a Temperature Sensor             */
  /*  IF tempSensor = 0 Utilizing a Static Value for Temperature   */
  if (tempSensor == 1) {
    temp = getTemperature();        // Get Temperature Sensor Reading
  } else if (tempSensor == 0) {
    temp = 8;                      // Static Temperature Value in C
                                    // Set by User to Desired Temperature                           
  } else {
    while (tempSensor != 1 || tempSensor != 0){
      Serial.println("ERROR: tempSensor Value Out of Range");
    }
  }

  printData(sensorSpecs, temp);     // Print Sensor Readings
  Serial.println("");               // Return Space Between Readings
  delay(1000);                       // Slow Down Serial Output
}

/* Only Called IF Temperature Sensor is Being Used */
float getTemperature(){

  /*  IF Temperature Sensor is different from the TMP102 and not   */     
  /*    utilizing I2C via the Wire.h library, replace the code     */
  /*    within the getTemperature() function.                      */
  Wire.requestFrom(tempAddress,2);  // Wire.requestFrom(address, # of bytes to request)

  byte MSB = Wire.read();           // Receive byte as MSB or left-most bit
  byte LSB = Wire.read();           // Receive byte as LSB or right-most bit

  /*  TMP102 Temperature Register 12-bit, read-only, two's compliment for negative */
  /*  << is bit shift left ; >> is bit shift right ; | is bitwise OR               */
  /*  Syntax:   variable << number_of_bits                                         */
  /*            variable >> number_of_bits                                         */
  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;  //One LSB equals 0.0625 C
  return celsius;
}

upload_2017-3-2_13-29-35.png
 
Last edited by a moderator:

kubeek

Joined Sep 20, 2005
5,626
Not sure what insurrections you are talking about, but the blue wire is definitely connected wrong. And the brown wire doesn´t look like it is connected to the breadboard at all.
 

Raymond Genovese

Joined Mar 5, 2016
1,658
Yes, there is a way to know if your readings are correct.

The easiest way is to check your readings against another humidity sensor or hygrometer.

This is probably more than you want to know, but certain salts, when in a slurry will create a nearby atmosphere of a know humidity. The one I always remember is that sodium chloride (table salt) will give you ~76% depending on temperature. You can see the method here and a list of the salts here - please understand that some of the salts are poisonous so don't jump to this if you are not certain how to go about doing it. The idea is to check your sensor at a number of different values that are known to be associated with the salts.

What if you can't do either one of the above? Well, look at the values you are getting - it looks to me like your environment is dry, but not terribly so. RH values of 25-26% are not uncommon, so what you are reading is not outrageous.

Now breath on the sensor and watch the readings. Just get to within a few inches and exhale a few times. The RH should jump up, if it does not, you have some problems.

You do have the sensor hooked up correctly, but it took me a while to see that because of the way you are using the breadboard. Normally, the (+) rail would be for 5v and the (-) rail for Ground. You have the Ground ok, but for some reason, you are using the (+) rail for the analog input to the arduino (A0) and the analog out from the sensor. You are going directly from the arduino 5v to the sensor 5V (white lead) but it is very hard to see. So, from what I can see, you have it hooked up correctly except for one thing - you should have an 80K resistor between the sensor's OUT and GND. See figure 9 in the datasheet for this chip.

From that data sheet you can see how to get the value for relative humidity on your own.

VOUT=(VSUPPLY)(0.0062(sensor RH) + 0.16), typical at 25 C

but, as you know, there is a second formula that adjusts the value for temperature
True RH = (Sensor RH)/(1.0546 – 0.00216T), T inºC

The Sparkfun code is designed to work with a temperature sensor. You used a fixed value, and that is ok - not optimal for accuracy, but still ok, but use a fixed value of 25 rather than 8. I know that your temp outside is 8, but the formula probably has less error with 25 (see the note "typical at 25 C). In either event, you should not have very large differences between the compensated and uncompensated values.

Hope this helps.
 

AlbertHall

Joined Jun 4, 2014
8,542
You cannot expect the outside humidity to be the same as the inside humidity. I have humidity sensors inside and outside. At the moment inside is 43% and outside is 98%.
 

Reloadron

Joined Jan 15, 2015
4,591
Not sure what insurrections you are talking about, but the blue wire is definitely connected wrong. And the brown wire doesn´t look like it is connected to the breadboard at all.
You have the Vout going to power. How about this. Just power the sensor with a proper ground and +5 Volts. Do not connect Vout to anything and just measure the Vout voltage. The sensor data sheet tells you what the voltage should be for a given RH. Once that makes sense then connect it to the Analog In of your Arduino.

You cannot expect the outside humidity to be the same as the inside humidity. I have humidity sensors inside and outside. At the moment inside is 43% and outside is 98%.
That is humid, is it raining? :)

Ron
 

Raymond Genovese

Joined Mar 5, 2016
1,658
You have the Vout going to power. How about this. Just power the sensor with a proper ground and +5 Volts. Do not connect Vout to anything and just measure the Vout voltage. The sensor data sheet tells you what the voltage should be for a given RH. Once that makes sense then connect it to the Analog In of your Arduino.



That is humid, is it raining? :)

Ron
Look carefully, he does not have Vout going to power, he has Vout going to A0 on the Arduino, which is correct. He is just using the (+) rail on the breadboard for the connection (for some reason).
 

Reloadron

Joined Jan 15, 2015
4,591
Look carefully, he does not have Vout going to power, he has Vout going to A0 on the Arduino, which is correct. He is just using the (+) rail on the breadboard for the connection (for some reason).
Ah, the rail messed me up. I should have looked closer. Thanks for pointing that out to me.

Ron
 
Top