DHT22 sensor not showing

I will take a look and yes I have a resistor, but I have this complete module:

Yes, this module looks like it already has a resistor on it - hmm

I had multiple of these modules, but another has the same result. So I think it has to do something with code/library. I will look if I can find something.

The library has had some updates since the OMG included version 1.4.2.; it’s now 1.4.4.
Although I cannot see any major changes, or changes which should be relevant for the problems you are seeing it might be worth you trying it out with the latest version, by changing line 122 in patformio.ini to

dht = DHT sensor library@1.4.4

I know I should have an old non-board DHT22 in one of my drawers somewhere - if I can find it I can also have a try with manually adding a 5k resistor to see what results I’m getting :wink:

Also going through the forum here there there seem to have been similar issues

so whatever the older “real” DHT22s and new DHT22s are (no board/board with resistor??) there might be some library adjustment needed for some.

@christian-0s - any hints at what timing changes in the library got you proper readings from the ‘new’ DHT22s?

Thanks

I just used the library with the adafruit example DHTTester that’s included with the library. This test sketch seem to work fine on a ESP32. My openmqttgateway is running on a ESP8266. Library 1.4.4 doesn’t make a difference.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN 2     // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Which version of ESP8266 do you have? Here a very similar setup to yours works fine with the user still adding an additional BH1750 light sensor - all with a NodeMCU v3.

While he needed to change the DHT_RECEIVER_GPIO to 14 (D5) to free D1 for the BH1750 this might also be worth trying out in your case - also as commented in config_DHT.h.

I have this one: DEBO JT ESP8266: Developer boards - NodeMCU ESP8266 Wi-Fi module at reichelt elektronik. I just tried PIN 14 (D15), but the reading is the same.

Looks like a v2 to me at first glance, of which I also have some lying around here. So if I find my old style DHT22 I’ll give it a try in the next few days.

One last idea - which pin do you use to supply power to the DHT22, the 3.3V, which should be fine spec wise, or the VIN, which could (on the NodeMCUv2??) have 5V - looking at the diode on your version I think it will, and you’re using the USB port for supplying power - and should also be fine for the DHT22?

Maybe swapping the power might give you different results - best to check for the 5V with a multimeter first - and slowly grasping at straws here :stuck_out_tongue_winking_eye:

I use the VIN pin. It had 4.6v according to my multimeter. Thank you for all the help so far!

Then maybe swap it around and try the 3.3V pin to supply power to the DHT22 :slight_smile: it’s input range should be from 3.0-5.5V

3.3v same result unfortunately :neutral_face:

While it’s always a good idea to use a dedicated regulated power pin to supply power to sensors - VIN only being for input on some models, on others also carrying around 5V from the USB supply - unfortunately it didn’t help here.

I am out of ideas what else it could be, but will keep you posted on my tests if and when I find my old style DHT22.

Or someone else might have further suggestions.

All the best.

1 Like

Hi again @FerronN,

having dug out my DHT22 - plain version not on a board with included resistor like yours - I tested it and found exactly the same issues you were having. Enabling DHT debugging it also showed that a lot of times there were checksum errors when reading from the DHT and when the checksum was fine the hex bytes corresponded with the erroneous temperature and humidity values :frowning:

Not knowing exactly where the issue lies I went back to a previous OpenMQTTGateway version, before changes were made on the OMG side, but also before substantial changes to the included DHT/unified sensor libraries.

Using OpenMQTTGateway 0.9.8 I got constant good readings from my DHT22.

Using the same older library versions from then in OMG 0.9.16 this is also working nicely for me, please change the library links in platformio.ini to:

dht = DHT sensor library@1.3.0
unifiedsensor = Adafruit Unified Sensor@1.0.2

Also an additional lib_deps needs to be added, in your case the environment should be

[env:nodemcuv2-ir-dht]
platform = ${com.esp8266_platform}
board = nodemcuv2
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager8266}
  ${libraries.irremoteesp}
  ${libraries.esp8266_mdns}
  ${libraries.unifiedsensor}
  ${libraries.dht}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayIR="IR"'
  '-DZsensorDHT="DHT"'
  '-DGateway_Name="OpenMQTTGateway_ESP8266_IR"'
board_build.flash_mode = dout

Please let us know if these older library versions fix your issues as well.

1 Like

The older library fixes the issue for me :slight_smile: I think it has something to do with OMG. I also tried my ESP32 with OMG and I got the same wrong readings (dht library 1.4.4 and unified sensor 1.1.6). Using the same libraries (and versions) and the sketch I referred to earlier I got the correct values.

Thanks for the confirmation!

For the time being, using the older libraries will have to be the quick fix, until we can sort out what the issue with the new libraries might be.

In the end though, old libraries, new libraries, the temperature and humidity is being published correctly now :slight_smile:

Thank you for your help! Yeah for this it’s not that big a problem. Hope we can find the cause so others won’t have the same problem.

Thanks for pointing that, Added some results below:

And pushed a PR:

1 Like

So we hope they fix it in a newer version or OMG just keeps an older version?

I would just keep it with an older version, doesn’t seem to have a big value add to bump it

Hi DigiH, sorry for the extremely late response.
I had used the library esp32DHT (this version: https://raw.githubusercontent.com/bertmelis/esp32DHT/4f57bf3ef14fb606305bb55317d31d3df3322b32/src/esp32DHT.cpp) and had to change line 151 from if (pulse > 120) { to if (pulse > 100) { to get the fake DHT22s to work. In the mean time I see that library changed a lot so I don’t know if now it would have worked without changes.

1 Like