DHT22 sensor cannot withstand humid environment?

I recently built a project around an ESP8266 using a DHT22 sensor to monitor the temperature/humidity in the bathroom and turn on the fan when required. The sensor was placed inside and just above the shower vent opening. The first time I tested it, the temperature only varied by a degree or two. The humidity started at around 60% and rose all the way up to 100% during a bath and failed shortly afterwards. The sensor now records neither temperature nor humidity. Are these sensors so badly designed that they can't withstand more than a little humidity?

I successfully am using a Si7021 humidity sensor in my bathroom. The one with factory-installed white Teflon cover. They also have built-in temp-switched heating, to further protect the sensor from condensation. I used epoxy glue to fully cover the sensor/wires, and only left the white sensor window exposed. Leo..

Is it this one?

https://www.ebay.co.uk/itm/GY-21-Si7021-SHT21-I2C-High-Precision-Humidity-Temperature-Sensor-Arduino-Pi/313176728670

BTW, I tried another spare DHT22 sensor and I'm getting a humidity of 64.7% in my home office!

DHT dhtSensor(DHTPIN, DHT22);

That seems rather seems rather high so I also tested a DHT11 and this showed just 18%.

DHT dhtSensor(DHTPIN, DHT11);

So what gives? Is there a problem with the Adafruit sensor library? Surely the sensors cannot be that far out from each other?

Tried the original sensor on the UNO and it still works but humidity is also high - 65% - so thinking that perhaps the sensor crashed or something. Will try a reset next time, but both DHT22's are reading very high humidity.

I have read bad things about DHT sensors, so I didn’t go there.
Yes, that’s the sensor I’m using.
I have set fan threshold to 65%, and internal heater threshold to 80%.
Works without problems in my bathroom with shower and bath.

Using an ATtiny85 and wrote code for humidity only, without the use of a library, so probably no use to you.
Here is the test code that I used on an Uno, before cleaning it up and porting it to the ATtiny85.
I used a blinking LED to show humidity, so I can still monitor it in/on the fan if needed.
Leo…

// Bathroom Fan Control with Si7021 and Attiny85
// Blink LED and SSR LED powered from 5volt supply
#include <Wire.h> // will use drazzy boards manager
const byte ledPin = 13; // testing on Uno
//const byte ledPin = 3; // Attiny85
const byte outPin = 4;
unsigned long prevMillis;

void setup() {
  Serial.begin(9600); // remove for Attiny85
  Wire.begin();
  pinMode(ledPin, OUTPUT);
  pinMode(outPin, OUTPUT); // fan should test-run before the first measurement
  Wire.beginTransmission(0x40); // Si7021 address
  Wire.write(0xFE); // reset on bootup
  Wire.endTransmission();
}

void loop() {
  if (millis() - prevMillis > 30000UL) {
    prevMillis = millis();
    Wire.beginTransmission(0x40); // address
    Wire.write(0xE5); // RH measure command
    Wire.endTransmission();
    Wire.requestFrom(0x40, 2); // get the two RH bytes
    unsigned int raw = Wire.read() << 8 | Wire.read(); // join
    byte humidity = (float)raw * 125 / 65536 - 6; // process
    if (humidity >= 65) digitalWrite(outPin, LOW); // SSR on
    else digitalWrite(outPin, HIGH); // SSR off
    byte tens = humidity / 10;
    byte units = humidity % 10;
    for (byte i = 0; i < tens; i++) { // flash LED 'tens' times
      digitalWrite(ledPin, HIGH);
      delay(20);
      digitalWrite(ledPin, LOW);
      delay(480);
    }
    delay(500);
    for (byte i = 0; i < units; i++) { // flash LED 'units' times
      digitalWrite(ledPin, HIGH);
      delay(20);
      digitalWrite(ledPin, LOW);
      delay(480);
    }
    if (humidity >= 80) {
      Wire.beginTransmission(0x40); // address
      Wire.write(0xE6); // user register
      Wire.write(0x3E); // heater on
      Wire.endTransmission();
    } else {
      Wire.beginTransmission(0x40); // address
      Wire.write(0xE6); // user register
      Wire.write(0x3A); // heater off
      Wire.endTransmission();
    }
    Serial.println(humidity); // remove for Attiny85
  }
}

