# DHT22 reading crashes ESP32

**URL:** <https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962>\
**Category:** Sensors\
**Created:** [August 13, 2023, 10:33pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962 "2023-08-13T22:33:30Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 13, 2023, 10:33pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/1 "2023-08-13T22:33:30Z")

</div>

I am trying to use 4 dht22 sensors with an esp32 and I keep experiencing these crashes. The program will run fine for 15-40mins and then the microcontroller will reset itself. It seems to have something to do with reading the sensor data but im a noob and i'm struggling to figure it out. Does anyone have any ideas?  
I am programming an ESP32\_Devkitc\_v4 WROOM-32D using the arduino framework in platformio.

Here is the register dump with stack trace

```arduino
20:16:23.918 > Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1). 
20:16:23.925 >
20:16:23.925 > Core 1 register dump:
20:16:23.927 > PC : 0x400e785f PS : 0x00060935 A0 : 0x800e54c5 A1 : 0x3ffb2040
20:16:23.935 > A2 : 0x0000001a A3 : 0x00000000 A4 : 0x00000027 A5 : 0x00060123  
20:16:23.943 > A6 : 0x00060120 A7 : 0x00000001 A8 : 0x3ff44000 A9 : 0x0000001f
20:16:23.950 > A10 : 0x3ff5f07c A11 : 0x04000000 A12 : 0x0000001a A13 : 0x00060f23  
20:16:23.958 > A14 : 0x00060f20 A15 : 0x00000001 SAR : 0x0000001a EXCCAUSE: 0x00000006
20:16:23.966 > EXCVADDR: 0x00000000 LBEG : 0x400849d1 LEND : 0x400849d9 LCOUNT : 0x00000027  
20:16:23.974 >
20:16:23.974 >
20:16:23.974 > Backtrace: 0x400e785c:0x3ffb2040 0x400e54c2:0x3ffb2070 0x400e2843:0x3ffb2090 0x400e293e:0x3ffb20b0 0x400e2a1f:0x3ffb2210 0x400d3316:0x3ffb2240 0x400d6fd2:0x3ffb2270 0x400e6d71:0x3ffb2290
20:16:24.099 >
20:16:24.099 > #0 0x400e785c:0x3ffb2040 in gpio_ll_get_level at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/hal/esp32/include/hal/gpio_ll.h:473
20:16:24.099 > (inlined by) gpio_get_level at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/gpio.c:233
20:16:24.099 > #1 0x400e54c2:0x3ffb2070 in __digitalRead at C:/Users/3dPrintStation/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-gpio.c:150
20:16:24.099 > #2 0x400e2843:0x3ffb2090 in DHT::expectPulse(bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:382
20:16:24.099 > #3 0x400e293e:0x3ffb20b0 in DHT::read(bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:306
20:16:24.099 > #4 0x400e2a1f:0x3ffb2210 in DHT::readTemperature(bool, bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:88
20:16:24.099 > #5 0x400d3316:0x3ffb2240 in readSensorData() at src/DHT_SENSORS.cpp:29
20:16:24.099 > #6 0x400d6fd2:0x3ffb2270 in loop() at src/main.cpp:48
20:16:24.099 > #7 0x400e6d71:0x3ffb2290 in loopTask(void*) at C:/Users/3dPrintStation/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50

```

Here are the pins

```arduino
DHT dht[NUM_SLOTS] = {
    DHT(25, DHT22),
    DHT(26, DHT22),
    DHT(27, DHT22),
    DHT(33, DHT22)};

```

This is the function that reads the temp and humidity data. It is only called in the main loop. Originally I had it inside another function and I was using a shorter interval for readings but i've been moving things around seeing if I could get something to work.

```arduino
float temperature[NUM_SLOTS];
float humidity[NUM_SLOTS];

void readSensorData()
{
    unsigned long currentMillis = millis();
    const int Interval = 5000;
    static unsigned long previousMillis;

    if (currentMillis - previousMillis >= Interval)
    {
        previousMillis = currentMillis;

        for (uint8_t i = 0; i < NUM_SLOTS; i++)
        {
        temperature[i] = dht[i].readTemperature();  
        humidity[i] = dht[i].readHumidity();   
        }
    }
}

```

I spent all afternoon looking into this yesterday and I can't figure out what I've done wrong. Any guidance would be much appreciated

---

<div class="post-metadata">

**Author:** ![dingsken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dingsken/32/1013044_2.png) [@dingsken](https://forum.arduino.cc/u/dingsken)\
**Post date:** [August 13, 2023, 10:46pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/2 "2023-08-13T22:46:36Z")

</div>

@jaywhy Hey there,  
Can you please post the whole sketch you´re using? When you see the error core paniced, there´s something wrong with the coding or wiring but mostly coding or an indefintive loop.  
Maybe I can test the code with 2 dht22´s.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 13, 2023, 11:36pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/3 "2023-08-13T23:36:44Z")

</div>

Never used this sensor, but Google tells me that the min sample time of these sensors is two seconds (0.5Hz). It seems you're reading the sensors multiple (NUM\_SLOTS) times after each other, without that 2-second break.  
Leo..

---

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 13, 2023, 11:40pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/4 "2023-08-13T23:40:03Z")

