Malfunctioning Temperature on DHT11 Sensor

The humidity is fine but over the course of a month or so the temperature sensor has gotten progressively worse. It’s gotten to the point that now the temperature sensor only ever reports one temperature, 71.60 F. It does this even though currently, according to a thermometer I have, it’s 64 F in my room. Has powering the sensor constantly caused it to malfunction? I don’t think it’s something wrong with my code but I’ll post it anyway

// include the library code:
int sensor = A0; // soil moisture sensor
int sensval = 0;
#include <LiquidCrystal.h>
#include "DHT.h"
#include <Adafruit_NeoPixel.h>
#define PIN 11
// set the DHT Pin
#define DHTPIN 8

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1,PIN, NEO_GRB + NEO_KHZ800);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
  
void setup() {
 // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  dht.begin();
  strip.begin();
  strip.show();
  
  //Serial.begin(9600);
  // Print a message to the LCD.
 
}

void loop() {
  lcd.setCursor(0,0);
  lcd.print("Temp:  Humidity:");
  delay(500);
  
  lcd.setCursor(0, 1);
  // read humidity
  float h = dht.readHumidity();
  //read temperature in Fahrenheit
  float f =dht.readTemperature(true);
 
  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h);  
   
  if(f<=75)
  {
    strip.setPixelColor(0,0,map(f,60,90,0,255)/2,(255-map(f,60,75,0,255))/2);
    strip.show();
  }
  if(f>=75)
  {
    strip.setPixelColor(0,map(f,75,90,0,255)/2,(255-map(f,60,90,0,255))/2,0);
    strip.show();
  }
   delay(500);
    sensval = analogRead(sensor);
  while (sensval > 50)
  { delay(500);
    lcd.clear();
    lcd.print("Soil Moisture:");
    lcd.setCursor(0,1);
    lcd.print(sensval);
    if (sensval<=575)
    {
      strip.setPixelColor(0,0,map(sensval,0,950,0,255)/2,(255-map(sensval,0,575,0,255))/2); 
      strip.show();
    }
    if (sensval>=575)
    {
      strip.setPixelColor(0,map(sensval,575,950,0,255)/2,(255-map(sensval,0,950,0,255))/2,0);
      strip.show();
    }
    sensval = analogRead(sensor);
  }
    //Serial.println(f);
}

I’m pretty new at this, any help would be much appreciated.

Replace the sensor. DHT11 are ultra-cheap sensors, you'll find several stories of such sensors dying slowly after not very much time in duty. Maybe your next DHT11 is working for a longer time. DHT22 are more reliable, a DHT33 even seems to include the rock-solid DS18B20, so upgrade if you want to get reliable results.

I started with DHT11, too. I thought "not that accurate but ultra cheap". Well, that was a mistake. Would never ever buy again or recommend them--IMHO money is 100% wasted. In addition, I wasted to much time finding out why the readings made no sense.

I've tested some humidity sensors, i.e. DHT11, DHT22, AM2320, SI7021, HTU21D, and BME280, from worst to best. Depending on your scenario I would recommend the HTU21D. The AM2320 is relatively cheap and seems to be the similar to DHT22 but you can choose to use I2C or single data wire. The accuracy of the AM2320 where ok in relation to all other sensors. I lined them all up and tested simultaneously. In addition I prepared a full NaCl saturated environment to calibrate 75% humidity.

I'll second pylon's suggestion to use DS18B20, Iif you need reliable temperature readings.

HTH & best

Alright, I guess I'll look into getting a new sensor. Has anyone had experience with the SHT31-D?

Thanks for the info, the SHT31-D sounds interesting. Maybe I'll have a look.
Best

Have had excellent results with this:

Well worth the price, IMHO :slight_smile:

Alright, I guess I'll look into getting a new sensor. Has anyone had experience with the SHT31-D?

I use that sensor in my home automation network and it works excellently. It costs a bit more than the DHT11 but in my opinion it's worth the money. I use the sensor on my own breakout board, that solution is much cheaper than the adafruit board but don't try to solder that chip without a reflow oven.

GregoryGregg:
The humidity is fine but over the course of a month or so the temperature sensor has gotten progressively worse. It's gotten to the point that now the temperature sensor only ever reports one temperature, 71.60 F. It does this even though currently, according to a thermometer I have, it's 64 F in my room. Has powering the sensor constantly caused it to malfunction? I don't think it's something wrong with my code but I'll post it anyway

I created a whole Weather and Environmental Station with wifi based telemetary using this sensor.
After sitting for a year doing nothing, the temperature part of this sensor is reading about 15C higher than it should.
At least I know now what is causing it.. a sh*tty sensor. I have bought another new one just to verify.
Looking at later posts I may get SHT31-D solution, but I'm not paying for the hugely marked up prices from Adafruit.