For my ongoing thermostat project I require some sort of temperature and humidity sensor. Because I'm fairly new to all this I decided to get a 2 in 1 sensor from Robotshop called the SHT15. I went with the SHT15 because it had both a temperature and humidity sensor and uses a "digital 2-wire" interface. When I first purchased it I didn't realize that "digital 2-wire" didn't mean I2C, but that's another story.
In order to get the sensor to communicate with the Arduino I needed to write some custom code that manipulates the data and clock lines by pulling them high and low at the correct times. I haven't had any experience doing this before so it was a learning experience for me.
Connecting the SHT15 to the Arduino is pretty simple. The data and sck lines each goto a digital input/output on the Arduino and the VCC goes to +5V. Pretty simple. Here is a picture of my breadboard.

As you can see I had to solder on some breadboard wires onto the SHT15 breakout board. It's been a while since I've soldered so it was good practice. NOTE: You can decouple the power supply pings (VCC, GND) with a 100nF capacitor.
Onto the code! As I said before I used the C source code from the website to help me with getting all the timing right. After a few short hours of some frustration I was able to get it working. One thing I didn't get working was outputting the actual temperature/humidity values in human readable form. The numbers that the SHT15 returns require you to plug them into a formula before they will make sense to us. The formulas can be found in the SHT15 datasheet. There are a few functions that I have yet to implement such as the heater but it shouldn't be too difficult.
Here is my source code (now on GitHub): serial_temp_humidity.pde
Enjoy! Feel free to ask me any questions. I'm out.
In order to get the sensor to communicate with the Arduino I needed to write some custom code that manipulates the data and clock lines by pulling them high and low at the correct times. I haven't had any experience doing this before so it was a learning experience for me.
Connecting the SHT15 to the Arduino is pretty simple. The data and sck lines each goto a digital input/output on the Arduino and the VCC goes to +5V. Pretty simple. Here is a picture of my breadboard.
As you can see I had to solder on some breadboard wires onto the SHT15 breakout board. It's been a while since I've soldered so it was good practice. NOTE: You can decouple the power supply pings (VCC, GND) with a 100nF capacitor.
Onto the code! As I said before I used the C source code from the website to help me with getting all the timing right. After a few short hours of some frustration I was able to get it working. One thing I didn't get working was outputting the actual temperature/humidity values in human readable form. The numbers that the SHT15 returns require you to plug them into a formula before they will make sense to us. The formulas can be found in the SHT15 datasheet. There are a few functions that I have yet to implement such as the heater but it shouldn't be too difficult.
Here is my source code (now on GitHub): serial_temp_humidity.pde
Enjoy! Feel free to ask me any questions. I'm out.
Comments
Since you posted this wonderful instruction, I finally have success in my SHT15 and Arduino setup for humidity measurement.
Thank you again,
Bryan.
I'm working on a similar Arduino project using the SHT15 and thought I'd try your code before reinventing the same.. Unfortunately all I'm getting back on the serial line is this:
Starting Temperature/Humidity reading...
Response time = 2550
Temprature:254
Response time = 2550
Humidity:254
I've verified my circuit so now I'm looking in to adding debugging logging to the code. Any thoughts as to where I should start troubleshooting it?
Thanks for breaking the trail for me, good to know its been done before!
Because the response time is 2550 it looks like the SHT isn't pulling the data line low before the loop times out. I would concentrate my debugging efforts in the writeByteSHT function for this reason.
Perhaps you are having some problems with interference. You could try decoupling the power supply pins (VDD, GND) with a 100 nF capacitor. Also make sure you are not using data pins 0 or 1 on the Arduino. I've had odd results with that myself.
Hope that helps!
Re:getting a constant instead of actual reading: I had the same problem and found that 1) the connections on my sht75 needed to be redone as the resistance was too high across the wire (also had to shorten wire.
Thanks!
Nick.
Unfortunately my server that hosts these files is down at the moment. I'll update the links and post another comment when I get a temporary server set up. Sorry for the inconvenience.
Wayne
I've made some changes to print the values in human readable form for both Temperature (DegC) and Temperature Compensated Humidity.
// SHT15 Sensor Coefficients
const float C1=-4.0; // for 12 Bit
const float C2= 0.0405; // for 12 Bit
const float C3=-0.0000028; // for 12 Bit
const float D1=-40.0; // for 14 Bit @ 5V
const float D2=0.01; // for 14 Bit DEGC
const float T1=0.01; // for 14 Bit @ 5V
const float T2=0.00008; // for 14 Bit @ 5V
void serialPrintFloat( float f){
Serial.print((int)f);
Serial.print(".");
int temp = (f - (int)f) * 100;
Serial.println( abs(temp) );
}
void loop () {
delay(2000);
Serial.println("Starting Temperature/Humidity reading...");
int temp_raw = getTempSHT(); // get raw temperature value
Serial.print("Temperature(DEGC): ");
float temp_degc = (temp_raw * D2) + D1; // Unit Conversion - See datasheet
serialPrintFloat(temp_degc);
int rh_raw = getHumidSHT(); // get raw Humidity value
Serial.print("Humidity(%RH): ");
float rh_lin = C3 * rh_raw * rh_raw + C2 * rh_raw + C1; // Linear conversion
float rh_true = (temp_degc * (T1 + T2 * rh_raw) + rh_lin); // Temperature compensated RH
serialPrintFloat(rh_true);
}
Regards,
Stephen...
Great stuff, I had been struggling with the code until I found this, beautiful!
In my case, the SHT15 needs to be very far from the Arduino, over 50 meters. Have you, or anyone else any experience or suggestions on how to do it? I suppose decoupling would be essential but one end? both ends? Or is the whole thing even possible?
Regards,
Paul
I am especially interested to see if a rain event can me measured using the SHT15, in terms of a)start time, b) stop time AND especially c) inches of rain.
thanks for this code! it's (hopefully) going to save me a lot of work!
Anyway, I'm having a problem at the moment. I ran the sensor all night to get a night's worth of data to check it's working. Here's the graph I got:
http://img223.imageshack.us/my.php?image=picture1hx9.png
Doesn't look right, does it? It's almost as if a few of the least significant bits have disappeared.
Have you seen this before? Any ideas?
Thanks,
Joe
had a go at debugging, but couldn't find the issue. I wasn't getting the 8 LSB of temp. Since then have found some other code on the net that works for me, here:
http://www.glacialwanderer.com/hobbyrobotics
Amazingly, found this in his code. This is his reading function:
int shiftIn(int dataPin, int clockPin, int numBits)
{
int ret = 0;
int i;
for (i=0; i<numBits; ++i)
{
digitalWrite(clockPin, HIGH);
delay(10); // I don't know why I need this, but without it I don't get my 8 lsb of temp
ret = ret*2 + digitalRead(dataPin);
digitalWrite(clockPin, LOW);
}
return(ret);
}
So if you're still getting problems, try putting delays in there!
After every pinMode(dataPin,INPUT) line there needs to be a digitalWrite to turn on the pullup resistors on the input pin. Took me ages to figure that one out....
cant think why it works without them..!
Im pretty new to Arduino; actually I just got my first Duemilanove yesterday...
The reason why I got it, is a project in which I want to connect a humidity censor to a servomotor. Tell the servo to be at to different positions at for instance 20% and 60% humidity. Do you yhink the SHT15 would be the right censor to buy, or do you know if there is another cheaper censor that only measures humidity and not temp.?
Thanks, Anders
The SHT15 is the only temp/humidity sensor I have experience with so I dont really know of one that would be less expensive. I do know that the SHT15 is a great little sensor and I have had no problems with it at all. You will have to modify my source code a little bit to accurately detect humidity as my code only uses the temperature readings. This should all be detailed in the SHT15 manual. If you do have any problems with it I could try and help you out.
Good luck with your project. I'd be curious to hear how it goes.
Take care,
Wayne
Thanks,
Anders