DHT22 and NodeMCU

Hi guys.
I have a NodeMcu board with a DHT22 connected, publising the values to HA via MQTT. It all works fine, except the values coming from the DHT22 are VERY jittery, with a variation +/- 2degC. I am trying to do some automation around temperature control, and its provigin difficult with the jitter.

It seems that its potentailly a known DHT22 issue, but any suggestions on how to cope with it in code would be greatly appreciated!

+/- 2° C is pretty heavy. I’m using different sensors with a variation of +/- 0.13° C and implemented a bound check to decide if I send an updated value or not:

bool checkBound(float newValue, float prevValue, float maxDiff) {
  return !isnan(newValue) &&
         (newValue < prevValue - maxDiff || newValue > prevValue + maxDiff);

Putting a 0.1uF capacitor across the power supply and ground right at the sensor pins may help.


Heres the state history of the sensor in question… Its a nightmare.

@Florian, that checkBound solution may work – what do you have maxDiff set to out of interest ?

How often are you polling the DHT22?

Did you see this:

I will try out a modified version of the BRUH code mentioned in that other thread.
Seems to sort out the exact issue.

I have another couple of DHT22 that are not having this behaviour, but they are connected to RPIs, not something arduino based.

I’m using 0.13 as bound and a delay of 1000 milliseconds between the checks.