  14 December 2009
Author: Giorgos Lazaridis
PIC Precision Thermometer and Humidity meter using the SHT15

This could be my favorite sensor that i have interfaced to a PIC so far. There are actually two reasons for that. First, it is a single sensor that it can measure both temperature and relative air humidity with very high accuracy. But the basic reason that i choose this for my favorite sensor, is the challenge to get the measurement results.

The Challenge

Although it uses standard I2C protocol for the communication with the uController, the 12/14 bit return value needs yet many work to become a daily-understandable number. The temperature for example returns a 14-bit number. To convert this number into a oC, you need to apply the following formula:

Temperature = -40 + 0.01 x ValREAD

Of course using a pocket calculator, this is a 3-seconds calculation. But with the PIC, things are much tougher. The PIC can handle 8-bit numbers, that means numbers from 0 to 255. Moreover, within the instructions of the PIC there is no multiplication or division. That makes things even tougher.

But even more difficult is the humidity calculation. To get the results, you need to do many tricks. The calculation formula that needs to be applied to the 12-bit return value in order to get the humidity % is as follows:

Humidity% = -4 + 0.0405 x ValREAD + (-2.8 x 10-6) x ValREAD2

To solve the above two formulas, you need to have a couple of sophisticated subroutines prepared. Basically, you need to have a 16bit x 16bit multiplication routine, and an 24bit / 24bit division routine.

Calculate the temperature

This is by far the easiest part. Basically, what you need to do is to divide the 14-bit return value by 100. Then, you just subtract 40 from the result and that's all! If you have the appropriate 24-bit division routine it is very easy.

Calculate the humidity

Here we need a little bit more work. The procedure that i describe is not common and not the only one correct. Actually, there are lots of "correct" procedures and ways to solve the formula. The one i used is just one way that works.

First of all i calculate the ValREAD2, by multiplying the return value to its self. Then i divide this value by 1000. I multiply the result by 28, and divide the result by 10000. Look bellow:

P = P / 1000
P = P x 28
P = P / 10000

What i've done so far is to have calculated the value for the 2.8 x 10-6 x ValREAD2. The first trick i did was to multiply the 2.8 by 10 and covert it to 28. To balance this, i changed the 10-6 into 10-7. Moreover, you can see that i chose to have 3 different calculations (P/1000, Px28 and P/10000) instead of 2 (P/10000000 and Px28). This is a very important step to maintain the accuracy. I chose the 1000 for the first division, because it is not too big to have a small number as a result (i do not use the decimals), and it is not too small, because the multiplication could overflow the 24-bit return word.

The above result is saved it for later use. Then i multiply the return value by 405, and divide it by 10000:

Q = ValREAD2 x 405
Q = Q / 10000

This calculation will calculate the other part of the formula: 0.0405 x ValREAD. There is not a special trick here, instead of that i multiply the 0.0405 by 10000 to convert it to 405, and after the multiplication with the read value, i divide it with 10000 again. I did not want to mess with decimal numbers.

Finally, all i had to do to get the humidity in percent, was to subtract the previous calculated value (P) from this value (Q), and subtract another 4 from the result:

Humidity% = P - Q - 4

I can say that i was quite aroused when the whole thing worked! And the fact that having decimal numbers in the humidity result is not necessary (not to say confusing), turns the above calculation series valid and accurate.

The Circuit

The schematic diagram is very simple. I use the PIC16F631. The microcontroller is the PIC 16F631. The communication with the SHT15 comes from pins RC6 (Data) and RC7 (Clock). The communication with the 20x4 display is done by using the short protocol (4-bit communication). The R/W wire of the LCD can be held permanently low (and save one I/O port of the PIC), as i only Write data to the LCD and do not Read any. Notice that the Data bus of the SHt15 needs a pull-up resistor. An 1K resistor is enough. Higher values may cause problems as the rise and fall times will be higher. The LED is blinking every time a new measurement is taken.

Here are all the files needed as well as the full assembly listing, to re-compile the program: SHT15 PIC precision temperature and humidity meter

For those that do not want to recompile and wants it as-is, here is the compiled hex version to directly upload to the PIC: SHT15 PIC precision temperature and humidity meter - hex

Bill Of Materials
 Resistors R1 100 Ohm variable resistor R2 10 KOhm variable resistor R3 330 Ohm 1/4Watt 5% resistor R4 1 KOhm 1/4Watt 5% resistor ICs IC1 PIC 16F631 Microcontroller IC2 SHT15 Humidity and Temperature Sensor Misc LCD1 LCD 20x4 Character LCD w/ HD44780U1 controller  LED1 LED 3mm red Relative pages
• High accuracy temperature meter
• Low cost medium accuracy PIC temperature meter
• Learning PICs @ PCB Heaven On-Line Book
• Learn about the most popular PC Cooling methods
• Peltier coolers (TEC) theory of operation

 Name  Email (shall not be published)  Website Notify me of new posts via emailWrite your comments below:BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.  HOT in heaven!  NEW in heaven! New Theory: AC electric motor working principle