As tempatures are slowly going below freezing point (0 degrees celsius) at night here in germany, i discovered a problem with the sensor's Arduino Class.
When the temperature drops below 0°C (for exampe -1°C) the Class gives me exactly 0°C at all times.
I figured out the class got an update regarding to this issue 4 month ago, so i updated the class and re-uploaded my sketch to the board.
Now, when the temperature drops below 0°C, i get something like 3275.3°C from the class. (but everythink ok with positive temperatures)
As the variable inside the class is working with integers, i remembered the maximum integer value is 32767.
So real my temperature is probalby 32767 (max int. value) - 32753 (value the class gives me) = 14 = 1.4 = the real -1.4°C
It seems to me something causes the integer value to overflow, but i don't know how to solve this...
Ok, as i'm sending the measured values every 10 minutes to a webserver, i could just calculate the real negative temperature,
but that didn't solve the problem on the roots.
You can try my DHT library - Arduino Playground - DHTLib - if it meets your requirements. It should work for negative temperatures.
Interface is a bit different as it also supports the DHT11 which does not do negative values.
A quick look shows that the algorithm should work, I see no real failure there wrt sub zero values.
Above 0 it works - you did not mention failure there.
To mimic the code with the one in my library you should change
f = (data[2] & 0x7F)* 256 + data[3];
f /= 10.0;
if (data[2] & 0x80) f *= -1;
printf("Temp = %.1f *C, Hum = %.1f \%\n", f, h);
to
if (data[2] & 0x80)
{
int t = (data[2] & 0x7F)* 256 + data[3];
printf("t = %d", t);
f = t * -0.1;
}
else
{
int t = data[2] * 256 + data[3];
printf("t = %d", t);
f = t * 0.1;
}
printf("Temp = %.1f *C, Hum = %.1f \%\n", f, h);
can you post the output the application generates?
The problem looks like the code thats reading the sensor isnt interpreting the Sensors sign bit.
The DHT22 sensor uses the MSB of data byte 3 to indicate a positive or negative temperature.
Its 0 for positive and 1 for negative temps, so if the sign bit isnt read properly, you get very high positive temps.
I have the same problem. Today temperature goes under 0°C and my weather station send bad values to webserver:
3276.6
3276.5
3276.4
3276.7
Temperatures >0°C is good.
I used this DHT22 library. My Arduino code.
I have ATmega8 without bootloader and it is located in very remote place . So is very difficult to reflash firmware in ATmega8 for me
Is there any way to calculate good temperature from number like "3276.5"?
EDIT:
If i understand you, for "3276.5" i must do: ( 32767 / (3276.5 * 10) / 10) = -0.1°C
What about lower temperatures? For example -20.7°C? Is still possible to calculate good temp?
Just in case you haven't noticed, the thread was over three years old before you replied to it and the forum told you it was an old thread but you posted anyway.