Skip to main content

Ardunio and the SHT15

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.

Comments

Sun said…
Many thanks to you, Wayne

Since you posted this wonderful instruction, I finally have success in my SHT15 and Arduino setup for humidity measurement.

Thank you again,
Bryan.
Bad Andy said…
Any new updates on this project?

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!
Wayne said…
Sorry for the slow response. No news on this project as of yet. I received a large shipment of LED's and have been playing with them!

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!
Dmitri said…
Thank you for posting the code. You got me from developement to a working system in under 10 minutes.

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.
Nick Bilton said…
Hi Wayne - I've tried to download this code but it keeps spinning and doesn't seem to think the server exists, or it doesn't want to give it to me. Is there another link (or does someone else have it).

Thanks!

Nick.
Wayne said…
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
Wayne said…
Hello everyone. My webserver is now back up and running after a bit of a meltdown.
madeinoz said…
Thanks for the code, had it all up and running in a few minutes :)

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...
Midas said…
Hi Wayne,

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
Bigzwey said…
Can you post a data plot over time (perhaps 24 hours) that show a change in weather.
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.
Joe said…
Hi wayne,
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
Wayne said…
Yeah that does seem odd. I'll have to try it on my machine and see if I can reproduce your problem. I'll let you know what I find.
Joe said…
Hi wayne,
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!
Brian said…
After leaving my SHT71 on for more than a few minutes I find the temperature shoots up 18F/10C. Any idea whats happening here?
Joe said…
There's quite a bug in this code and I'm not sure why it works in the first place..... It reared its head when I used a longer wire to connect the SHT15 so it could be outside.

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..!
Hi Wayne.
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
Wayne said…
Hi 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
Cool, I'll try to figure it out and post a comment when some sensors and servos are up running.

Thanks,
Anders
DKHawk said…
This comment has been removed by the author.
sandy said…
This comment has been removed by the author.
mohsen said…
how can i modify it so it will work on lcd screen!
Wayne said…
I've moved the code to github so everyone can contribute. Been a long time coming I know!

Popular posts from this blog

Arduino LED MIDI Controller

It's been a while since I've made a post so I have decided that it was about time I did. This time I'll be talking about my Haunted House I made.

I started with the idea to take a Halloween decoration (small haunted house) and add some LEDs to it and make them blink. What I ended up with was a haunted house with 6 LEDs in it all controlled by MIDI. I used an Arduino to receive MIDI signals from my computer and turn on/off LED lights based on those signals.

Check out the video...




The "MIDI to Arduino Breakout Board" as I call it in the video I designed myself. I used various resources on MIDI around the web and came up with this schematic.




Digikey Part list:

2 x DIN5 - CP-2350-ND
2 x 6N138 - 516-1600-5-ND
1 x diode - 1N914B-ND
2 x 220 ohm resistor
1 x 270 ohm resistor


As you can see it isn't very complicated. The hardest part was finding in DIN5 part numbers at Digikey. The code on the other hand was a bit more complicated. The trick was to decode the …

First Ardunio Program

I have finally received my Arduino and have been able to write a few simple programs for it. For my thermostat program I am interested in being able to read several analog sensors (temperature and humidity). I also need to be able to poll specific sensor values from the computer using the serial interface so I can log their values in 5 minute intervals. I don't have all the electronic components yet to build my thermostat so I wanted to write up some test sketches. I based my sketches on a todbot blog entry that I found very useful.

I was originally going to use the C code that todbot wrote to test communication with the Arduino but I soon realized the limitations. What I ended up doing is using "screen" to open a terminal connection to the serial port so I could send and receive data to/from the Arduino. In the future I will have to write a daemon that will run on my linux box that will constantly poll the Arduino for data but thats another story. For now screen …