:: Sensirion Humidity and Temperature Sensors ::
Note: Page under construction. Feel free to add to it!
This page is dedicated to the care and feeding of the Sensirion SHT1x and SHT7x series humidity and temperature sensors. Information regarding the new SHT21 sensors will be added at a later date (after I've gained experience with my forthcoming sample!).
Navigation
Helpful Hints
- Hint: If the measured temperature and humidity has very bad resolution, read this: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229870415/0
- >> Version 2.0 of the library added consistent setting of the internal pullup for the data pin (on by default). Previous versions left the internal pullup state undefined, i.e., dependent on the value of the last bit transmitted. A #define in Sensirion.h can be used to modify pullup usage. Note: the Sensirion data sheet recommends using a 10K ohm pullup - the Arduino internal pullup ranges from 20K to 50K ohms.
- The CRC (cyclical redundancy check) functionality and enhanced error reporting included in the latest version of the library can be used to help diagnose communication problems with the sensor. See the NonBlocking example included with the library for an approach to taking advantage of these features.
- Self-heating: Sensirion recommends that the sensor not be active more than 10% of the time to avoid erroneous temperature measurements due to self-heating. In its default high resolution mode, the sensor takes up to 320 msec to perform a 14-bit temperature measurement and 80 msec to perform a 12-bit humidity measurement. That's 400 msec combined so include at least a 3.6 second delay between pairs of temperature & humidity measurements. Low resolution mode reduces these numbers to 80 msec for temperature (12-bit) and 20 msec for humidity (8-bit), allowing the delay to be reduced to 1 second. Note: The SHT1x library currently measures both temperature and humidity in "readHumidity()" (raw humidity measurements must be temperature compensated) so the delay should be at least 6.5 seconds when using this library.
- Non-blocking calls: As noted above, the sensor can take quite a while to perform a measurement. Traditional blocking calls send a command to the sensor and then spin, waiting for the measurement to complete. This means your sketch can spend hundreds of milliseconds doing nothing! Non-blocking calls return control to your sketch immediately after the command is sent but require the sketch to periodically check for completion. The example code on this page and the NonBlocking example included in the Sensirion library show ways to take advantage of this approach.
Libraries and Example Code
Sensirion
Version 2.0 - 10Dec2010
Rewritten version of the library that includes extensive changes for robustness, reduced code size, plus a couple of new features while maintaining backwards compatibility with previous versions.
- Added CRC checking (enabled by default via #define in Sensirion.h)
- Added consistent setting of the data pin internal pullup (was previously undefined - depended on last bit transmitted)
- Improved error reporting capability
- Added status register read function; expanded write function to cover all settable bits.
Download library: Sensirion_10Dec2010.zip
Example code:
/*
* Example code for SHT1x or SHT7x sensors demonstrating blocking calls
* for temperature and humidity measurement in the setup routine and
* non-blocking calls in the main loop. The pin 13 LED is flashed as a
* background task while temperature and humidity measurements are made.
*/
#include <Sensirion.h>
const uint8_t dataPin = 9; // SHT serial data
const uint8_t sclkPin = 8; // SHT serial clock
const uint8_t ledPin = 13; // Arduino built-in LED
const uint32_t TRHSTEP = 5000UL; // Sensor query period
const uint32_t BLINKSTEP = 250UL; // LED blink period
Sensirion sht = Sensirion(dataPin, sclkPin);
uint16_t rawData;
float temperature;
float humidity;
float dewpoint;
byte ledState = 0;
byte measActive = false;
byte measType = TEMP;
unsigned long trhMillis = 0; // Time interval tracking
unsigned long blinkMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
delay(15); // Wait >= 11 ms before first cmd
// Demonstrate blocking calls
sht.measTemp(&rawData); // sht.meas(TEMP, &rawData, BLOCK)
temperature = sht.calcTemp(rawData);
sht.measHumi(&rawData); // sht.meas(HUMI, &rawData, BLOCK)
humidity = sht.calcHumi(rawData, temperature);
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}
void loop() {
unsigned long curMillis = millis(); // Get current time
// Rapidly blink LED. Blocking calls take too long to allow this.
if (curMillis - blinkMillis >= BLINKSTEP) { // Time to toggle the LED state?
ledState ^= 1;
digitalWrite(ledPin, ledState);
blinkMillis = curMillis;
}
// Demonstrate non-blocking calls
if (curMillis - trhMillis >= TRHSTEP) { // Time for new measurements?
measActive = true;
measType = TEMP;
sht.meas(TEMP, &rawData, NONBLOCK); // Start temp measurement
trhMillis = curMillis;
}
if (measActive && sht.measRdy()) { // Note: no error checking
if (measType == TEMP) { // Process temp or humi?
measType = HUMI;
temperature = sht.calcTemp(rawData); // Convert raw sensor data
sht.meas(HUMI, &rawData, NONBLOCK); // Start humidity measurement
} else {
measActive = false;
humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
dewpoint = sht.calcDewpoint(humidity, temperature);
logData();
}
}
}
void logData() {
Serial.print("Temperature = "); Serial.print(temperature);
Serial.print(" C, Humidity = "); Serial.print(humidity);
Serial.print(" %, Dewpoint = "); Serial.print(dewpoint);
Serial.println(" C");
}
Version 1.1 - 04Aug10
This version of the library includes several enhancements over the original. It was a goal of this rewrite to bring in new functionality while modifying the original code as little as possible to avoid impacting existing sketches that use this library. Enhancements include:
- Added separate functions for temperature and humidity measurements, each with blocking vs. non-blocking flags
- Added function to write the sensor Status Register to enable selecting the sensor precision (ie, 14-bit/12-bit Temp/RH vs. 12-bit/8-bit Temp/RH)
- Dewpoint calculation is now a public function
- Updated temperature, humidity, and dewpoint equations to match latest recommendations from Sensirion (V4)
Download library: Sensirion_04Aug10.zip
Original version - 28Nov08
Version of the Sensirion library first available through the Interfacing With Hardware page.
Download library: http://www.target23.de/data/Sensirion_20081128.zip
SHT1x
Library available from Practical Arduino. No commentary yet due to my lack of experience with this library. Feel free to contribute comments to this page.
Download library: http://github.com/practicalarduino/SHT1x