-
Notifications
You must be signed in to change notification settings - Fork 50
SHT1x
The SHT1x is a family of temperature and relative humidity sensor chips (SHT10, SHT11 and SHT15) that seems to be what some of the TEMPer devices use - or at least they're using a chip that uses the same formulas for calculating the temperature and relative humidity from the raw data.
The Sensirion SHT10 has a temperature range of -40°C to 123.8°C, with an accuracy of ±0.5°C (typical), and a 14-bit resolution (typical; 12-bit minimal). It has a relative humidity range of 0%RH to 100%RH, with an accuracy of ±4.5%RH (typical), and a 12-bit resolution (typical; 8-bit minimal). The SHT11 and SHT15 are the same except for better accuracies. For more details, see the datasheet.
However, the TEMPer types using this chip (or an equivalent) usually say -40°C ~ +120°C - so they might be using a compatible chip instead of an actual Sensirion SHT1x, and thus might have different characteristics. (On the other hand, RDing might simply be rounding off, and using the same numbers on all their devices.)
The raw data we get from this type of sensor is four bytes, two for temperature and two for relative humidity.
The temperature bytes are a high byte and a low byte, where the high byte is signed (using two's complement notation) and the low byte is unsigned (since both are really just one number with more than 8 bits).
To convert these two bytes into a floating-point temperature value in degrees Celcius, we start by combining the bytes into an integer:
int temp = ( (signed char)high_byte << 8 ) + ( (unsigned char)low_byte && 0xFF );
Then, we convert it to a float, using this formula (which was taken from the SHT1x datasheet, and uses the high-resolution values for VDD = 3.5V):
float tempC = -39.7 + 0.01 * temp;
The relative humidity bytes are, again, a high byte and a low byte, but this time both are unsigned (since the relative humidity cannot be below zero).
To convert these two bytes into a floating-point relative humidity value in %RH, we start by combining the bytes into an integer:
int rh = ( ( high_byte & 0xFF ) << 8 ) + ( low_byte & 0xFF );
Next, we linearize the value, using this formula (which was taken from the SHT1x datasheet, and uses the high-resolution values):
float relhum = -2.0468 + 0.0367 * rh - 1.5955e-6 * rh * rh;
Then, we apply temperature compensation, using this formula (which was taken from the SHT1x datasheet, and uses the high-resolution values) and the temperature calculated as above:
relhum = ( tempC - 25 ) * ( 0.01 + 0.00008 * rh ) + relhum;
And finally, we clamp the values to a sensible range, as the datasheet says to do:
if ( relhum <= 0 ) relhum = 0;
if ( relhum > 99 ) relhum = 100;