8 years, 10 months ago.

The DHT is giving a round value

Hello,

why the DHT lib is given me a round value? can it be more precise? like 25.5 for example? or it is a hardware limitation: the sensor cannot give more accurate values.

Thanks and best regards.

Question relating to:

Temperature & Humidity

1 Answer

8 years, 10 months ago.

I don't know the sensors but the code in the library implies that the DHT11 is only accurate to the nearest whole number while the DHT22 should output to the nearest 1/10th. However for some reason despite trying to calculate the value to the nearest 1/10th the library uses an integer to store the result.

Edit DHT.cpp and change lines 139 and 211 from int v; to float v; and it should work correctly.

Thanks I changed, but still I am getting round values :(

posted by sabrine fatnassi 08 Feb 2016

Just a thought, how are you observing the data? if using printf then a float could appear as an integer by the data handler i.e.

#include <mbed.h>

int main()
{
 float a=4.5;
 printf("appears as an int:%d  and now as a float:%f\n\r",a,a);
 sleep();   
}
posted by Martin Simpson 08 Feb 2016