DHT11 only returns 0's when I am using and LCD Shield

Hello everyone,

I am racking my brain to figure out why my DHT11 sensor is only returning 0's for Temperature and Humidity on my Arduino Mega 2560. I am using the DHT11 sensor with 3 pins that already has the pullup resistor soldered onto it, plus I have tested that the DHT11 is working with the same board on the same pins using a test sketch (included in the attachments). OK now I will try to give you a full idea of what I am doing, hopefully without being too exhausting.

I am making a Filament dryer for my 3D printing projects. The basic idea is that I will control (via relays) a heating element and a fan to heat and circulate air inside of the drying chamber. The Temperature and current humidity in the chamber will be monitored by the DHT11. I am timing the drying cycle using a DS3231SN RTC outputting a 1HZ pulse attached to an interrupt that will increment the timer which is displayed on the Velleman VMA203 LCD and Button Shield that I am using as the display. Once every 5 seconds the arduino will read and sample the Temperature and Humidity then display those values along with the timer. Both the RTC and the DHT11 are powered from the 5v rail on the Arduino Mega, as is the LCD.

The LCD Shield uses digital pins 4-9 for communication and digital pin 10 for the backlight also used A0 for the 6 on board buttons.
The RTC is attached to the SDA (20) and SCL(21) pins for I2c and digital pin 19 for the 1HZ interrupt.
The DHT11 is attached the A10 for communications.

I am using Arduino IDE 1.8.13

I know the main sketch is probably a huge mess and possibly hard to follow because it is made up mostly of repurposed examples modified to fit what I need. But I can't seem to find what would be causing the DHT11 to only return 0's. I even put a couple lines into the function to read the DHT11 that allow it to ignore interrupts while it is reading the sensor, since the datasheet says it takes a while to read, thinking that maybe it was getting interrupted. That was not the case or if it is the 2 snippets of code I found to temporarily diable interrupts then re-enable them is wrong.
Thank you in advance for any help given, and please be patient I am new and trying to be as thorough as possible with the information provided here.

DHTtester.ino (2.48 KB)

LCD_SHIELD_MENU_WIP.ino (23.1 KB)

Does DHTtester.ino work?

Yes it does work,

demonicarcher:
Yes it does work,

Sorry, does it work with all the other hardware attached, including the LCD?

Also,

//*******************************************************************************************************
// checks the current temperature and humidity inside the dryer
void checkDHT11() {
cli();//stop interrupts
  hCurrent = dht.readHumidity();
  tCurrent =  dht.readTemperature(true);
  Serial.print(hCurrent);
  Serial.print(" - ");
  Serial.print(tCurrent);
  Serial.println(" DHT11");
sei();//allow interrupts

}

What does this print, can you post the output? Why are you disabling interrupts?

I just re-tested and yes it does work with all of the Hardware connected.

As for that piece of code. The output printed is

0 - 0 DHT11 - this is just for troubleshooting reasons and will be removed when I get the rest of the sketch working correctly.
I am disableing the interrupts for 2 reasons.

  1. I disabled them to test to make sure that it was not the interrupt preventing me from getting a complete reading from the sensor.
  2. Attempting to prevent the interrupt from preventing a good read from the sensor

If I comment out the interrupt in the setup loop, and call checkDHT11() somewhere else in the program (in this case in the menuItem6() function it provides me with a good reading..

OK I have finally solved my own problem, unfortunately I don't know exactly what was causing it.

I added a variable to indicate whether or not to check the DHT11 and changed that in the interrupt function instead of calling the checkDHT() function inside of the the interrupt function.

if (lapsed > 4) { // after 5 seconds or more has passed recheck the temperature and humidity
Serial.println("reset lapse");
testDHT = true;
lapsed = 0;
}
else{
testDHT= false;
}

as opposed to

if (lapsed > 4) { // after 5 seconds or more has passed recheck the temperature and humidity
checkDHT11()
lapsed = 0;
}

then modified checkDHT11() to

void checkDHT11() {
if (testDHT == true){
hCurrent = dht.readHumidity();
tCurrent = dht.readTemperature(true);
Serial.print(hCurrent);
Serial.print(" - ");
Serial.print(tCurrent);
Serial.println(" DHT11");
testDHT = false;
}
}

i got rid of the lines disabling interrupts and it seems to be working just fine...

Thank you aarg for the help and asking the questions that led me to try some new approaches.