SHT15 Humidity and Temperature Sensor

SHT15The first sensor I wrote a driver for on my new Arduino board was the SHT15. At this time both of these products are widely available at many internet stores and are relatively cheap ($30-$40 range). I’m very happy with the results I’ve gotten. It took me just a few hours to get everything working and it should take you even less time if you leverage the code below.

Below is the circuit diagram I have and a picture of the actual hardware. As you can see it’s extremely simple with just 4 wires needed for attaching the SHT15 to the Arduino board. I power the Arduino board off a USB port on my PC and I power the SHT15 from my Arduino board. Since both parts are very low power this works fine.

Circuit Diagram

Arduino Sht15

Here is a link to the code I wrote which has nice formating. Below is the identical code, but the formating might not be as nice for copying and pasting. To use this code you need to hook up your Arduino board to your PC and connect with HyperTermial or a similar tool that lets you communicate to your Arduino board. Once connected you just press “h” to take a humidity reading or “t” to take a temperature reading.

// Maurice Ribble 
// 4-3-2008
// http://www.glacialwanderer.com/hobbyrobotics

// This code tests the SHT15 on the Arduino board.
// This app assumes your data pin is pin 10 and your your clock pin is pin 11.
// To run this app just attach HyperTerminal (or similar serial communications tool)
// to your Arduino board at 9600 bits per second.  I also needed te set the
// flow control to none or I couldn't send commands to my Arduino board via HyperTerminal.
// Then press the 't' key to take a temperature reading or the 'h' key to take a
// humidity reading.

// These are commands we need to send to HSHT15 to control it
int gTempCmd  = 0b00000011;
int gHumidCmd = 0b00000101;
  
int shiftIn(int dataPin, int clockPin, int numBits)
{
   int ret = 0;
   int i;

   for (i=0; i 0)
  {
      cmd = Serial.read();
      
      switch (cmd)
      {
      case 't':  //Read Temperature
         {
           int val;
           int temp;
           
           sendCommandSHT(gTempCmd, theDataPin, theClockPin);
           waitForResultSHT(theDataPin);
           val = getData16SHT(theDataPin, theClockPin);
           skipCrcSHT(theDataPin, theClockPin);
           Serial.print("Temp is:");
           Serial.print(val, HEX);
           temp = -40.0 + 0.018 * (float)val;
           Serial.print("  ");
           Serial.println(temp, DEC);         
           break;
         }
      case 'h': //Read Humidity
         {
           int val;
           int humid;
           
           sendCommandSHT(gHumidCmd, theDataPin, theClockPin);
           waitForResultSHT(theDataPin);
           val = getData16SHT(theDataPin, theClockPin);
           skipCrcSHT(theDataPin, theClockPin);
           Serial.print("Humidity is:");
           Serial.print(val, HEX);
           humid = -4.0 + 0.0405 * val + -0.0000028 * val * val;
           Serial.print("  ");
           Serial.println(humid, DEC);
           break; 
         }
      default:
         {
           Serial.println("You pressed something else");
         }
      }
   }
}

Here is a page with more details about the SHT15.

