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.
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?
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.
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.