yet another DHT11 Class for Arduino

Posted another DHT11 class on the playground - Arduino Playground - DHT11Lib

The class is based upon earlier work of George Hadjikyriacou and augmented by SimKard and RobTillaart. The main difference with other DHT11 classes is the support of two dewpoint() formulas, one as used by the NOAA and another faster and smaller one. The price for this is an inaccuracy of max 0.6544 C which is lower than the accuracy of the DHT11 sensor itself. The library is tested on an MEGA2560.

For positive temp values the library might be compatible with the DHT22, but this is not tested.

As allways comments and remarks are welcome.

Great! Just few hours ago ordered two of them, even not being sure if I can handle them!
Now there's a hope!

Cheers,
Kari

Hi Kari,

What platform do you intend to use it? The lib is just released and not tested on an UNO/2009. I hope you will provide feedback so I can improve the lib if needed.

Tia,
Rob

Rob,
I have Mega 1280, Nano, Duemilanove and Pro mini. I will tell how it goes, asap, after I just got that part.
:expressionless:
Thanks in advance!

Cheers,
Kari

An updated version 0.3.2 is posted on the playground.

Major changes:

  • read() function does not stall anymore
  • temperature and humidity back to int as DHT11 does not support decimal fraction.
  • dewpoint() and other non DHT11 specific functions are removed from the class (but kept in the demo sketch),

This results in a smaller lib as no floating point is used in the lib anymore.

feedback welcome

The new 0.3.2 version is giving erroneous results:

Read sensor: OK
Humidity (%): 11110
Temperature (oC): 11100
Temperature (oF): 82.40
Temperature (K): 301.15
Dew Point (oC): 8.83
Dew PointFast (oC): 8.79

@Vahan
Which platform do you use? UNO/ MEGA?

Strange that both values read as BINARY. When I make a decimal representation of they are realistic values. I'think it is a minor issue in the test application, I'll dive into it.

Humidity (%): 11110 = 30
Temperature (oC): 11100 = 28

This is confirmed by the value for Fahrenheid() and Dewpoint()

is 28 C a reasonable value for you? I don't know where you live, but for me it is not an extreme

Update

It is a bug in the example sketch. The integer value is presented as BINARY as the value 2 in the println statement is interpreted as the BINARY flag for integers iso 2 decimal places for a float. A cast is needed.

replace the corresponding lines in the test app to :

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

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

I will fix the code in the playground article,
Thanx for this feedback,
Rob

Hi Rob,

I'm working with Arduino mega 2560 and dht11 sensor. I have tried the code (0.3.2 version). It work without error, but, unfortunately the measurement don't work and seem to be constant all the time (also the temperature reading is out of measurement range). Here is the results of my measurement (from serial monitor).


Read sensor: OK
Humidity (%): 66.00
Temperature (oC): 60.00
Temperature (oF): 140.00
Temperature (K): 333.15
Dew Point (oC): 51.24
Dew PointFast (oC): 51.29


I bought the sensor 2 weeks ago, and I have used it since yesterday. I tested the sensor using this code DHT11_Temperature_and_Humidity_Sensor__SKU__DFR0067_-DFRobot
before I tested your code on dht11 sensor. I don't know, may be something happen to my sensor or i miss something in the code.
Perhaps someone can help me clearing this problem. I would be thankful :slight_smile:

Regards,

Thoms :slight_smile:

Thanx for this feedback,

A few questions:

  • what was the real temperature? / how far was the measurement off ?

  • was the humidity right?

  • what was the output of the other sketch from dfrobot?

  • if you breath to the sensor does the values change?
    if so how?

  • can you measure the voltage applied to the sensor?

  • are you sure you have a DHT11? A DHT22 looks the same, talks the same but data must be interpreted differently
    you can test this with - Arduino Playground - DHTLib -

These questions help me to get a better picture what could cause the readings.
regards,
Rob

Hi Rob, thanx for the response.

  • what was the real temperature? / how far was the measurement off ?

the real temperature is about 25OC, and the measurement off is about 60 - 25 C = 35 C.

  • was the humidity right?

the real humidity is about 80%.

  • what was the output of the other sketch from dfrobot?

The output was error status, because I didn't use sensor shield as the recommendation.

  • if you breath to the sensor does the values change?
    if so how?

I have tried to do that, but the reading temperature and humidity doesn't change, even I use my laptop exhaust.

  • can you measure the voltage applied to the sensor?

Ya, I checked the sensor voltage (GND & Signal) and the power pin (VCC & GND). Both of them had same voltage, about 4.96 V.

  • are you sure you have a DHT11? A DHT22 looks the same, talks the same but data must be interpreted differently
    you can test this with - Arduino Playground - DHTLib -

I am pretty sure that my sensor is DHT11 (as written in the sensor board). I have tried DHTLib from Arduino Playground - DHTLib, and the result didn't change at all, temperature 60 C and humidity 66 %.

I also read digital signal from the sensor using basic example from arduino DigitalReadSerial (without delay), and the result in serial monitor is 1111111 all the time.

I wonder if the problem come from the sensor.

Regards,

Thoms :slight_smile:

As the lib proofed to work with other sensors everything points to the sensor.

Q: Do you have a chance to try the sensor with an UNO board?

Q2: Have you tried other pins on the MEGA?
have the pins you used other functions? // don't have a MEGA myself
or internal pullups or so?

Rob

Hi Rob,
Thanks for your help and guidance.
Yesterday, I did the measurement using Arduino Duemilanove, but the results still didn't change at all. Also, it didn't work with another pin on my MEGA.
Luckily, another dht11 sensor came yesterday. I tried the new dht11, and voila! it works :slight_smile:
I think the problem is the sensor. When I uploaded code from DFrobot (that suggest to use sensor shield), I forgot to unplug my dht11 signal wire from arduino digital pin. And my guest, the dht11 ADC was damaged when I uploaded the code. I don't want to verify my guess, but if that (the problem) happen to someone, please let the others know for verification by posting in this forum. I would be thankful :smiley:

regards,

thoms

Sorry for the broken sensor, on the datasheet there is a procedure to recalibrate, might be a last resort to get life back in.

As the sensor never worked you might send it back to get a refund/new one (depends on the shop)

You can also try to disect it ....

Did you use my DHTlib on the good sensor? I like all - esp. positive - feedback :wink:

Ya, I use your DHTlib on the good sensor :smiley:
So that, I don't need to buy sensor shield for my simple project. :slight_smile:
Btw, thanks a lot for sharing.

Regards,

thoms

thom--s:
I don't know, may be something happen to my sensor or i miss something in the code.
Perhaps someone can help me clearing this problem. I would be thankful :slight_smile:

Regards,

Thoms :slight_smile:

You've installed the required pull-up resistor on the sensor?

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

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

thom--s:
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.

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

agree on that one;

The DHT11-lib - Arduino Playground - DHT11Lib - is upgraded (version 0.4.0) so it can be used under IDE 1.0 too

disclaimer - not tested extensively yet...