Arduino Forum

Using Arduino => Sensors => Topic started by: Kaybee327 on Aug 21, 2019, 05:47 pm

Title: DHT 11 AND 22 GIVE WRONG VALUES
Post by: Kaybee327 on Aug 21, 2019, 05:47 pm
Trying to make a basic temp humidity display but can not get correct figures and I am stumped. Error I get with both 5v and 3.3v are:

dht 22   Arduino  Mega     temp     -959       humidity           -999

            Arduino  Uno       temp          1       humidity                1

dht11    Arduino  Mega     temp          1       humidity                1

            Arduino  Uno       temp     -959       humidity           -999

Sketch I am using is very basic  and is


#include <dht.h>

dht DHT;

#define DHT11_PIN A0

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);
}

If anyone can offer suggestions before I go completely mad it would be apprerciated

Keith
Title: Re: DHT 11 AND 22 GIVE WRONG VALUES
Post by: Annygnr on Aug 21, 2019, 07:08 pm
Try this code:


#include "DHT.h"
 
#define DHTPIN A0

#define DHTTYPE DHT11
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup()
{
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
}
 
void loop()
{
  // A leitura da temperatura e umidade pode levar 250ms!
  // O atraso do sensor pode chegar a 2 segundos.
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  // testa se retorno é valido, caso contrário algo está errado.
  if (isnan(t) || isnan(h))
  {
    Serial.println("Failed to read from DHT");
  }
  else
  {
    Serial.print("Umidade: ");
    Serial.print(h);
    Serial.print(" %t");
    Serial.print("Temperatura: ");
    Serial.print(t);
    Serial.println(" *C");
  }
}

Also, use these 2 libs:
https://github.com/AnnyCaroline/ceu-dht/tree/master/arduinoLibs
Title: Re: DHT 11 AND 22 GIVE WRONG VALUES
Post by: Kaybee327 on Aug 22, 2019, 02:40 am
many thanks for your reply.

unable to get github libraries as kept getting error 404.

Tried the code on it's own and got a better result but still not correct. This time got humidity - 23.7 and temperature -1.00
Title: Re: DHT 11 AND 22 GIVE WRONG VALUES
Post by: Southpark on Aug 22, 2019, 04:26 am
Also see what happens when you push the reset button after the software gets loaded to the arduino.

And show some photos of your setup ----- eg. show the cables, how you wired it up. Sometimes, cables being too long could be an issue. Or value of pull-up resistors etc.

And, if you did any soldering of cables to your modules ----- I think that some of the components can be prone to heat damage. So, if in doubt ...... use an arduino header, female slots (holes). Solder cable to the header's pins. And then plug the dht22 pins into the header slots.