DHT22 sensor component
Quote from Christian on October 23, 2024, 5:51 pmHello,
I hope this question was not asked before, but I could not find any hint on this forum.
I am confused with how the data are exchanged between the DHT22 and a host (MCU or what not).
For ex. Aosong datasheet very painfully states : [edit : most probably not an official datasheet](note : RH = Relative Humidity, T = Temperature °C)
"Data is comprised of integral and decimal part, the following is the formula for data. "
"DATA = 8 bit integral RH data+8 bit decimal RH data+8 bit integral T data+8 bit decimal T data+8 bit check-sum" (kind of fixed point decimal as I understand it).So I would assume that if RH = 53.5, the first two bytes would be :
B1 : 00110101 -> 53 -> integral part
B2 : 00110010 -> 50 -> decimal part (or even simply 00000101 ?)However the component in SimulIDE treats the data as 16 bits 00000010 00010111 = 535 ; but that would not quite follow the datasheet in my opinion.
(Note DHT11 has not this problem, since only the integral parts are transmitted).
Any hints welcome 🙂
Hello,
I hope this question was not asked before, but I could not find any hint on this forum.
I am confused with how the data are exchanged between the DHT22 and a host (MCU or what not).
For ex. Aosong datasheet very painfully states : [edit : most probably not an official datasheet]
(note : RH = Relative Humidity, T = Temperature °C)
"Data is comprised of integral and decimal part, the following is the formula for data. "
"DATA = 8 bit integral RH data+8 bit decimal RH data+8 bit integral T data+8 bit decimal T data+8 bit check-sum" (kind of fixed point decimal as I understand it).
So I would assume that if RH = 53.5, the first two bytes would be :
B1 : 00110101 -> 53 -> integral part
B2 : 00110010 -> 50 -> decimal part (or even simply 00000101 ?)
However the component in SimulIDE treats the data as 16 bits 00000010 00010111 = 535 ; but that would not quite follow the datasheet in my opinion.
(Note DHT11 has not this problem, since only the integral parts are transmitted).
Any hints welcome 🙂
Quote from arcachofo on October 23, 2024, 7:08 pmHi.
Depending on the datasheet you can find good information or whatever.
This one looks good: https://www.makerguides.com/wp-content/uploads/2019/02/DHT22-AM2302-Datasheet.pdfBasically is what you found: 10*temperatue as a 16 bit number.
"Data is comprised of integral and decimal part, the following is the formula for data. "
"DATA = 8 bit integral RH data+8 bit decimal RH data+8 bit integral T data+8 bit decimal T data+8 bit check-sum"This one seems like DHT11 format, even if it appears in some DHT22 datasheets.
Hi.
Depending on the datasheet you can find good information or whatever.
This one looks good: https://www.makerguides.com/wp-content/uploads/2019/02/DHT22-AM2302-Datasheet.pdf
Basically is what you found: 10*temperatue as a 16 bit number.
"Data is comprised of integral and decimal part, the following is the formula for data. "
"DATA = 8 bit integral RH data+8 bit decimal RH data+8 bit integral T data+8 bit decimal T data+8 bit check-sum"
This one seems like DHT11 format, even if it appears in some DHT22 datasheets.
Quote from Christian on October 23, 2024, 8:29 pmAhah ok - what a mess...
Thanks for the datasheet, this one is very clear. Being misled by this one -
https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf
Ahah ok - what a mess...
Thanks for the datasheet, this one is very clear. Being misled by this one -
https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf
Quote from Christian on October 24, 2024, 11:37 amNote on DHT11 - (for all intended purposes 🙂
Eventually I could get hold of what seems a genuine datasheet from the DHT11 manufacturer, AOSONG/ASAIR, here :
https://www.alldatasheet.fr/datasheet-pdf/pdf/1132088/ETC2/DHT11.htmlIt is in Chinese - because it would otherwise have been to easy ; but can be translated on line fairly accurately.
First, contrary to many unofficial datasheets, the supported temperature range goes from -20° to +60° and not 0° to 50° (but then there are numerous clones/counterfeit products on the market). And this range can be confirmed on ASAIR/AOSONG website directly.
Second, it seems that RH low byte will always read 00000000 ( from doc p3 "Note: The decimal part of humidity is 0").
But this is not the case for the temperature low byte, who can hold the negative temperature information, and support a decimal part.
Example given by the datasheet :
"The high byte of temperature is the integer part of temperature data, the low byte of temperature is the decimal part of temperature data, and if the low byte of temperature Bit8 is 1, it indicates negative temperature, otherwise it indicates positive temperature."Ex : 00110101 00000000 00011000 00000100
-> RH 53.0%
-> T = 24 integral part and 4 decimal part => result = 24,4°C
And :
"When the temperature is below 0°C, the highest position of the lower 8 bits of the temperature data is 1.
Example:-10.1℃ is represented by 00001010 10000001"Then again we are talking about a cheap sensor of dubious reliability...
Note on DHT11 - (for all intended purposes 🙂
Eventually I could get hold of what seems a genuine datasheet from the DHT11 manufacturer, AOSONG/ASAIR, here :
https://www.alldatasheet.fr/datasheet-pdf/pdf/1132088/ETC2/DHT11.html
It is in Chinese - because it would otherwise have been to easy ; but can be translated on line fairly accurately.
First, contrary to many unofficial datasheets, the supported temperature range goes from -20° to +60° and not 0° to 50° (but then there are numerous clones/counterfeit products on the market). And this range can be confirmed on ASAIR/AOSONG website directly.
Second, it seems that RH low byte will always read 00000000 ( from doc p3 "Note: The decimal part of humidity is 0").
But this is not the case for the temperature low byte, who can hold the negative temperature information, and support a decimal part.
Example given by the datasheet :
"The high byte of temperature is the integer part of temperature data, the low byte of temperature is the decimal part of temperature data, and if the low byte of temperature Bit8 is 1, it indicates negative temperature, otherwise it indicates positive temperature."
Ex : 00110101 00000000 00011000 00000100
-> RH 53.0%
-> T = 24 integral part and 4 decimal part => result = 24,4°C
And :
"When the temperature is below 0°C, the highest position of the lower 8 bits of the temperature data is 1.
Example:-10.1℃ is represented by 00001010 10000001"
Then again we are talking about a cheap sensor of dubious reliability...
Quote from arcachofo on October 24, 2024, 5:41 pmThanks for the information.
I didn't know about that datasheet.It's weird, in most datasheets in English temperature range is 0ºC to 50ºC, but usually they are not from the manufacturer.
This one seem to be from the manufacturer, but no info about temperature range or decimals:
https://components101.com/sites/default/files/component_datasheet/DHT11-Temperature-Sensor.pdfThat datasheet links to this site and searching for DHT11 also shows -20ºC to 60ºC:
http://www.aosong.com/en/products-21.html
Thanks for the information.
I didn't know about that datasheet.
It's weird, in most datasheets in English temperature range is 0ºC to 50ºC, but usually they are not from the manufacturer.
This one seem to be from the manufacturer, but no info about temperature range or decimals:
https://components101.com/sites/default/files/component_datasheet/DHT11-Temperature-Sensor.pdf
That datasheet links to this site and searching for DHT11 also shows -20ºC to 60ºC:
http://www.aosong.com/en/products-21.html
Quote from Christian on October 24, 2024, 9:37 pmYes, this is really maddening 🙂 Then again plenty of dirty DHT11 clones on the market...
One thing in the datasheet from components101 : there is no version nor date, which normally all manufacturer would take care to indicate - and basically the most obvious information is missing, not to mention the terrible translation.
The datasheet from alldatasheet has got a version number, which is good sign I think : V1.3_20170331.
Also from the AOSONG website (which provides no datasheets on line for their products) link you give, if you check the last picture, it will show the back of a genuine DHT11, with the manufacturer ASAIR, and the chip operating ranges. It confirms that the genuine part humidity range is 5%-95%, and temperature range -20° +60°. Now you need a way to transmit the information about the temperature sign.
Yes, this is really maddening 🙂 Then again plenty of dirty DHT11 clones on the market...
One thing in the datasheet from components101 : there is no version nor date, which normally all manufacturer would take care to indicate - and basically the most obvious information is missing, not to mention the terrible translation.
The datasheet from alldatasheet has got a version number, which is good sign I think : V1.3_20170331.
Also from the AOSONG website (which provides no datasheets on line for their products) link you give, if you check the last picture, it will show the back of a genuine DHT11, with the manufacturer ASAIR, and the chip operating ranges. It confirms that the genuine part humidity range is 5%-95%, and temperature range -20° +60°. Now you need a way to transmit the information about the temperature sign.
Quote from Christian on October 26, 2024, 1:07 pmFor the record-
Eventually I could not help myself and bought some genuine ASAIR dht11 from AZ Delivery - that is, with the proper marking on the plastic case.
The operating ranges stated on the sensor case are as follow :
DC : +3.3 - 5.5v
RH : 5-95 +-5
T : -20 60° +- 2°CFrom measurements :
Decimal/fractional part of RH is never set , ie always = 0
Decimal/fractional part of T° is set, with MSB being the the temperature sign (1 = negative T°)For negative T° support test, I basically put the sensor in the freezer (who runs at -14°, give or take)
The pseudo DHT clones I have will happily set the RH and T° decimals, but come with absolutely no support of negative temperature. Attached the DHT11 datasheet translated online from Chinese - for those interested.
For the record-
Eventually I could not help myself and bought some genuine ASAIR dht11 from AZ Delivery - that is, with the proper marking on the plastic case.
The operating ranges stated on the sensor case are as follow :
DC : +3.3 - 5.5v
RH : 5-95 +-5
T : -20 60° +- 2°C
From measurements :
Decimal/fractional part of RH is never set , ie always = 0
Decimal/fractional part of T° is set, with MSB being the the temperature sign (1 = negative T°)
For negative T° support test, I basically put the sensor in the freezer (who runs at -14°, give or take)
The pseudo DHT clones I have will happily set the RH and T° decimals, but come with absolutely no support of negative temperature. Attached the DHT11 datasheet translated online from Chinese - for those interested.
Quote from arcachofo on October 26, 2024, 1:27 pmGreat! thanks for sharing.
I implemented negative temperature for DHT11, but I found that most used libraries (Arduino) don't support negative temperatures, just give a reading error.
But if the real device does indeed work in the -20ºC to 60ºC range, then I will publish the changes to support it.
Great! thanks for sharing.
I implemented negative temperature for DHT11, but I found that most used libraries (Arduino) don't support negative temperatures, just give a reading error.
But if the real device does indeed work in the -20ºC to 60ºC range, then I will publish the changes to support it.
Quote from Christian on October 26, 2024, 1:51 pmHi,
I think your choice is reasonable ; these specs are supported by the manufacturer website + an original chinese datasheet + experience (though a limited one, I did not went to the extreme T°...)
And even if it were not, what can do the most can do the least 🙂The Arduino guys have been simply mislead like most people by those dubious datasheets that work with clones but not the original one. Even AZ Delivery provide their customers with a wrong datasheet...
[edit 17/11/2024]
The Adafruit library for Arduino also compute the negative T° - see DHT-sensor-library/DHT.cpp at master · adafruit/DHT-sensor-library · GitHub line 90 :
case DHT11: if = data[2]; -> T° integral part if (data[3] & 0x80) { -> test lower/decimal temperature byte msb f = -1 - f; } f += (data[3] & 0x0f) * 0.1;
Hi,
I think your choice is reasonable ; these specs are supported by the manufacturer website + an original chinese datasheet + experience (though a limited one, I did not went to the extreme T°...)
And even if it were not, what can do the most can do the least 🙂
The Arduino guys have been simply mislead like most people by those dubious datasheets that work with clones but not the original one. Even AZ Delivery provide their customers with a wrong datasheet...
[edit 17/11/2024]
The Adafruit library for Arduino also compute the negative T° - see DHT-sensor-library/DHT.cpp at master · adafruit/DHT-sensor-library · GitHub line 90 :
case DHT11:
if = data[2]; -> T° integral part
if (data[3] & 0x80) { -> test lower/decimal temperature byte msb
f = -1 - f;
}
f += (data[3] & 0x0f) * 0.1;