Skip to content
Luka Pravica edited this page Mar 11, 2018 · 3 revisions

The SHT2x series consists of a low-cost version with the SHT20 humidity sensor, a standard version with the SHT21 humidity sensor, and a high-end version with the SHT25 humidity sensor.

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, both unsigned. The default resolution is 14 bit and the two last bits of the LSB must be set to zero. Some TEMPer devices shift the raw sensor temperature data by two bits and the data needs to be shifted back before the conversion equations are used.

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 = ( (unsigned char)high_byte << 8 ) + ( (unsigned char)low_byte && 0xFF );

Then, we convert it to a float, using this formula (which was taken from the SHT20 datasheet):
float tempC = -46.85 + 175.72 * temp / 65536;

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). The default resolution is 12 bit and the four last bits of the LSB must be set to zero. Some TEMPer devices shift the raw sensor humidity data by four bits and the data needs to be shifted back before the conversion equations are used.

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 );

Then, we convert it to a float, using this formula (which was taken from the SHT20 datasheet):
humidity = -6 + 125 * rh / 65536;

Clone this wiki locally