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 SHT15 sensor
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 °C, 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
A sample screenshot of the 20x4 LCD
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 = ValREAD2 x ValREAD2 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 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:
sir. i did try to simulate these in proteus but there was no display in the LCD. What could be the problem? I was hoping you could help me on this.. I intend to use this for my my little incubator so I could monitor the temp and the humidity. Would it be too much to ask if you can add a code that will trigger the relay on if the temp is 36.5 and also trigger the relay off if the temp is 37.5?
@Jason this circuit is only to demonstrate how can someone interface an SHT. A complete project requires much more coding for the PIC. The answer to your question is that you need to re-write the software for the PIC to do so.
@karla the board i used may be discontinued, i am not sure. I suppose that the board you sent me will work as well, as the sensor is the same. Regarding the capacitor, as i see, there is one SMD capacitor on the left side of the board as shown in the picture.
so..i only have to follow the schematic? and...where did u buy the sensor..??cause u put like in a breakout board and i cant not find that kind of breakout. i found another that dont have the capacitor that is in yours,does it affect? do u have a special suggestion about this proyect?a detail?
i found this : https://02f9a18.netsolstores.com/cart.aspx
thanks for answering.
@karla whenever there is a capacitor in a photo that does not exist in the schematic, this is a smoothing capacitor for the power supply. The are connected in parallel to the supply voltage. The electrolytic capacitors are always 1uF and the ceramic (or other) is 0.1uF. It is up to you to decide if you will use a capacitor or not, and how many you will put. Depends on your supply voltage quality.
i made these myself. there is an excellent document here:
Eagle library is the most difficult to use. I do not know why they did it that stiff. It is such a nice piece of software, and yet copying library footprints is a job for pros. But you can make new parts from a scratch quite easily. In my plans is to publish a PCB Heaven eagle lib with all the parts that i have used over time.
Your PIC Precision Thermometer and Humidity meter using the SHT15 , is very nice.Please include it, Set temp. option ,so that it can be use as a temperature controller for Egg incubator,and it can control Heater and Fan. I am waiting for your more Projects.
thank you for answering my question.
if anyone can write it in the C language that will be very thanksfull
(my english is not so good) but I will serach the internet and I think that will laso certainly help.