Parts: Precision Humidity And Temperature Sensor (SHT1x/7x)

sht11

Sensirion’s SHTxx is a digitally interfaced humidity and temperature sensor. Accurate humidity measurements usually require careful analog design, but the SHTxx moves all that complicated stuff into a single chip. Through-hole (SHT7x) and surface mount (SHT1x) versions are available, we used the surface mount SHT11 with +/-3% accuracy. We’ll show you how to use the SHTxx below.

Sensirion SHT1x/SHT7x precision humidity and temperature sensor (Octopart search, starting at $25).

This isn’t a cheap sensor. Octopart lists a few places to buy it. Several smaller hobby electronics stores carry it; Hobby Engineering has it for $29 (#H01509-01C). We found compatible PCB footprints in sht10_11_15.lbr and sht11.lbr on the Cadsoft library download page. Pin connections for the different package types are in the datasheet: SHT1x (PDF), SHT7x (PDF).

sht11

The SHTxx has a two-wire serial interface that requires pull-up resistors (R1,2), values between 2K and 10K should work. Sensirion recommends a decoupling capacitor (C1) only if the sensor is powered over a length of wire, but we think it’s always a good idea to include one.

We’ll demonstrate the SHTxx using the Bus Pirate universal serial interface in raw2wire mode with Hi-Z outputs. The SHTxx is powered from the Bus Pirate’s 3.3volt supply. The Bus Pirate’s on-board pull-up resistors hold the bus high, eliminating the need for external resistors R1 and R2.

Interface

The SHTxx communicates over two wires using a simple serial protocol. The protocol isn’t compatible with I2C, but a single SHTxx can exist on a bus with I2C peripherals.

Command Code
Measure Temperature 00000011
Measure Relative Humidity 00000101
Read Status Register 00000111
Write Status Register 00000110
Soft reset 00011110

Five commands control the SHTxx, these are outlined in the table. The first 3 bits are the address (always 000), the remaining 5 bits are a unique command code.

Reset

Start a transaction by clearing any partial commands or data from a previous use. A minimum of nine clock ticks while data is high will clear the SHTxx interface. The Bus Pirate syntax to for this is -^:9; data high (-), 9 clock ticks (^:9).

Commands to the SHT11 begin with a unique start condition. Like an I2C start condition, this is the only time when the data signal changes with the clock signal high. This illegal condition causes the chip to prepare for a new command. The SHTxx start condition is different than I2C, allowing both types of devices to exist on the same bus.

The Bus Pirate code to generate an SHTxx style start condition is -/_\/-\ ; data starts high (-), clock up (/), data goes low (_), clock low (\), clock high (/), data goes high (-), and a final clock low transition (\) ends the sequence.

A soft reset is a good idea because it puts the chip in a default state. Prior to the first temperature or humidity conversion, we send the soft reset command.

RAW2WIRE>-^:9 -/_\/-\ 0b00011110 !<–command
4xx RAW2WIRE DATA OUTPUT, 1 <–clear interface
4xx RAW2WIRE 0x09 CLOCK TICKS
4xx RAW2WIRE DATA OUTPUT, 1 <–start condition
4xx RAW2WIRE CLOCK, 1
4xx RAW2WIRE DATA OUTPUT, 0
4xx RAW2WIRE CLOCK, 0
4xx RAW2WIRE CLOCK, 1
4xx RAW2WIRE DATA OUTPUT, 1
4xx RAW2WIRE CLOCK, 0
420 RAW2WIRE WRITE: 0x1E <–soft reset code
4xx RAW2WIRE READ BIT: 0 <–acknowledge bit, OK
RAW2WIRE>

First, we clear the interface (-^:9), then send the start condition (-/_\/-\). The reset command (0b00011110=0x1E) follows. The SHTxx acknowledges (acks) commands by pulling the data line low for one bit after a command is transmitted. We read one bit (!) to get the acknowledgment status; 0 is success, 1 signals an error.

Temperature

Now we can read the temperature. This happens in two steps, with a delay for the temperature conversion.

RAW2WIRE>-^:9 -/_\/-\ 0b00000011 !
4xx RAW2WIRE DATA OUTPUT, 1  <–clear interface
4xx RAW2WIRE 0x09 CLOCK TICKS
4xx RAW2WIRE DATA OUTPUT, 1 <–start condition

4xx RAW2WIRE CLOCK, 0
420 RAW2WIRE WRITE: 0x03 <–start temperature conversion
4xx RAW2WIRE READ BIT: 0 <–ack bit, OK
RAW2WIRE>

First, we send a start condition and the temperature conversion command (00000011=0x03). The SHTxx replies to a successful command by pulling the data line low for one bit (ack). After the ack bit, the data line goes high until the conversion finishes.

RAW2WIRE>.
4xx RAW2WIRE DATA INPUT, STATE: 0 <–data low when done
RAW2WIRE>

When the data line goes low, the temperature conversion is finished. ‘.’ is the Bus Pirate command to read the data state without a clock tick. Now we can grab the result.

RAW2WIRE>r_^ r_^ r_^
430 RAW2WIRE READ: 0x17 <–data byte 1
4xx RAW2WIRE DATA OUTPUT, 0 <–data low
4xx RAW2WIRE 0x01 CLOCK TICKS <–send ack bit
430 RAW2WIRE READ: 0xCC <–data byte 2
4xx RAW2WIRE DATA OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
430 RAW2WIRE READ: 0x0C <–crc
4xx RAW2WIRE DATA OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
RAW2WIRE>

Each byte read (r) requires an I2C style acknowledgment bit with the data low. We do this with the _^ sequence; data low (_), one clock tick (^).

The first two bytes are the temperature reading (0x17cc), followed by a CRC (0x0c). The raw value (0x17cc=6092) is converted to degrees Celsius using the equation and coefficients on page 9 of the datasheet. Temperature readings are 14bits by default:

T = -39.7 + 0.01*X

21.22C = -39.7 + (0.01*6092)

Humidity

Humidity conversions are started with code 00000101 (0x05 hex).

RAW2WIRE>-^:9 -/_\/-\ 0b00000101 ! <–command
4xx RAW2WIRE DATA OUTPUT, 1 <–clear interface
4xx RAW2WIRE 0x09 CLOCK TICKS
4xx RAW2WIRE DATA OUTPUT, 1 <–start condition

4xx RAW2WIRE CLOCK, 0
420 RAW2WIRE WRITE: 0x05 <–start humidity conversion
4xx RAW2WIRE READ BIT: 0<–ack bit, OK

As before, a ninth acknowledgment bit is low if the SHTxx processed the command.

RAW2WIRE>.
4xx RAW2WIRE DATA INPUT, STATE: 0 <–data low when done

The data line goes high and then returns low when the humidity conversion is done.

RAW2WIRE>r_^ r_^ r_^
430 RAW2WIRE READ: 0x05 <–data byte 1
4xx RAW2WIRE DATA OUTPUT, 0 <–data low
4xx RAW2WIRE 0x01 CLOCK TICKS <–ack bit
430 RAW2WIRE READ: 0x80 <–data byte 2
4xx RAW2WIRE DATA OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
430 RAW2WIRE READ: 0x46 <–crc
4xx RAW2WIRE DATA OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
RAW2WIRE>

A complete conversion generates a three byte response. The first two bytes are the raw humidity reading (0x0580=1408), the final byte is a CRC (0x46) that can be used to verify data integrity.

Humidity readings have 12bits of resolution by default, convert to humidity using this equation:

RH = -2.0468 + 0.0367(X) + (-0.0000015955*(X^2))

46.46%RH = -2.0468 + 0.0367(1408) + (-0.0000015955*(1408^2))

Conclusion

This isn’t a cheap sensor, but it doesn’t require careful analog design like the Honeywell HIH series. Have you worked with a humidity sensor?

Like this post? Check out the parts posts you may have missed.

21 thoughts on “Parts: Precision Humidity And Temperature Sensor (SHT1x/7x)

  1. I’ve tried these once, the serial communication is fucked up, the protocol has trouble with the arduino software.

    The second start conflicts with the way the arduino software works.

    On a start command the software buffers the data, and then on an end command it sends it. having two starts doesn’t work.

    I may be wrong, but that’s my experience.

  2. the scp1000-d01 is way expensive ($25 in 100+ quantity from digikey – typically $50 in a breakout from sparkfun). yah, MEMS, 17-bit resolution, whatever, that’s nice. the HP03D, available from futurlec for $9.90 (on a breakout board already), has good enough resolution/accuracy (10/50 Pa) for most weather applications, and it’s an I2C interface.

    the scp1000’s a great chip if you absolutely need high accuracy (e.g. an altimeter). but if you don’t need ~10 Pa accuracy, the HP03D’s a great bet. the HP02D’s half the price of the HP03D if you don’t need high accuracy.

  3. I’m using one of this to read the temperature and humidity on a arduino to calculate the dew point on a paper dryer. Works like a charm.
    You can put a led an resistor on the clock signal to see if the shtxxx is working.

  4. The Honeywell HIH isn’t *that* hard to interface to if you do it using a Dallas DS2438 one-wire chip. The 2438 datasheet has an example of doing this. I’ve been using it for a couple years for remote sensing (it can do temp, humidity, and solar intensity with a single chip) and it’s done very well. Nevertheless, this is a very cool project and it’ll be fun to give it a try.

  5. I’ve worked with these sensors before. They’re quite neat. The best thing is the need for few external components and the small size, which allows you to make a very small sensor unit.

    One thing about the pic in the article: the capacitor, which is meant for filtering high frequencies in the power supply looks more like a loop antenna than a filter.

    “I’ve tried these once, the serial communication is fucked up, the protocol has trouble with the arduino software.

    The second start conflicts with the way the arduino software works.”

    The serial communication in the sensor is “almost i2c”, therefore incompatible with i2c. You will have to write the communication yourself from the lowest level. Having never worked with Arduino, but having worked with several Atmel µCs I’d say it isn’t difficult at all. If something was fucked up when you tried the sensor, it was probably the Arduino or its user.

  6. @neurobyte

    Try writing the I2C handling code yourself. It’s actually fairly simple if you read into the datasheet for the AVR. You’d be surprised what all actually needs a start condition then another rather soon after. I had to implement one for interfacing to either an RTC chip or a temperature sensor, else it wouldn’t send me the data I was looking for.

  7. Does anyone know how to simulate the output of a SHT10 sensor? I am trying to test a control board and it uses a SHT10 sensor. I want to disconnect the sensor and use my computer to generate the signals from a yearly weather file. The board would get the temp and RH signals and I will determine if the board is doing the correct thing given the different temp and RH levels.

Leave a Reply to ferdinandCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.