5

Smart Humidity and Temperature sensor TH02 Library

Playing around with Hoperf RFM12B and RFM69 for my wireless sensors, I discovered they also have one interesting sensor for temperature and humidity called TH02. Just look the picture below, this sensor is so small

th02 pinout

th02 sensor pinout

Of course I already looked and tried some other humidity sensors such as DHT11 or DHT22 but from my point of view they are too big and not so accurate, slow conversion time and does not have really low power. Moreover, protocol to read them need to be interrupt free and strict timing for controlling the pins.

I found some other more accurate but far more expensive. Well the famous “you’ll have what you pay for” applied for humidity sensors until I discovered this one.

TH02 is an I2C sensor, as I’m using a lot of I2C devices such as OLED described in previous post it’s not really a problem. And what I like on this sensor is :

  • it’s small,
  • it’s almost accurate for the price (0.5°C, 4.5% RH)
  • it is not very expensive (less than $5)
  • it is numeric and factory calibrated
  • it has really low power consumption (about 320µA during conversion, 150µA in idle mode)
  • it has a fast conversion time (40ms max)
  • it’s bread board friendly or easy PCB soldering
  • it has a fast response time (15ms max after power up) so powering up, and doing a temperature conversion AND a humidy conversion is typical 63ms and maximum 76ms
  • it can use I2C bus until 400 KHz (tested) and has 75 Ko integrated pull up resistor

And for all of this, I think it is an excellent humidity and temperature sensor. This is why I ordered some and played with them without any problem.

Arduino Library

While I was testing them with my sensors, I created a Arduino library to use it. You can find the library and sample code on my github in the TH02 repository

Features

List of features implemented in this library:

  • Reading device ID
  • Starting a Temperature / Humidity conversion in normal/fast mode
  • Keep in memory last Temperature and Humidity with 2 digits precision
  • Calculate Linear and temperature compensation for Humidity
  • Waiting end of conversion with time out
  • return data as int16 * 10 rounded to avoid float in your program

Usage and installation are described on README.md file. As the standard Arduino I2C library (Wire) can’t do repeated start, I’m using the excellent I2C library written by Wayne Truchsess. You fill find excellent documentation about I2C and library comparison on the DSS Circuit site . I strongly suggest to use this library in all you project using I2C as master. Edit of April 2015, The library now use the Arduino Wire library. This add compatibility with other I2C libraries already using the wire library.

Here is a dump of the sample sketch GetTempHum provided with my library running :

Starting Temperature conversion..done!
Temperature = 24.37 C  =>  24.4 C
Starting Humidity conversion..done!
Raw Humidity = 65.25%  => Compensated 58.69%  Rounded  58.7%

See this sketch source code on Github TH02 library. The test has been done cabling the sensor to custom Moteino USB board like the following picture

TH02 connected to Moteino

TH02 connected to custom Moteino USB using I2C

Reference

For any explanation see TH02 sensor information and datasheet on Hoperf site. This is the documentation I used to create the library.

You can buy sensor on Anarduino site for $4.55

Charles

Charles

You can discuss about this article or other project using the community forum