HIH 4602 humidity sensor

Hi!

I am having some troubles getting a Honeywell HIH4602 A/C sensor to work. It is my first attempt to program an analog sensor and I really need some help.
This is the code I have done so far but I keep getting errors.

float humidity;

void setup()
{
Serial.begin(115200);
humidity.begin(A0);
}

void loop()
{
humidity=analogRead(A1);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print('\n');

humidity=(humidity-0.835542)/(0.028743465);

Serial.print(humidity);

Serial.print('\n');
delay(500); //make it readable
}

Attached are the link with the product data sheet and a photo with the specific data of my sensor.

Thanks in advance!

Welcome in Arduinoland

  1. please post your code between code tags - it is the # button above the smileys (you can modify your existing post)
  2. what are the errors you get?
  3. Can you explain how you connected the device?

Use CTRL-T to re-indent your code to make it even more readable

  humidity.begin(A0);

is meaningless
humidity is just a floating point number that does not have a begin method (at least I have never seen it :wink:

float humidity;

void setup()
{
  Serial.begin(115200);
  Serial.println("Sensor test:\tHIH 4602 \n"); 
}

void loop()
{
  float raw = analogRead(A1);
  humidity = (raw - 0.835542) / 0.028743465;

  Serial.print("raw: \t");
  Serial.print(raw);
  Serial.println();

  Serial.print("humidity: \t");
  Serial.print(humidity);
  Serial.println;
  
  delay(500);
}

To which analog pin is the sensor connected? A0 or A1

It is connected to A0.

Well, I don't really know how to write the code; I have made the circuit and connected it to the board as it is shown in the data sheet but I can't manage to do more than that.

I should get a read-out of the relative humidity inside an environmental chamber.

if it is connected to A0 you should do analogRead(A0) and not analogRead(A1).

yes, I did that but I still get -29.07raw which is not correct

Think over again:
What do you actually get with analogRead. Its NOT voltage, but 'steps' indicating the voltage put to the pin.
each step is 5V/1023 = ca 5mV/step

What if: float raw = analogRead(A1);
changed to
float raw = analogRead(A1) *5.0/1023.0

no, it is still a negative output for humidity and 0 for raw

and there is no data change at humidity variations

andr_88v:
yes, I did that but I still get -29.07raw which is not correct

That is an indication that the analogLine is floating.

Can you post how you connected the sensor?

the case ground is not connected now

.

got a multimeter ?
Indors (30-35%RH) the reading should be 1.8 .. 1.9V to the analog input (based on info from datasheet)
If you dont fint this voltage - somthing is wrong. (hardware or connections)
From formulas given - calculate True RH

datasheet.png

I'll check that tomorrow at the uni.

Thanks a lot :slight_smile:

A.

Hi again!

I have managed getting the sensor to work by removing the resistance; although it gives out the humidity percentage, it can be anywhere between 0 and 60 and when I blow over, it will give out even negative values.

Do you have any further suggestions?

The code looks like this now:

float humidity;

void setup()
{
  Serial.begin(115200);
  Serial.println("Sensor test:\tHIH 4602 \n"); 
}

void loop()
{
  float raw = (analogRead(A0)*(5.0/1023.0));
  humidity = (raw - 0.836)/0.029;

  Serial.print("\n"); 
  Serial.print("raw: \t");
  Serial.print(raw);
  Serial.println();

  
  Serial.print("humidity: \t");
  Serial.print(humidity);
  
  delay(500);
}

Your code is fine.

So you are left with the sensor or wiring being faulty.

#2 is signal out (A0)
#3 is ground
#4 is V in (5v)
With an 80kOhm load resistor between 2 & 3.

Double check everything, again.

Confusing the connections might just instantly kill the sensor.

Good luck,
tf

You got it correct as far as I can see. (reply 13 is interesting..)

Thank a lot, guys, but it def. doesn't work with a resistor on it, it shows a constant -29.07 and removing the resistor (and applying the code above) gives ascending/descending values between 10 and 80 and won't stabilize no matter for how long it runs.

Most probably the sensor is broken...it is just frustrating as I have ordered it 5 days ago.

Verify pinout to 100%. (pin 2,3 and 4)
Verify common GND and 5V
Verify the analog input port on MCU

If if doesnt work WITH the load-resitor <=80k... Sensor is defective!