</div>

I appreciate the offer. My code is at least 1000 lines long and is broken up amongst multiple tabs. I leave for work soon but I can reformat it and post tonight.

According to the stack trace, it seems to be something to do with reading the sensors and that only happens once in the sketch.  
Yesterday I commented out the readSensorData function and it ran for a few hours without crashing so i went back to trying to troubleshoot it. I have commented it out again and i'm going to let it run for the rest of the day to see what happens.

I've searched for anywhere that it could be getting stuck in a loop but every other part of the sketch works fine, even with readSensorData included. All buttons work, the rotary encoder works, all of the buttons on the webpage work, etc. and the temp and humidity readings update consistently both on the webpage and on the lcd screens up until it crashes. I cant find any condition where something becomes unresponsive.

I do have everything hooked up to a single power supply though. Do you think that it could be a power supply issue? It is only a cheap one that comes in the beginner kits and it is powering quite a bit of stuff  
edit: in this photo the temp and humidity readings are zero because i have commented out readSensorData. They normally work fine.

 ![20230814_092705](https://europe1.discourse-cdn.com/arduino/original/4X/5/e/1/5e1b4b3fc1a237dc2a2822f8f6a520dbf54d3957.jpeg)

---

<div class="post-metadata">

**Author:** ![osval](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/osval/32/680092_2.png) [@osval](https://forum.arduino.cc/u/osval)\
**Post date:** [August 13, 2023, 11:50pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/5 "2023-08-13T23:50:06Z")

</div>

in my little experience with espressif I see they tend to crash sometimes with certain power supply ...

---

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 13, 2023, 11:50pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/6 "2023-08-13T23:50:42Z")

</div>

Wouldn't it be that each individual sensor needs a 2sec interval?  
NUM\_SLOTS = 4 because there are 4 sensors in the array.

The code should:  
only after the 5 second interval has passed  
read temp from sensor0  
read hum from sensor0  
read temp from sensor1  
read hum from sensor1  
read temp from sensor2  
read hum from sensor2  
read temp from sensor3  
read hum from sensor3

Then there is another 5 second interval before the sensors should be read again. i have used the serial monitor to confirm that they are only being read every 5 seconds

edit: I just realised it could be because i am reading the temp and humidity immediately after each other. I haven't tried reading them separately with a 2 second interval in between each!

---

<div class="post-metadata">

**Author:** ![timinelmira](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/timinelmira/32/1101596_2.png) [@timinelmira](https://forum.arduino.cc/u/timinelmira)\
**Post date:** [August 14, 2023, 2:42am UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/7 "2023-08-14T02:42:00Z")

</div>

Have you got a pull up resistor on the data line of each sensor? (I've had problems with DHT sensors if there isn't)

---

<div class="post-metadata">

**Author:** ![dingsken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dingsken/32/1013044_2.png) [@dingsken](https://forum.arduino.cc/u/dingsken)\
**Post date:** [August 14, 2023, 10:35am UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/8 "2023-08-14T10:35:21Z")

</div>

@jaywhy indeed like @timinelmira said, you need a resistor for each sensor. In the image I only see one.

---

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 14, 2023, 12:06pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/9 "2023-08-14T12:06:52Z")

</div>

I didnt. I tried 10k resistors when i first got them and they would all read NAN.

I just tried some 5.1k and they are returning actual values. Will leave running for a while and see what happens. If i have no luck then i will start reformatting my code to post

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [August 14, 2023, 1:59pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/10 "2023-08-14T13:59:50Z")

</div>

Hi, @jaywhy

> [@jaywhy](#):
>
> If i have no luck then i will start reformatting my code to post

If you have no luck, write some code to **JUST** read the DHTs, and see if the problem occurs.

Lets prove your hardware before butchering your code.

Did you write your code in stages, and test each time?

Thanks.. Tom.. 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![oldcurmudgeon](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oldcurmudgeon/32/1280882_2.png) [@oldcurmudgeon](https://forum.arduino.cc/u/oldcurmudgeon)\
**Post date:** [August 14, 2023, 3:17pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/11 "2023-08-14T15:17:50Z")

</div>

Check your library and wiring. I had a similar problem with an esp8266 and it turned out the library I was using was waiting for data that never came. The data wire was loose so no data, which eventually caused a wdt timeout.

---

<div class="post-metadata">

**Author:** ![barshatriplee](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@barshatriplee](https://forum.arduino.cc/u/barshatriplee)\
**Post date:** [August 14, 2023, 3:39pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/12 "2023-08-14T15:39:53Z")

</div>

Here is another thread about the Guru meditation error: [Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled - #7 by cotestatnt](https://forum.arduino.cc/t/guru-meditation-error-core-1-paniced-loadprohibited-exception-was-unhandled/876182/7)

Check your wiring and try another library.

---

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 16, 2023, 11:01pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/13 "2023-08-16T23:01:26Z")

</div>

Thank you everyone for the help and suggestions.  
I ended up spending more time on this, rewiring things, swapping out components, running a modified version of the DHT example code, etc. and didn't get anywhere. Sometimes it would run fine for 1.5hrs, I would think I had made progress, then it would ultimately crash. I did find that I was getting failed readings but not from one sensor consistently.

```arduino
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity[i]) || isnan(temperature[i])) {
    Serial.print("Failed to read from DHT sensor");
    Serial.println(i);
    return;

```

Last night I decided to to try some DS18b20s for the temperature readings and it has run over night with no crashes. I am just going to leave the DHTs for now and look for another solution for the humidity readings so that I can keep working. If I ever figure out what was wrong I'll make another post.

---

<div class="post-metadata">

**Author:** ![dingsken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dingsken/32/1013044_2.png) [@dingsken](https://forum.arduino.cc/u/dingsken)\
**Post date:** [August 18, 2023, 9:32pm UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/14 "2023-08-18T21:32:47Z")

</div>

@jaywhy maybe this is a better one, something new [https://www.bol.com/nl/p/azdelivery-gy-21-htu21-vochtigheids-temperatuursensor-compatibel-met-arduino/9300000123701207?referrer=socialshare\_pdp\_androidapp](https://www.bol.com/nl/p/azdelivery-gy-21-htu21-vochtigheids-temperatuursensor-compatibel-met-arduino/9300000123701207?referrer=socialshare_pdp_androidapp)

Or following link: [https://www.az-delivery.de/nl/products/aht10-feuchte-temperatur-sensor?\_pos=3&\_sid=50d2b0b2e&\_ss=r](https://www.az-delivery.de/nl/products/aht10-feuchte-temperatur-sensor?_pos=3&_sid=50d2b0b2e&_ss=r)

Greetings dingsken.

---

<div class="post-metadata">

**Author:** ![jaywhy](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jaywhy](https://forum.arduino.cc/u/jaywhy)\
**Post date:** [August 20, 2023, 1:10am UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/15 "2023-08-20T01:10:09Z")

</div>

> [@dingsken](#):
>
> maybe this is a better one, something new [https://www.bol.com/nl/p/azdelivery-gy-21-htu21-vochtigheids-temperatuursensor-compatibel-met-arduino/9300000123701207?referrer=socialshare\_pdp\_androidapp](https://www.bol.com/nl/p/azdelivery-gy-21-htu21-vochtigheids-temperatuursensor-compatibel-met-arduino/9300000123701207?referrer=socialshare_pdp_androidapp)

Thanks for the suggestion @dingsken  
I have purchased a set of GY-21 HTU21s. Hopefully i'll have better luck with these

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 16, 2024, 1:10am UTC](https://forum.arduino.cc/t/dht22-reading-crashes-esp32/1157962/16 "2024-02-16T01:10:21Z")

</div>

Closed on February 16, 2024, 1:10am UTC

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