DHT11 - RH & Temp reading = -999

Hey :slight_smile:

I’m very new to Arduino (< 1 week) and have never programmed before, so apologies in advance.

Yesterday I set up the DHT11 sensor and I was able to get a reading in IDE, which was great. RH of 59% and temperature of 21 Celsius. Fantastic, it worked! I then tried to get this reading on a 16x2 LCD screen that came with the kit. It didn’t work and I couldn’t figure it out. At first I tried to fix this by changing out the resistor which didn’t work. I decided to start from scratch and this worked. I could get a reading, but both RH and Temperature read as -999.

I tried to get a reading by going back to the original project, using the dht11 and Arduino only, the reading was still -999.

How can I tell if the sensor is working or if it’s something in the code. I have uploaded the DHTlib to IDE. Code for both projects is below. I think I have included everything here, but please let me know if there’s more information required.

Thanks a million :slight_smile:

Code for reading the data in IDE:

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

Code for reading the data on an LCD screen;

#include <dht.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;

#define DHT11_PIN 7

void setup(){
  lcd.begin(16, 2);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}

Are you missing a dht.begin() statement ?

I will try this when I get home :slight_smile: So my code should read like this?

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
  Serial.begin(9600);

dht.begin()

}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

I was assuming you were using the Adafruit library which requires a begin() method to set the pin as an input pin. I now see there are others. If that is not the case, please post the link to the DHT library you are using or state where you got it from.

Sure thing, here’s the link; Circuit basics - DHT11 on Arduino

I have also attached the DHTLib zip file. Thanks :slight_smile:

DHTLib.zip (2.41 KB)

OK. dht.begin() is not relevant for the library you are using. The -999 is to signal an error condition:

#define DHTLIB_INVALID_VALUE    -999

It looks like there is some sort of a timeout error on attempting to read the device.

Maybe you could look at another sketch to test the device: https://learn.adafruit.com/dht/using-a-dhtxx-sensor but a wiring error is the first thing to rule out.

Hi, Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please a picture of your project so we can see your component layout.

Thanks.. Tom... :)

TomGeorge:
Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please a picture of your project so we can see your component layout.

Thanks… Tom… :slight_smile:

Hi I have a similar problem with dht11…

here is my code… and also followed everything from http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/ and including its library… sorry I am still a newbie and i want to learn … thank you!

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
Serial.begin(9600);

}

void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}

Hi there,

Just had the same problem because I connected the output of the DHT22 on an analog Pin whereas it should be connected on a PWM pin. In your case it seems that you connected your DHT on the pin 7 which is a digital one but not PWM (if you were using an UNO). Try with the pins 3,5, 6, 9, 10, 11.

Hope it will help,

Please post the code you use.

Hi, I had the same Issue at the beginning. I tried to set my Input Pin to a Pin with PWM and set the delay higher to 2000. Now I get stable results.

A Pin with PWM and delay higher around 2000, worked perfect!