Efficient way to apply variable corrections to a sensor that reads high temp

Hello,

I have an outdoor weather sensor based on an Arduino nano and a DHT22 sensor.

It works well, but the temperature is always too high. From what I've read it could be the result of heating with the DHT22 itself. I can't force air through the sensor very easily (a proposed solution), so I think I may be stuck with the heating effect.

A solution is to reduce actual reading by 1 degree (for example) in the code. This would be a pretty simple fix, however I've found the effect of the heating within the sensor cannot be mapped to a single static correction. eg. At around 0 degrees Celsius, it could be as much a 2 degree difference, but as the temperature gets a lot colder or a lot warmer, the difference is less.

I would like to attempt to apply a correction to the temperature in a smooth way. For example:

If the temperature read is 0 degrees, subtract 2 degrees
If the temperature read is 50 degrees, subtract .5 degrees
If the temperature read is -50 degrees, subtract .5 degrees

The assumption in my simple example is that 50/-50 is the upper/lower limit (I hope!)

I would like the adjustments in between to be "smooth" - a logarithmic looking curve (maybe that's not the right way to describe it, but I think you probably get what I mean)

I'm hoping someone can propose a nice little piece of math/code that could handle this. I doesn't need to be perfect. I'm sure I could get the job done, but it would be ugly.

Thanks for looking at this.

Mike.

Maybe you could use the map() function ?

...R

No, the measurement error is not due to self heating.

The proper way to deal with a nonlinear sensor calibration is to construct a calibration curve. You use an accurate thermometer as a reference, and make a table of the thermometer temperature versus the sensor temperature. The more points, the better.

Then, make a plot and fit the points with a suitable curve (a quadratic is likely to be fine). There are plenty of web sites like this one that will calculate the fit and give you the appropriate correction curve, as described in this excellent tutorial.

In the end, you will add a line to your program that takes the sensor temperature and calculates the corrected temperature. It might look like:

float corrected_T = a*measured_T*measured_T + b*measured_T + c;

where a, b, c are constants determined by the curve fit program for a quadratic correction.

For this operation:

If the temperature read is 0 degrees, subtract 2 degrees
If the temperature read is 50 degrees, subtract .5 degrees
If the temperature read is -50 degrees, subtract .5 degrees

The equation is

float corrected_T = 0.0006*measured_T*measured_T + measured_T - 2.0;

Had a similar problem long ago, solved it by multimap.
Multimap has two arrays, one of in-values (increasing) and one of corresponding out-values.
in between it does linear interpolation

Check - arduino.cc/playground/Main/MultiMap for some examples

A float version is at the end of the article.

latest version is on github, slightly different


my new DHTNEW lib has an option to set a constant offset, separate for temp and hum.
might be an option to try DHTNEW class for DHT11 and DHT12 and compatibles. - Libraries - Arduino Forum

Hi,
Have you got a bypass capacitor across the power pins at the DHT22?

Do you have any other sensors/hardware with the DHT22?

Tom... :slight_smile:

The rated error of that sensor is +/- 0.5 C, with repeatability a bit better at +/- 0.2 C.

So your measurement errors are only just out of spec, and the question is of course: are you really sure that your reference thermometer is really that much more accurate? Is that one calibrated?

Hi,
How have you got the sensors housed?
Are you measuring the environment AT the DHT?

What is the distance from controller to sensors.

Tom... :slight_smile:

TomGeorge:
What is the distance from controller to sensors.

As the protocol is digital, distance should not matter. Or do I miss a point?
(it still early monday overhere)

robtillaart:
As the protocol is digital, distance should not matter. Or do I miss a point?
(it still early monday overhere)

Some digital protocols are only for PCB level comms, or very short distances. for eg I2C.
Tom... :slight_smile:
(Monday night..here, just to let you know, its been a nice day, you will enjoy it,,,, :slight_smile: :slight_smile: :slight_smile: :slight_smile: )