DHT11 error 253 after first reading

I am using the sample ReadTempAndHumidy (below), but getting error 253 starting with the second reading.
Looks like this:
Temperature: 28 °C Humidity: 72 %
Error 253 Reading from DHT11 timed out.
Error 253 Reading from DHT11 timed out.
Error 253 Reading from DHT11 timed out.

#include <DHT11.h>
DHT11 dht11(2);

void setup() {
    Serial.begin(9600);
    
    dht11.setDelay(1000); // Set this to the desired delay. Default is 500ms.
}

void loop() {
    int temperature = 0;
    int humidity = 0;

    int result = dht11.readTemperatureHumidity(temperature, humidity);

    if (result == 0) {
        Serial.print("Temperature: ");
        Serial.print(temperature);
        Serial.print(" °C\tHumidity: ");
        Serial.print(humidity);
        Serial.println(" %");
    } else {
        Serial.println(DHT11::getErrorString(result));
    }
}

I have seen in other threads that the DHT11 requires 2 seconds between readings. Try putting a

delay(2000);

After you take the reading.

2 Likes

If result is something else than 0, you only print errorstring.
Try with inverse logic...

This is correct. Zero indicates success. Other values indicate a failure.

1 Like

Good for testing.

For final solution, avoid using delay()

void loop() {
    int temperature = 0;
    int humidity = 0;
    static unsigned long lastReadingTime;
    unsigned long timeNow = millis();

    if (timeNow - lastReadingTime > 2000) {
      int result = dht11.readTemperatureHumidity(temperature, humidity);

      if (result == 0) {
          Serial.print("Temperature: ");
          Serial.print(temperature);
          Serial.print(" °C\tHumidity: ");
          Serial.print(humidity);
          Serial.println(" %");
        } else {
          Serial.println(DHT11::getErrorString(result));
      }
      lastReadingTime = timeNow;
    }
}
1 Like

Fully agree. It’s what I call a q&d test. Quick and dirty.

neither increasing the delay nor removing it altogether helped

so far, my workaround is to just get it to reset after the only good reading. but still hoping to clarify the issue.

delay(2000);
void(* resetFunc) (void) = 0;//declare reset function at address 0
resetFunc(); //call reset

What's your hardware? At 3.3V your wiring has to be short. If you use bare sensor you need pullup.
Try with different library like dhtLib from Tillaart.

Never heard of anyone needing to reset the Arduino between readings. Interesting that it works, however.

Let's see a schematic and some bright, clear photos of your circuit.

Ah, so you are not using a DHT11. You are using a module which includes a DHT11. Please post a link to the internal schematic of the module.

The seller just said DHT11 and nothing more. Here are the photos. Any advice on getting it's exact name/spec?


I find it strange and a little suspicious that these modules are made at all. It seems to contain a grand total of 2 components: the DHT11 and a 10K resistor. A bare DHT11 can be plugged straight into a breadboard, I've done that. And who doesn't have a 10K resistor? So what value is this module adding? My only answer is that the manufacturer can make more profit selling beginners this module than they could from selling the same beginners a DHT11 and a 10K resistor...

EDIT: OK, I may have worked it out. If you didn't have a breadboard, this module would be useful because you can simply connect it directly to an Uno with female-to-male Dupont wires. Those kind of wires probably would not make good contact with the pins of a bare DHT11 because the pins are quite thin. And without a breadboard, adding the 10K resistor would also be difficult.

But if you have a breadboard, you can save yourself a few pennies by buying a bare DHT11 and a 10K resistor. The module adds zero benefit if you have a breadboard.

Ok...

I suggest adding an external 10K resistor between the data pin and the Vcc pin of the DHT11. Most schematics for DHT11 show a 4K7 pull-up resistor. The combination of 2x 10K in parallel will be equivalent to that.

Also add a 0.1uF capacitor between the Vcc and ground pins of the DHT11, as close as you can get the cap to the DHT11.

Did you try another DHT11 library yet, as suggested by @kmin ?

I have not encountered the library you are using before, so trying a more commonly used one would be a good idea, to eliminate the possibility the library is at fault.

I added the "only-kind-i-had" resistor and now it keeps reading ok. Thank you!
0.1uF capacitor sounds fancy, but i'll look into it.

Other libraries wouldn't read at all.

No, it's absolutely basic and commonplace. Almost every circuit has these 0.1uF "bypass" capacitors near major components like chips & sensors. It's better to add them always even if they don't seem to be needed, because they cost almost nothing and can avoid wasting loads of time trying to figure out why a circuit isn't behaving correctly.

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

(Sorry, that link isn't working at the moment, I seem to remember @Grumpy_Mike mentioning there was a problem with it at the moment.)

Yes the web site was closed down by my ISP when they withdrew the free hosting you used to get. So I have transfered this tutorial to the Arduino site.

De-coupling tutorial

1 Like