Most capacitive humidity sensors have a specified upper limit of 95%rH non-condensing. And like most electronics are allergic to water.

THe atmospheric value of rH can vary dramatically, comfortable is 40~60%, but cold outside and heat inside can take it to 10%, warm and rainy outside can push interior to 90%, its all normal.

Besides in a bathroom you are looking for a rate of change not an absolute value, as the atmosphere can easily get to greater than 80%, even if you are not there.

As Wawa commented, an integral heater is a must if you have a condensing environment, which a bathroom certainly is.

Wawa: I have read bad things about DHT sensors, so I didn't go there. Yes, that's the sensor I'm using. I have set fan threshold to 65%, and internal heater threshold to 80%. Works without problems in my bathroom with shower and bath.

Looks like I a going to have to switch to a Si7021 sensor. Thank you for the code example.

AmphenolSensors: Most capacitive humidity sensors have a specified upper limit of 95%rH non-condensing. And like most electronics are allergic to water.

THe atmospheric value of rH can vary dramatically, comfortable is 40~60%, but cold outside and heat inside can take it to 10%, warm and rainy outside can push interior to 90%, its all normal.

Besides in a bathroom you are looking for a rate of change not an absolute value, as the atmosphere can easily get to greater than 80%, even if you are not there.

As Wawa commented, an integral heater is a must if you have a condensing environment, which a bathroom certainly is.

I guess I assumed that a humidity sensor would have that water allergy thing covered. Even in a dry office environment the DHT22 is at 64% while a DHT11 at the same time shows 17%. It does not seem to make sense. I thought perhaps there is a problem with the Adafruit library so I tried another library and same result. These DHT11's are cheap, but the DHT22's cost a bit more and price is similar to the Si7021. Even the Si7021 has exposed components on the board.

I appreciate that the program would need to evaluate a threshold rather than an absolute value and that is what I intend to do.

I am not sure what you mean about an integral heater? If it had an integral heater wouldn't this affect the temperature reading?

BitSeeker: I am not sure what you mean about an integral heater? If it had an integral heater wouldn't this affect the temperature reading?

The software-switched internal heater is probably just a resistor that heats up the sensor on the inside a bit, to stop condensation on the sensor element. So yes, it raises the temp a bit, and how much is documented in the Si7021 datasheet. Leo..

Ok, thanks. Will look that up.

The Si7021 sensor arrived eventually and I have just been trying it out. The readings approximately match the DHT22, except that it does not crash like the DHT22 did when reaching 100%. Perhaps then, it was the DHT11 that was reading incorrectly and much too low. Still it seems odd that the humidity in my home office is 54%! This is using the Adafruit Si7021 library rather then the raw code you provided. I will try the raw code for comparison I think.

I haven't tried the heating resistor feature yet, but at least the sensor seems more reliable.

The other thing about capacitive humidity sensors (which the ones mentioned above are), and to an extent resistive ones, is that they can dry out. They actually rely on some moisture being in the fabric to balance with the environment. Think of a dry chamois leather - it doesn't work until your wet it. A way of reconditioning sensors if they are dried out is to put them in an oven for a few hours with a bain-marie at about 70~80°. Not ideal and not controlled, but it can help.

As to control, as I mentioned earlier what you want to do is monitor how fast the humidity level is rising, as that indicates bath time, a gradual rise is either natural, or you drying clothes over the bath. Monitor it, you'll better understand the dynamic.

AmphenolSensors:
As to control, as I mentioned earlier what you want to do is monitor how fast the humidity level is rising, as that indicates bath time, a gradual rise is either natural, or you drying clothes over the bath. Monitor it, you’ll better understand the dynamic.

Thanks. I understand and that is exactly what I intend to do - monitor for w a while to get an idea of variations and then program to monitor how fast humidity is rising during a bath or shower. Thank you for the pointers.

And when you make your way over to the Bosh sensors like the BMP180, BMP280, BME280, BMP388, or BME680 the BME series using SPI are the better ones.

I use a BME680 in a Stevenson's shield, outside, that has been running since Feb 11th of this year. The Stevenson shield allows the environment to enter for measurement and sampling but is protective of the exposed electronics in the 'attic'.

Inside, I use the BME280 SPI versions.