Cannot read from DHT11

I am having trouble reading a DHT11 sensor. I did not write the code (I got it from the project hub). I have fixed several issues already but I can't figure out why this is not working (it does compile and upload to the arduino). Below is the section of code that is not working:

int temperature;
int soilMoisture;
int humidity;

int chk;

void readTempAndHum()
{
  chk = kDHT.read(DHT11_PIN);
  temperature = kDHT.readTemperature();
  Serial.println(temperature); // I added this line for debug purposes
  humidity = kDHT.readHumidity();
}

"temperature" returns '0' (as does humidity). I would appreciate any help that could be provided.

Thanks.

It helps if you post the whole code as the error is usually in the bit we can't see. And, as you are using something external to your board, it helps to provide a schematic (or hand drawing) showing how you wired it up.

Did you try the code from the project hub as is without any modifications? Did that work?

Did you include the pull-up resistor?

The code would not compile without the modifications. I did not try the pull-up resistor.

You need the pull up resistor. I think around 10K is the value to use.

You can't "try" an engineering plan. You follow it, unless you know what you're doing.

The DHT11 sensor data sheet suggests to use 5.1K Ohms for the required pullup resistor. If the sensor cable is longer than 20 m, or you have read errors, lower that value.

Hello
Run some DHT11 sensor tutorials to learn how this sensors works.

I added the 5.1k resistor as per the datasheet. I am still getting 0 for the temperature and humidity values. I am attaching the code (as I originally stated I did not write the original code, I made some modifications to fix compile errors). I would appreciate if anyone could help me figure this out. Thanks.
flowerPotMonitor_transmit.ino (1.6 KB)

I wouldn't try and learn from code that didn't compile without errors. As @paulpaulson suggested, pick a DHT11 sensor tutorial that actually works and learn from it. Then apply what you've learnt to your own code.

I have fixed the issue. I found a typo in the class creation line that carried out through the rest of the code.

Thanks everyone for your help.

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