Go Down

Topic: yet another DHT11 Class for Arduino (Read 17186 times) previous topic - next topic

thom--s

No, I didn't install the pull-up resistor on the sensor. Is it necessary?

robtillaart

depends on the length of the wires, that said - I never used pull ups for my DHT22 (OK not a DHT11, but electrically similar) but my max length was approx 10 cm or 4inch
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

arcs_n_sparks


No, I didn't install the pull-up resistor on the sensor. Is it necessary?


Well, the datasheet requires it. I tend to find that ignoring the datasheet is the first step towards headaches or unreliable behavior.

robtillaart

Quote
ignoring the datasheet is the first step towards headaches or unreliable behavior.

agree on that one;
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart


The DHT11-lib - http://arduino.cc/playground/Main/DHT11Lib -  is upgraded (version 0.4.0) so it can be used under IDE 1.0 too

disclaimer - not tested extensively yet...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

melano

Hello everybody,

I am tried to do a small project for temperature and humidity control. I am going to use four DHT11 sensor, but I have a question. How I can read multiple DHT11?

Thanks

robtillaart

Every DHT11 should have its own datapin.  +5V and GND can be shared.

A slightly changed sample with DHT's datapin connected to arduino-pin 2,3,4,5,

Code: [Select]

#include <dht11.h>

dht11 DHT11;

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void loop()
{
  Serial.println("\n");
  for (int pin = 2, pin < 5, pin++)
  {
    processDHT11(pin);
  }
  delay(2000);
}

void processDHT11(int pin)
{
  int chk = DHT11.read(pin);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
}
//
// END OF FILE
//

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

melano

Thanks very much for the answer. I've not yet proven, when I get ready commented how it works.

robtillaart


start with 2 and increment step by step
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

copachino

in this code which its the data pin??? digital 2???

Code: [Select]
//
//   FILE:  dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078);   // temp var
return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}


#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 2

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

  delay(2000);
}
//
// END OF FILE
//

robtillaart

Quote
in this code which its the data pin??? digital 2???

yes,
#define DHT11PIN 2 

The DHT11 connects to GND, +5V and one datapin which is used bidirectional.

check also - http://arduino.cc/playground/Main/DHTLib - as it supports the DHT22 which has higher precission (one decimal)

But for temp sensors I prefer the DS18B20 as these can be read at a higher frequency. - http://milesburton.com/Dallas_Temperature_Control_Library -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

copachino

thanks, ahhh no this its not for the aquaium jejeje, thisis like i want to sense the RH in the air of diferents cities,  something i want to know its, hoe much time do i need for the sensor(dht11) to get good reads, its that i just blow over it and the temp change, but when i stop blowing the temp stay conts, so it means that the sensor needs time to ajust it

robtillaart


Have you read the datasheet? It might be in there.

the DHT11 needs 2000 milliseconds between readings. The DS18B20 at max 750 millis.
My impression is that he DHT11 is also slower in following the temp than a DS18 although I did not do a real test.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Krodal

#28
Apr 20, 2012, 07:11 pm Last Edit: Apr 20, 2012, 07:12 pm by Krodal Reason: 1
Thanks for this code for the DHT11.
It's very small, even working on a ATmega8.
And if something is wrong, version 0.4.0 always returns an error. Very nice.
I use a pull-up of 10k on the data line.

robtillaart

Quote
Thanks for this code for the DHT11. ...   I use a pull-up of 10k on the data line.

you are welcome,

depending on the length of the wires a pull up helps to improve the signals edges
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up