Temperature & Humidity with the Sensirion SHT1x

(c) 2002 EME Systems, Berkeley CA U.S.A.
 <stamp index> <home>


Sensirion SHT11 or SHT15

updated 8/29/2005

sht1x by pennyA smart sensor for humidity and temperature available from Sensirion (http://www.sensirion.com). It comes from the factory in a tiny package that incorporates a precision analog to digital interface and a identical unit to unit calibration. All that a microcontroller has to do is read out the humidity and temperature values, via the two-sire digital serial interface. The only math required is a simple and offset and temperature compensation.SHT75

The photo to the left shows the sensor chip in relation to the great emancipator, and also the sensor chip mounted on an SMT carrier board so that it could be plugged into a DIP socket for experimentation. The top of the sensor chip carries a black plastic protective cover with a hole in the end to allow air to enter. Another photo below left shows the chip mounted on a SIP carrier board with the resistors and a bypass capacitor.

Sensirion also has sip package with pins on 0.05" centers (SHT7x). The sensor is located on the end of a long, thin neck with very good air flow and thermal characteristics.  See below for how we have mounted that in a modified PG7 gland nut. 

sensirion on SIPThe circuit is simplicity itself. A pull-up resistor is required on the data signal line, which is open collector and can be asserted by either the microcontroller or the SHT1x. The 220 ohm resistor shown in series between the Stamp and the SHT15 is required in my setup, because both the Stamp and the SHT1x can potentially be outputs at the same time and in opposite states. The resistor is for protection. Sensirion recommends also a pulldown resistor on the clock signal line. Occasionally, without it, the chip can fail to initialize properly, when the power supply comes up slowly or with noise. The power supply bypass capacitor is highly recommended.  Note that the pinout of t he SHT7x in the sip package is different from the pinout in the surface mount package.  Refer to the  data sheet available from the Sensirion web site.SHT1x schematic

 

The SHTxx chip also has a provision to turn on an internal heater, which is valuable for checking the operation and also for preventing condensation. It remains to be seen how well this sensor will hold up in hostile environments. The qualification data provided by Sensirion looks good, in terms of recovery from condensation from other hostile influences typically found in weather monitoring. (See the Sensirion web site).

At EME Systems, we are working to provide an outdoor packaging suitable for use with our OWL2 weather stations.  The photo on the left below shows the SHT75 mounted in a PG7 gland nut, sealed at the back and incorporating the resistors and capacitor shown in the schematic.   This arrangement can allow for sealing to an enclosure, but with good air flow.   The second photo shows the PG7 gland mounted on an enclosure, with the addition of a cap and water vapor permeable membrane.  This protects the sensor from hostile environments (e.g., seawater or agricultural sprays), in trade for a much slower response time, which is not important in many applications.   Note that Sensirion can now provide a Goretex cap for the model SHT1x sensor.    The diagram on the right shows the SHT15 mounted at the bottom edge of a circuit board next to an OWL2pe data logger, part of a  custom pollution monitoring instrument.


SHT75 in PG7 grip    SHT75 in PG7 grip with goretex membrane     SHT15 mounted on circuit board in polution monitor                                         SHTxx pinouts


sht1x on BOEDemo program. The following is a demo program for the BASIC Stamp II. It reads both the humidity and temperature from the SHT1x (or any of the chips in this line), and does the math to maintain the best resolution and to provide the temperature compensation. As usual with the serial interface chips, it is necessary to read the data sheet carefully to understand the serial protocol. The chip uses a protocol similar to I2C, but different. (You cannot use the BS2P I2C commands.) There is a start sequence and also an acknowledge after each byte, which the program below bit-bangs, for the rest it uses SHIFTIN and SHIFTOUT commands. A CRC is available to check the integrity of the data, but this program ignores it, which should be no problem on short data lines.  Note in the photo that the pulldown resistor on the clock line is not there.   I originally worked this out before Sensirion started recommending that resistor.   Most of the time it works without it.

'{$STAMP BS2}
' SHT15.bs2 version C
' (c) 2002, 2004 Tracy Allen, http://www.emesystems.com
' access the Sensirion model sht11 or sht15
' humidity and temperature chip
' temperature to xx.x degrees Celsius, RH to xx.x %
' Repeatedly shows raw data and converted values on debug screen.
' version B, corrects glaring error in humidity computation
' also adjusts timeout to allow use with faster stamps too.
' version C updates the math for temperature compensation of %RH
' and enables display of negative temperatures
' hookup sht11 or sht15 as follows for this program
'
' STAMP SENSIRION
' 220
' p1 ----o-----/\/\---o--pin 3 sck, clock
' |
' ;---/\/\-----' pull-down
' | 4.7k
' Vss--o-o---------------pin 1 common
' |
' === 0.1uf
' |
' Vdd--o-o---------------pin 4 +5 volts
' | 4.7k
' '---/\/\-----; pull-up
' |
' 220 |
' p0 ----------/\/\---o--pin 2 dta, data
'
'
' The following code does not implement the CRC checking


sck PIN 1
dta PIN 0 ' note, 5k-10k pull-up, also 330ohm between the dta on stamp to dta on sht
dtain var in0

shtTR CON 3 ' read temperature
shtRH CON 5 ' read humidity
shtSW CON 6 ' status register write
shtSR CON 7 ' status register read
shtS0 CON 30 ' restore status register defaults (be sure to delay 11 milliseconds)

cmd VAR Byte
result VAR Word ' raw result from sht, also used as counter
r0 VAR result.byte0
r1 VAR result.byte1
degC VAR Word ' degrees Celsius * 100
RH VAR Word ' %RH * 10
RHtc VAR Word ' for temperature compensation of RH

initialize:
outs=0
dirs=%1111111111111101
GOSUB shtrst ' reset communication with sht

DO
getTemperature:
cmd=shtTR ' temperature command to sht
GOSUB shtget16
degC=result+5/10-400 ' from 100ths to 10ths of a degree with rounding
DEBUG tab,REP "-"\degC.bit15,DEC ABS degC/10,".",DEC1 ABS degC
getHumidity:
cmd=shtRH ' humidity command to sht
GOSUB shtget16
RH=(26542-(54722**result+result))**result-40
' temperature compensation follows:
RHtc=655+(result*5)+(result**15917) ' intermediate factor
RHtc=(RHtc**(degC+2480))-(RHtc**2730)+RH ' compensated value
DEBUG tab, DEC result,tab,"%RH=",DEC RH/10,".",DEC1 RH
DEBUG tab,"%RHtc=",DEC RHtc/10,".",DEC1 RHtc,cr
PAUSE 1000
LOOP

' initializes communication with sht
shtRst:
SHIFTOUT dta,sck,lsbfirst,[$ffff\16]
RETURN

' get 16 bits of data, enter with command in "cmd"
shtget16:
gosub shtcmd ' send the command "cmd"
gosub shtwait ' wait for command to finish
shiftin dta,sck,msbpre,[r1] ' msbyte
low dta ' acknowledge
pulsout sck,10
input dta
shiftin dta,sck,msbpre,[r0] ' lsbyte
input dta ' terminate communication
pulsout sck,10
return

' send start sequence and command
shtcmd:
shtStart: ' send the start sequence
' dta: ~~~~~|_____|~~~~~~
' sck: ___|~~~|_|~~~~|____
' while dta is low, clock goes low and then high
input dta ' pullup high
high sck
low dta
low sck
high sck
input dta
low sck
shtcmd1: ' send the command
shiftout dta,sck,msbfirst,[cmd]
input dta ' allow acknowledge
pulsout sck,10
return

shtWait:
' wait for sht to pull data pin low
' or for time out
result=4096
DO
result=result-1
LOOP WHILE dta & result.bit11
RETURN

Math explanation: The math makes use of the ** operators to calculate the mulitplications times fractional values. The operators are explained in my tech note on BASIC Stamp math.

Here is the Sensirion formula that converts the raw result into relative humidity, a quadratic polynomial:

RH = c1 + c2* result + c3 * result2

with constants as follows:

c1 = -4
c2 = 0.0405
c3 = -2.8E-6

The formula can be rewritten as follows:

 RH = (c2 + (c3 * result)) * result + c1

The Stamp translation is the following. Each term is going to be multiplied times 10,in order to carry through one digit to the right of the decimal point.:

RH=(26542-(54723**result+result))**result - 40
----- -------------------- -------- --
( c2 + c3 * result ) *result + c1

with constants as follows:

10*c1 = -40 and on the stamp, that is the -40 at the end of the expression above

10*c2 = 0.405 on the stamp written as the fraction 26542/65536, (denominator implied)
or 26542 **
which will be used with the ** result that comes after adding... (the tricky one!)

(10*c3 * result) = -2.8E-5 * result
2.8E-5 * result is the same as the fraction 1.835/65536 * result
is the same as 1.85 * result / 65536
is the same as (0.85*result + result)/65536
is the same as (54723/65536 * result + result) / 65536
which on the Stamp is done with the denominator implied in the **.
(54723 ** result + result) **


Similar logic applies for the temperature compensation

From Sensirion, it involves the deviation of the temperature from 25 degrees Celsius, as well as the raw humidity value (result), added to the uncompensated humidity value:

RHtc = (T - 25) * (0.01 + 0.00008 * result) + RH

Order of magnitude: The raw humidity variable "result" can have values from near zero up to about 3000. So the temperature conpensation factor calculated by the expression inside the second set of parentheses varies from 0.01 percent to 0.25 percent per degree Celsius. Suppose the humidity is near 100 percent. Then the humidity compensation could add or subtract 6 percent humidity over the zero to 50 degree Celsius range. Less compensation at lower humidities.

Negative values don't work with the Stamp integer math ** operator, so I transform the temperature to Kelvin, by adding 273.

RHtc = ((T+273) - 25) * (0.01 + 0.00008 * result) - (273 * (0.01 + 0.00008 * result)) + RH
-----
(T+248)

That might seem more complicated, adding the 273 at one point and subtracting it at another, but the benefit is that the quantity (T+248) is always positive, and will multiply using the ** operator .

Consider the factor that involves the raw humidity "result".

(0.01 + 0.00008 * result)

It takes a treament just like the one above.

 0.01 on the Stamp is written as 655/65536

0.00008 * result is the same as 5.243/65536 * result
which is the same as (5* result + 0.243* result)/65536
which is the same as (5*result + 15917/65536 * result)/65536
which on the Stamp is done with the denominator 65536 implied in the ** operator
and combining the two terms, the factor to be multiplied times temperature is:

655 + (5*result) + (15917 ** result) ** (deviation of temperature from 25 Celsius)

In the above program, this factor is held temporarily in the variable RHtc

RHtc=655+(result*5)+(result**15917)

For example, suppose result = 1742 when RH=58.0%. The factor is computed on a calculator as follows: (0.01 + 0.00008*1742) = (0.01+0.1394) = 0.1494. (that change in %RH per degree Celsius) And in Stampese,

655 + (1742 * 5) + (1742 ** 15917) = 655 + 8710 + 423 = 655+9133 = 9788.

Observe that 9788/65536 = .14935, which is, as it should be, the same as the number computed on a scientific calculator. This is the number required for the ** operator.

The final formula is this:

 RHtc=(RHtc**(degC+2480))-(RHtc**2730)+RH ' compensated value

Going in, the factor we just calculated is held temporarily in variable RHtc. The temperature is held in variable degC, but recall that the value is actually ten times temperature. That is okay, because raw humidity variable RH is also holdes a value that is ten times the real value. The absolute value constant is 2730 in units of tenths of a degree.


A command-response interface. This is another program, sht1xdp.bsx. This one is able to turn the on-chip heater ON and OFF, and can also compute the dew point from the temperature and humidity values. Observe that the the program is specified for the BS2sx. Change the baud rate to use it with a slower stamp.

The interface is command driven. A prompt ">" appears on the left edge of the screen. To get a response, you enter the letter "s" (lower case) followed by a number at the keyboard:

  1. get and display Celsius temperature dgC=xx.x
  2. get and display %RH=xx.x
  3. turn on the sht1x internal heater, heat=1
  4. turn off the sht1x internal heater, heat=0 (default)
  5. get and display the dewpoint temperature dpC=xx.x

The dew point calculation is quite a challenge for the integer brain of the Stamp. Another demo program, dewpoint.bsx, allows you to enter temperature and RH values at the keyboard, instead of taking them from the sensor.

Here are some problems one encounters when applying traditional humidity sensors, problems that are well addressed by the Sensirion product:

  • Analog to digital interface and external circuitry: Many sensors transduce the humidity signal as a voltage or as a basic parameter such as capacitance or resistance. Additional circuitry is needed in order to read that signal with a microcontroller such as the BASIC Stamp. At the very least, there is an analog to digital or analog to time converter. This may take a couple of op-amps or an oscillator circuit, perhaps with provision for calibration of slope and offset.
  • Temperature compensation and dew point calculation: It is very useful to have an accurate temperature sensor in the same package as the humidity sensor, in order to calculate the dew point accurately, and also to temperature compensate the humidity signal if necessary. A separate interface and analog to digital channel may be required for the temperature sensor. (Example, the Honeywell HIH3602 includes an RTD inside the package with the humidity element, and our RHTD module provides the necessary interface between that chip and an analog to digital converter. The interface requires a voltage reference, an instrumentation amplifier and an op-amp.)
  • Calibration: The humidity transduction circuit requires initial calibration. Calibration constants for each individual sensor may come on a paper certificate, and those constants have to be dialed in, or entered into the microcontroller program, or provision has to be made for the end user to enter them. Provision has to be made for changing the sensor element at intervals of time (depending mostly on the challenge from the environment), or provision has to be made for recalibration or calibration checks using saturated salt solutions or other means.
  • Mounting, protection and response time: This is where the humidity sensor meets the real world. The sensor element itself has to be exposed to the hygro- and thermo- environment, but the electronics and the sensor element itself have to be well protected from condensation, dust and fumes that could degrade the calibration and eventually destroy the sensor. Some available humidity sensors are designed strictly for indoor use in mild environments. Other sensors, such as the HIH3602, incorporate several levels of protection that go a long way to protecting them at the core from the hostile environment. The HIH3602 is very convenient to use with its TO-5 metal package with the sintered stainless steel filter cover, but that makes its response quite slow.

 


 .<top> <index> <home> eme logo < mailto:info@emesystems.com >