External digital interrupt and dht11

I have an Arduino Pro Mini 5v, 16 mhz and it is connected to a digital switch on pin 2. This switch is used to wake the Arduino from sleep using a external digital interrupt. I also have a DHT11 temperature sensor connected to pin 9. What I want to achieve is the when the Arduino is awake for 5 seconds and also when the switch on pin 2 is HIGH, I want to read the temperature sensor and return the temperature. I am using the DHT11 library by Tillart and when I do this, it returns a TIME_OUT error. The only possible explanation I have for this is that somehow the voltage is changed when both the DHT11 and the switch on pin 2 is being read together? Any pointers to a solution will be greatly appreciated. I also forgot to to mention that I am using the LowPower library by RocketScream to put the Arduino to sleep. The library can be found here: https://github.com/rocketscream/Low-Power. I have pasted my code with this post as well. Thank you.

#include <LowPower.h>
#include <dht.h>


int pin2 = 2;
dht DHT;
#define DHT11_PIN 9

void pin2interrupt(void)
{
  // Function called when awoken from sleep
  // Detach interrupt to stop it from continuosly firing when in normal mode
}

void enterSleep(void)
{
  attachInterrupt(digitalPinToInterrupt(2), pin2interrupt, RISING);
  Serial.println("Sleeping");
  delay(100);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  Serial.println("Awake!");
}

void setup()
{
  Serial.begin(115200);
  pinMode(pin2, INPUT);
}

int loop_iterations = 0;

void loop()
{
  delay(1000);
  loop_iterations++;
  Serial.println("Awake in the loop!");
  Serial.println(loop_iterations);
  
  if (digitalRead(pin2) == LOW && loop_iterations >= 5)
  {
    loop_iterations = 0;
    Serial.println("No child detected, so going to sleep!");
    delay(200);
    enterSleep();
  }
  else if (loop_iterations >= 10)
  {
    delay(2000);
    int chk = DHT.read11(DHT11_PIN);
    delay(2000);
    Serial.print("DHT11, \t");
    switch (chk)
    {
      case DHTLIB_OK:
        Serial.print("OK,\t");
        break;
      case DHTLIB_ERROR_CHECKSUM:
        Serial.print("Checksum error,\t");
        break;
      case DHTLIB_ERROR_TIMEOUT:
        Serial.print("Time out error,\t");
        break;
      default:
        Serial.print("Unknown error,\t");
        break;
    }
    // DISPLAY DATA
    Serial.println(DHT.temperature, 1);
    loop_iterations = 0;
  }
}

The code you posted does not go to sleep. Is that code working?

PaulS:
The code you posted does not go to sleep. Is that code working?

I just updated the code. I had mistakenly pasted the older version. Sorry about that. Thank you for your time.

Does RISING actually trigger the interrupt to wake up? Most examples for waking from sleep, including the one that comes with the library you are using, use LOW to wake up on the interrupt.

When you go to sleep, you turn the ADC off. When you wake up, I don't see anywhere where you turn it back on. The DHT11 library expects the ADC to be on. Perhaps that's why it no longer works when you wake up.

The DHT11 is a digital sensor which transfers a couple bytes by wobbling a digital pin, one bit at a time. No ADC is required.

The DHT sensors are very slow to power on, stabilise and update the internal register. The way to read a DHT is to power it up, wait a few seconds, then poll the sensor about once a second, several times, ignoring any time outs.

Tillart's library is a very simple implementation. dht11/dht11.cpp at master · adidax/dht11 · GitHub