Temperature sensor accuracy.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
PandCall
Normal user
Posts: 44
Joined: 22 Sep 2022, 20:04

Temperature sensor accuracy.

#1 Post by PandCall » 03 Oct 2022, 11:11

Just a small question, how to have the real precision of a temperature sensor ?

If I define 5 as decimal value, the values 3 and 4 etc... are always 0.
But if I use a direct arduino code, I have the right value, which seems to validate that the temperature sensor gives the right precision.

ESP Easy
DHT22_setting.png
DHT22_setting.png (80.56 KiB) Viewed 2280 times
DHT22_decimal.png
DHT22_decimal.png (51.88 KiB) Viewed 2280 times
Arduino test
DHT22_decimal_arduino.png
DHT22_decimal_arduino.png (695 KiB) Viewed 2280 times
ESPEseay Oled
DHT22_decimal_oled.png
DHT22_decimal_oled.png (792.23 KiB) Viewed 2270 times
Regards

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Temperature sensor accuracy.

#2 Post by Ath » 03 Oct 2022, 13:25

Looking at the ESPEasy code and the Arduino library code, they both use the same method for extracting the temperature and humidity from the received data. That is a signed int value, to be divided by 10 (or multiplied by 0.1), so the actual accuracy is only 1 decimal. I expect the Arduino inaccuracy comes from the Serial.print() function, and the ESPEasy code is returning the most accurate result.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#3 Post by TD-er » 03 Oct 2022, 13:26

The nr of decimals only represent the formatting of the values already present.
But it looks like the temperature from the DHT22 is already "rounded" to 1 decimal before it is handed over for further processing.

As can be seen here, it is actually been truncated to 1 decimal:
https://github.com/letscontrolit/ESPEas ... #L288-L318

However, I do remember some of these sensors may have a separate register for the extra bits of resolution (pun intended :) )
I will check the datasheet to see if this is actually true for the DHT22.

Edit:
Nope, the resolution is 0.1C.
See the datasheets:
https://www.sparkfun.com/datasheets/Sen ... /DHT22.pdf
https://cdn-shop.adafruit.com/datasheet ... AM2302.pdf

Edit2:
I noticed you try to convert it to Fahrenheit.
See here what you can use for the formula field: https://espeasy.readthedocs.io/en/lates ... fahrenheit

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#4 Post by TD-er » 03 Oct 2022, 13:37

Just wondering, as I never heard of this "Heat Index".
I see it being defined here: http://www.wpc.ncep.noaa.gov/html/heati ... tion.shtml
But this is using the temperature in Fahrenheit.
Is this "Heat Index" something mainly used in the States?

PandCall
Normal user
Posts: 44
Joined: 22 Sep 2022, 20:04

Re: Temperature sensor accuracy.

#5 Post by PandCall » 03 Oct 2022, 13:45

Forget about Fahrenheit.
It was simply in the DHT Arduino example code.
For me the °C was enough.
Let's not look for conversion, just precision. :)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#6 Post by TD-er » 03 Oct 2022, 13:56

Well the sensor doesn't have any extra resolution.
Your Arduino test code does show the same in the first 2 columns.
The later columns have values which were converted to this "heat index" (Celsius and Fahrenheit)

PandCall
Normal user
Posts: 44
Joined: 22 Sep 2022, 20:04

Re: Temperature sensor accuracy.

#7 Post by PandCall » 03 Oct 2022, 13:57

If I understand your explanations, it is the Ardruino code that gives a virtual precision, the DHT returns in this format XXX.X
It is therefore the sensor that returns a limited format and if I want a greater precision, I must use another type of sensor (MCP9808).

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#8 Post by TD-er » 03 Oct 2022, 14:09

Nope, the Arduino library you're using does give the same resolution.
Only if you convert the temperature to compute some Heat Index value based on both temp and humidity, then you see extra decimals occur.

Before you're diving into buying expensive sensors, let me show you this chart:
Image
Blog where this image is used

It is very hard to get accurate temperature measurements as you need to take into account lots of factors.
For example reading a sensor more often, may heat up the sensor itself.
Also the location of the sensor makes a lot of difference. Like the ESP itself will produce heat and thus affect the readings when the sensor is close.

So you have to ask yourself:
Why do I need a higher resolution?
Do I need higher precision or higher accuracy?

After you've found yourself a satisfying answer, please throw away those DHTxx sensors as they aren't really that good anyway. (even though the DHT22 is already way better than the DHT11)

We can of course help you with finding a proper sensor, but then we must also know about the use case.

PandCall
Normal user
Posts: 44
Joined: 22 Sep 2022, 20:04

Re: Temperature sensor accuracy.

#9 Post by PandCall » 03 Oct 2022, 14:25

In fact, you don't need to be very precise.
My question was related to the fact that in ESPEasy we could define the number of decimal places.
Let's not waste any more time with that, it was if there was an error in my use or in the code.
By reading your comments, by reading documents, indeed the heat index is a bit like the dew point, it is calculated.
Thank you very much for all your answers.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#10 Post by TD-er » 03 Oct 2022, 14:40

The nr of decimals is merely a formatting parameter.

Thus "10" may become "10.0000" when set to 4 decimals.
If there isn't any more decimals available in the data, it may not make sense to increase the nr of decimals.
For example the amount of free memory in Bytes doesn't even make sense to have any decimals at all.

Most can do perfectly well with 2 decimals. Some units of measure, like GPS lattitude and longitude coordinates may typically need upto 6 decimals to not loose any present information/resolution.

PandCall
Normal user
Posts: 44
Joined: 22 Sep 2022, 20:04

Re: Temperature sensor accuracy.

#11 Post by PandCall » 03 Oct 2022, 14:52

I agree with you.
I was just asking the question, I didn't ask about the accuracy of the sensor used itself.
But yes, the real question is, what accuracy do I need.
What will I do with the value I get.
Real questions.
For what I'm doing right now, 1 or 2 decimal places is enough.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Temperature sensor accuracy.

#12 Post by TD-er » 03 Oct 2022, 15:23

And do realize that resolution, precision and accuracy are related but absolutely different parameters.

You can have low resolution, low accuracy and high precision.
But such a combination is often as useful as a stopped clock.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 30 guests