HDT11 reads temp of 255 C after running a while

I have an HDT11 connected to an Arduino 101. I check the temp every 5 seconds (but have tested variables from 2 seconds to 5 minutes), and after reading the temp accurately for some time, it starts reading the temp at 255 Celsius, and never goes down. I’ve switched out sensors, and even connected 2 sensors and compare. Interestingly both sensors switch to 255 at the same time. I’ve switched out arduinos, and even tested with raspberry pi and get the same issue. Anyone have the same issue? Any fixes?

Please post a link to that HDT11. Is it possible that you meant a DHT11?

Post your sketch and a wiring diagram/photo.

The fact you say you have changed sensors and arduinos with no change in the result makes me think you have a software error such as a memory leak or something that runs off the edge after a given number of cycles (or is there other hardware you have not changed?)

it appears to have something to do with the use of the millis() function as a timer, and it crapping out after 71.5 minutes. I’ve read a lot about the stack overflow on this, and several different people’s proposed fixes, but I can’t seem to get them to work on my code.

Below is my code, you can see that my ugly fix is to monitor the temps, and reset the arduino when the temp jumps over 200 degrees. it’s not elegant, but it works. I’m still looking for a way to work through it with the programming, but it’s beginning to drive me crazy.

#include <dht.h>

#define DHT1PIN 2
#define DHT2PIN 3

dht DHT1;
dht DHT2;

const int ledPin =  13;
const int ledPin2 = 12;
const int ledPin3 = 10;
const int resetPin = 11;

int ledState = LOW;

const long short_interval = 500;
const long long_interval =5000;
unsigned long previousMillis = 0;
unsigned long previousTMillis = 0;

void setup(){
  digitalWrite(resetPin, HIGH);
  pinMode(resetPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  Serial.begin(9600);
  }

void loop()
{
{
  unsigned long currentMillis = millis();
  
  //blink LED at short interval
  
  if ((unsigned long)(currentMillis - previousMillis) >= short_interval){
    previousMillis = currentMillis;
   
      if (ledState == LOW) {
      ledState = HIGH;
    }else {
        ledState = LOW;
      }
      digitalWrite(ledPin,ledState);
    }   
     
    }
   
//start taking temp readings at long interval when Tmillis <> maxed out
  
  unsigned long currentTMillis = millis();
  if ((unsigned long)(currentTMillis - previousTMillis) >= long_interval){
    previousTMillis = currentTMillis;

      int chk_in = DHT1.read11(DHT1PIN);
      int chk_out = DHT2.read11(DHT2PIN);

      
      Serial.print(currentTMillis);
      Serial.print("\t");   
      Serial.println(DHT1.temperature*1.8+32);
      Serial.print("\t");   
      Serial.println(DHT2.temperature*1.8+32);
  }
   //reset the arduino if the millis overflows
  if (DHT1.temperature*1.8+32 >200){
    digitalWrite(resetPin, LOW);
  }else {
    digitalWrite(resetPin, HIGH);
  } 
  
  if (DHT1.temperature > DHT2.temperature){
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, LOW);
     }else {
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, HIGH);
     }
   
  }

Here is the wiring as it stands now. The red light is ledPin2, the green is ledPin3.

UPDATE: having trouble embedding image. will attach here…

Please post a link to the dht library you're using. There are many of them and we cannot know which one you've chosen.

I think attached is what you’re looking for. Let me know if that’s not it. I’m not sure which you need, the h file or the cpp file, I’ve attached both.

dht.h (1.4 KB)

dht.cpp (3.99 KB)

A few things I noticed:

  • You don’t need two objects of type dht, one is sufficient as you supply the pin to be used in the read method
  • You get the return value of the read11() method but you don’t display it. If anything goes wrong, this value might tell you what it was

The DHT library you’re using is probably not compatible with the Arduino 101. It uses a simple while loop to realize a wait timeout, no delay or anything in it, it simply uses the time digitalRead() needs on an AVR Arduino (UNO, Mega2560, etc.) to wait a certain time. I’d expect the 101 to process these operations much faster. A small delay of the sensor and that doesn’t work anymore.

If you want to fix that you might want to start by insertint a delayMicroseconds(1) in the while() loops in the readSensor() method of the library. That might compensate the higher processing power of the ARM CPU. I don’t know how sensitive the DHT11 is for timing issues but that’s a starting point.

I'm not clear on what you mean by "You don't need two objects of type dht, one is sufficient as you supply the pin to be used in the read method" - I am using 2 sensors and comparing the temps between them. Is there a different way to code this so that it reads both with more efficient code?

also, it was my understanding that the read command was getting the temp, and then the "DHT1.temperature" line was displaying it. But maybe to your point, I'm confused why I'm not referencing the chk_in and chk_out - this is code that I cut and pasted together, and I'm wondering if I can just get rid of some of that?

Thanks,

Steve

I'm not clear on what you mean by "You don't need two objects of type dht, one is sufficient as you supply the pin to be used in the read method" - I am using 2 sensors and comparing the temps between them. Is there a different way to code this so that it reads both with more efficient code?

You have

dht DHT1;
dht DHT2;

but it's enough to have

dht DHT;

and then use

      int chk_in = DHT.read11(DHT1PIN);
      int chk_out = DHT.read11(DHT2PIN);

instead of

      int chk_in = DHT1.read11(DHT1PIN);
      int chk_out = DHT2.read11(DHT2PIN);

also, it was my understanding that the read command was getting the temp, and then the "DHT1.temperature" line was displaying it.

This is mostly correct although DHT1.temperature does not display it, it just returns the read temperature.

But maybe to your point, I'm confused why I'm not referencing the chk_in and chk_out - this is code that I cut and pasted together, and I'm wondering if I can just get rid of some of that?

The read11() method returns an integer status code that tells you if the read was successfully made or if there was a problem. If you store that return value in a variable but don't use that variable afterwards you'll never find out that you cannot display a temperature because that value was never received from the sensor. That's why you should always check return values.

Did you understand my comment about the incompatibility of the library you used with the hardware you try to run it on?

Does the DHT11 device need decoupling? I suspect it does.

@MarkT: As you can see on the posted picture the OP uses the DHT11 on a breakout board. Most of these boards include a decoupling capacitor.

pylon:
did you understand my comment about the incompatibility of the library you used with the hardware you try to run it on

pylon:
Yes, thanks. I wasn't aware that could be an issue. I loaded a newer library, but it gave me errors and didn't work at all with my 101. I'm going to try a few more this weekend. Not really knowing what I'm looking at, there seems to be a lot of language in the library that looks like it might be causing the time out. I also found someone's post about how to use the hdt11 without a library, but it was very confusing to me. This is becoming very frustrating, and maybe my Arduino reset really is just the best option for what I'm trying to accomplish.

Try the library from Adafruit (GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors), they did it with multi-platform usability in mind, so it should run on the Arduino 101 without a problem.