DHT22 stops working

hi at all, I have 6 DHT22 sensors connected to 6 digital pins on my Arduino and I'm facing a strange problem: after a while the sensors stops responding me, and they return null temperature and humidity.

I'm using the 'DHT sensor library' by AdaFruit v1.4.3. The sensors are charged with 5V and they don't need the resistor or capacitor because it's already inside the sensor "board".

The code that I'm using for accessing to the data is in the end of the question. The problem, as said, is that after a while, the sensors stop to return the temperature and the humidity. In the example above I'm using an interval of 5 seconds between each consecutive read, but the problem persist even with slower time intervals.

Any suggestion about how to understand what is the problem? There is any way using the library to see what is the error?

Thank you very much.

#include "DHT.h"
#include <ArduinoJson.h>

#define DHTTYPE DHT22
#define DHTPIN1 1
#define DHTPIN2 2
#define DHTPIN3 3
#define DHTPIN4 4
#define DHTPIN5 5
#define DHTPIN6 6

const int num_sensors = 6;
DHT *sensors = (DHT *)malloc(sizeof(DHT) * num_sensors);

const int temp_capacity = JSON_OBJECT_SIZE(3);
StaticJsonDocument<temp_capacity> json_temp;

void setup() {
  Serial.begin(9600);

  // setup sensors
  sensors[0] = DHT(DHTPIN1, DHTTYPE);
  sensors[1] = DHT(DHTPIN2, DHTTYPE);
  sensors[2] = DHT(DHTPIN3, DHTTYPE);
  sensors[3] = DHT(DHTPIN4, DHTTYPE);
  sensors[4] = DHT(DHTPIN5, DHTTYPE);
  sensors[5] = DHT(DHTPIN6, DHTTYPE);

  // setup sensors
  for (int i = 0; i < num_sensors; i++){
    sensors[i].begin();
  }
}

void loop() {
    for (int i = 0; i < num_sensors; i++)
    {
      float t = sensors[i].readTemperature(false, true);
      float h = sensors[i].readHumidity();

      json_temp["room"] = i + 1;
      json_temp["t"] = t;
      json_temp["h"] = h;

      String output = "";
      serializeJson(json_temp, output);

      Serial.println(output);
      Serial.flush();
    }

    delay(5000);
}

What Arduino board? Most boards use pin 1 for the hardware serial TX.

Do you have pullups on each DHT input? What value?

How long are the wires between the mystery Arduino board and the sensors?

What is supplying power to your project? Voltage? Current capacity?

Post a schematic of the project.

Arduino Uno. You're right, I'm using the pin1 of serial TX, could be that a problem?

Do you have pullups on each DHT input? What value?

Yes, there is a 1K resistor on data pin, like in the following schema:

Screenshot 2021-11-13 at 19.27.58

How long are the wires between the mystery Arduino board and the sensors?

That is something that could be problematic, the sensors are placed in a range of 3 to 5 meters with shielded wires.

What is supplying power to your project? Voltage? Current capacity?

The Arduino Uno board is supplied by a Raspberry Pi, the sensors are supplied with 5V. Like in the following schema:

Tx is and output, the DAT pin of the DHT is an output. It is never good to have 2 outputs connected together. What happens if one is LOW and the other is HIGH? It is called a short circuit. So yes, I think that it could be a problem. Maybe not the problem, but a problem.

After moving that sensor from pin 1, I think that the next thing that I would do is to reduce the wire length and use 10K pullups just to test.

Are you sure that the Pi is capable of supplying sufficient current for the Uno and sensors. The Uno alone needs about 50mA the sensors 1K pullups about 5 mA each + 2mA when each is measuring.

After moving that sensor from pin 1, I think that the next thing that I would do is to reduce the wire length and use 10K pullups just to test.

Ok, I will try this.

Are you sure that the Pi is capable of supplying sufficient current for the Uno and sensors. The Uno alone needs about 50mA the sensors 1K pullups about 5 mA each + 2mA when each is measuring.

Maybe I should try also to power supply the Arduino with an external charger.

I had problems too with DHT22 sensors failing randomly after hours or sometimes days. A workaround was to power the sensor from a digital output, and simply turn on the sensor for one reading, then off until next reading..

Then, I analyzed the data sent by the sensor, and there is a ~13 microseconds delay after every 8 data bits sent by the sensor. I verified it with multiple sensors that I had, all acting the same.

No DHT library - that I know of - take care of this delay (not mentioned in the datasheet). And, all these libraries wait ~1ms for the start signal, but the datasheet says "1-10ms", so IMO it's more 10ms than 1ms...

So I made my own DHT library, mainly changing this 1ms to something like 15ms, and added a delayMicroseconds(13) after every 8 bits of data received, and as far as I remember, it solved the problems...Until I replaced these crappy sensors with Bosch BME280..!

Hi,
Have you tried using the Arduino on its own and see if the fault reoccurs?

Use serial monitor to display the readings.

A schematic of your complete project would help.
PLEASE do not use a Fritzy image.

Tom.. :smiley: :+1: :coffee: :australia:

Hi at all, thank you for your suggestions.

I was able to solve the problem by enabling and disabling the current to the sensors using a relè only when I needed to read the data. In this way the behaviour of the sensors remains stable through time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.