23 Comments

  1. EspressoBob said,

    June 20, 2008 @ 1:57 pm

    I’m enjoying your site very much! I noticed that the code for this project is kind of incomplete, the web example is missing functions (sendCommandSHT, etc) and the “Here is a link to the code” link isn’t to this code at all! It doesn’t take “t” or “h” as inputs.

    I like learning by reading code examples and would love to see the full deal.

    Thanks,
    Bob

  2. Glacial Wanderer said,

    June 22, 2008 @ 7:57 pm

    I can’t figure out why my blog isn’t displaying all the code on this page, but I did update the linked code to be correct. You please check out the link to the code for the full correct code.

  3. Chief Robot said,

    June 25, 2008 @ 6:58 pm

    Some great ideas here. I’m looking into using a temperature reading to control either a small fan or a small motor to open a window. Have you ever controlled anything based on temperature with the arduino and the SHT15 Sensor?
    Thanks

  4. Glacial Wanderer said,

    June 25, 2008 @ 9:33 pm

    It is easy to control something based on the SHT16 Sensor. For instance all you would need to to to turn on an LED would be to look for a certain temperature in the code and then set a pin high when that value is reached. Turning on a fan or small motor would probably require a small extra circuit to handle the extra power. There is an article about using high powered relays here: http://www.glacialwanderer.com/hobbyrobotics/?p=9

  5. swkim789 said,

    June 28, 2008 @ 4:45 am

    Thank you, Maurice.

    I found your codes in Arduino sites. This works perfect for me.

    Since I am new to this electronics or programming world, it is taking quite long to make my modifications for the change of display digits of temperature.
    I am not sure whether the SHT15 allows me to read 1/10the of a degree in Celcius or not. I will appreciate it if you could shed me some light on this issue of reading one more digit, for example, 22.5 deg or 23.1 deg.
    Main interest of temperature range, for me, would be 4 to 50 degree Celcius.

    Ciao,

    Bryan Kim

  6. Glacial Wanderer said,

    June 29, 2008 @ 7:42 pm

    If you look at the hardware spec for the SHT15 that I link to in my article above you will see that this device is only accurate to +-0.5 Celsius. So while you could have the software guess to the nearest 1/10th the hardware isn’t accurate to that degree.

    Also if you look at the hardware spec you will see they give equations for converting to Celsius or Fahrenheit. Figuring this how isn’t hard to code and I would recommend looking at hardware specs before asking questions like this. That said since I looked this up in the spec I can save you the work by saying all you need to do is replace this code:

    temp = -40.0 + 0.018 * (float)val;

    with this code:

    temp = -40.0 + 0.01 * (float)val;

  7. swkim789 said,

    June 30, 2008 @ 4:28 am

    Many thanks, GlacialWanderer.

    This is a really big help to me.

    I should have consulted the specification sheet beforehand.

    Your code works perfect for my project.

    Thank you again.

  8. Hoopstar said,

    January 8, 2009 @ 6:32 pm

    I am getting the following error when I compile the above (after cutting and pasting it):

    In function ‘int shiftIn(int, int, int)’:
    error: ‘ack’ was not declared in this scope In function ‘void loop()’:

    Any ideas??

    Hoops

  9. Hoopstar said,

    January 8, 2009 @ 6:34 pm

    Bah.. ignore me ๐Ÿ™‚

    Found your link to the properly formatted code and it works a treat – cheers..!!

  10. joe said,

    January 10, 2009 @ 12:46 pm

    There is a bug in this code that I found after using the SHT15 with a long wire to the temperature sensor… every time you set pinMode(dataPin,INPUT) you must also turn on the pull-up resistors with digitalWrite(dataPin,HIGH). The SHT15 needs the pullup resistor because it pulls the line down to indicate a zero, rather than pulling it up.
    So if anybody’s having weird problems (I wasn’t getting the 8 LSB of temp or humidity), do this.

  11. swkim789 said,

    May 13, 2009 @ 11:04 pm

    Hi,

    Many thanks, glacialwanderer!

    Would it be possible to have both SHT15 and RTC ds1307 connected to the Arduino and read in the time stamp data, temperature, and humidity?

    For example, mm:second, date, degree celcius, R.H. once every 10 second.

    Thanks for your interest in this regard.

  12. Jonathan Oxer said,

    August 5, 2009 @ 5:50 am

    Maurice’s work on the SHT15 has now been incorporated into an Arduino library to make it really easy to communicate with them from your projects. The library is available at http://github.com/practicalarduino/SHT1x/

  13. Dan said,

    December 1, 2009 @ 10:12 am

    Thank you glacialwanderer. I got an Arduino starter pack and am starting to find how interesting these electronics are.

    Regards, DH

  14. Winky, an arduino-based temperature logger: project plan | eval.nu blog said,

    January 5, 2010 @ 7:10 pm

    […] after a quick WWW search, I found both wiring shemes and a library for communication with the SHT15. The hard part turned out to be getting the code […]

  15. antoine said,

    May 18, 2010 @ 1:24 pm

    Many thanks Glacialwanderer.

    I got my new Arduino board and a HS1101 temperature and humidity module from :

    http://cgi.ebay.ca/HS1101-Temperature-Relative-Humidity-Sensor-
    Module_W0QQitemZ250620359526QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item3a5a233366

    And I’m wandering if the wiring sheme and code will be the same as the one you wrote, except for the calibration process (wich I suppose is linear).

    OTOH, can you elaborate a little bit on the SPI communication involved in your piece of code.

    regards,

    Antoine

  16. Jacob said,

    June 26, 2010 @ 10:00 am

    This is strange, this code works fine and yields correct answers, but the library on Github for the SHT15 is returning falls values.

  17. electro said,

    August 21, 2010 @ 7:26 am

    can i use this code with SHT11 directly without ant change ??

  18. Mike said,

    November 9, 2010 @ 10:58 am

    Jacob, I am having the same issue. Have you had any luck with the Github library?

  19. aziz said,

    December 4, 2010 @ 6:05 am

    hello
    I’m not found code of fonction : shiftOut(dataPin, clockPin, MSBFIRST, command);

  20. jorge said,

    December 25, 2010 @ 6:17 am

    Dear,

    Iร‚ยดm using 021 version, when I compile occurs this error :

    for (i=0; i 0)

    sht15:21: error: expected `;’ before numeric constant

    Please help-me

    Best Regards

  21. Chris said,

    January 17, 2011 @ 8:41 pm

    I have the code working but I think the readings might be off… I am getting -40C and -40F in a room that is 73F…. Any suggestions? I am using the downloaded library.

    -Chris

  22. Avi said,

    April 25, 2011 @ 6:49 am

    @ jorge

    Look to your code =)

    The “missing token” is between the “i” and the “0”, it must be like this:

    for (i=0; i; 0)

    @Glacial Wanderer
    Very helpfull this one! I’m working with an SHT15 and also with an RTC… using your code on the other one too! Man, you rock ๐Ÿ˜‰

  23. Sensoreihin tutustumista « ramitahtinen said,

    April 3, 2012 @ 3:34 am

    […] http://www.glacialwanderer.com/hobbyrobotics/?p=5 Share this:TwitterFacebookLike this:LikeBe the first to like this post. […]

RSS feed for comments on this post