Go Down

Topic: Sensirion Temp/Humidity sensor library help (Read 21337 times) previous topic - next topic


I think you are using arduino IDE 0016 or older.
And it's very likely that you didn't remove the Sensirion.o file after the modification.
Please remove it and re-verify.

The latest IDE 0017 fixed this kind of problem.
* Libraries are now compiled with the sketch, eliminating the delay when
 switching boards and the need to delete .o files when changing library
 source code.


Everything works fine now and "Yes" I used the Version 16.

Thanks fr your help: [smiley=dankk2.gif]


When you connect the SHT-xx to arduino via a short cable(about 10cm), the library works fine.
But if you hook up the sensor with very long cable, you will get corrupted data.
The reason is that, the default clock pulse width is too short for the long cable.

If you connect the Sensirion recommended resistors and capacitors this problem should be elminated.


Can someone post their working code..??


Hello, amigos míos

I suggest you going to a post in Spanish where you can find my code: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246400334

It's tested and works good. There are TWO parts of code, both are needed, just copy&paste together. There are several lines that are for another sensors, but there's no need to delete anything if you don't want to. It's not a library, it's just a set of functions, .. but who cares?



Can someone post their working code?

A working code library has already been published at http://github.com/practicalarduino/SHT1x/
Use the example provided.


Hi all! I have a problem with a SHT11 sensor. I tell you my configuration: arduino duemilanove, a 2x16 lcd display, a DS1307 (RTC) and a SHT11 sensor. What I want to do is write the time given by the RTC in the first row of the display and in the second row I want to write the temperature and the humidity collected by the SHT11 sensor.  I wrote few lines of code and I saw that the time shown in the display is not accurate, in fact every minute it skips 5 or 6 seconds. I think it happens because in the library that I'm using there are some delays(). I thought so because in another project I had the same problem and I solved it changing the delay() function with millis(). In this case the delay() is in the library, not in the script, how could I fix this problem? I post a simplified version of the script I'm working on, I hope someone can help me, I'm a newbie and please excuse me if I've made some mistakes when i wrote this post, I'm italian. Here comes the script:


  #include <WProgram.h>
  #include <Wire.h>
  #include <DS1307.h>
  #include <LiquidCrystal.h>
  #include <SHT1x.h>
  #define dataPin  12
  #define clockPin 13
  SHT1x sht1x(dataPin, clockPin);
  float temp_c;
  float humidity;
  LiquidCrystal lcd(2,3,4,5,6,7,8);
  int rtc[7];
  void setup()

  void loop()

  temp_c = sht1x.readTemperatureC();
  humidity = sht1x.readHumidity();
  lcd.setCursor(0,0); // 1st row display
  lcd.print(rtc[2]); // hours
  lcd.print(rtc[1]); // minutes
  lcd.print(rtc[0]); // seconds
  lcd.setCursor(0,1); // 2nd row display
  lcd.print(" U=");


You've got 2 things running, the RTC & the Senirion.
Comment one out (the SHT11) & then see if the RTC works.

Use a process of elimination.


If I comment the SHT11 code, the time runs well.


You should also run the SHT11 code on its own.

Did you use the "working code library" I mentioned above?.


Yes, I use that library and I've tried to follow the example sketch. On their own they work fine, the problem happens when I try to combine both scripts. By using the script posted above, I've seen that if I comment the delays in the SHT1x.cpp file included in the library, the problem of the seconds seems disappeared but the sensor doesn't return values. Any ideas to make SHT11 and RTC work together?


Oct 04, 2009, 03:01 am Last Edit: Oct 04, 2009, 07:41 am by novice Reason: 1
At least now you have determined that each work in isolation, but not together. I tend to think it's a conflict between timers used in both applications/tasks.

Sounds like you are familiar with C Code, so I'd suggest looking at the timer code in each & working out why they conflict.

I could have a similar problem soon, when I have to combine code for a DS18B20, LCD display, and SHT15 all into the same application, so I'd appreciate you looking more at your problem.

Edit: The DS18B20 & SHT15 code is working! - will add LCD stuff asap.


Unfortunately I'm not so good with programming, I don't know what I have to do to modify the library (and if this is the right way to solve the problem).


Hello everybody,

I'm not so good in electronic (and in English !!).

After some issue with my SHT11 and Arduino Duemilanove, I finally found a way to be successfull.

First of all, with my oscilloscope I see that clock pin have less voltage than data pin ?

It seems that built-in AVR pull-up resistance was enabled on my clock pin and not on my data pin (probably due to previous testing).

So, I have change contructor to disable it on both :

Code: [Select]

Sensirion::Sensirion(uint8_t data, uint8_t clock)
 // Pins for software SPI
 _pinData = data;
 _pinClock = clock;
 pinMode(_pinData, INPUT);           // set pin to input
 digitalWrite(_pinData, LOW);        // turn off pullup resistors
 pinMode(_pinClock, INPUT);          // set pin to input
 digitalWrite(_pinClock, LOW);       // turn off pullup resistors
 // set DDR for software SPI pins
 pinMode(_pinClock, OUTPUT);
 pinMode(_pinData, OUTPUT);

Is it make sense ?

After, I have see in this thread that we have to use 3.3v power instead of 5v. I have connected vdd on 3.3v pin. But in this case, the data pin
and clock pin continue to use 5v, no ?

Because, very often the measure function returned 1 (communication error), I have inserted a resistance (330 ohm) on clock and data pin to reduce voltage.

And now, all works fine (without pull-up resistance on data pin).

Code: [Select]

Result : 0
Temperature: 28.54 C, Humidity: 53.3 %, Dewpoint: 18.4 C
Result : 0
Temperature: 28.54 C, Humidity: 53.3 %, Dewpoint: 18.4 C
Result : 0
Temperature: 28.55 C, Humidity: 53.3 %, Dewpoint: 18.5 C
Result : 0
Temperature: 28.55 C, Humidity: 52.97 %, Dewpoint: 18.3 C
Result : 0
Temperature: 28.55 C, Humidity: 52.97 %, Dewpoint: 18.3 C
Result : 0
Temperature: 28.55 C, Humidity: 52.97 %, Dewpoint: 18.3 C
Result : 0
Temperature: 28.55 C, Humidity: 53.0 %, Dewpoint: 18.4 C
Result : 0
Temperature: 28.58 C, Humidity: 52.97 %, Dewpoint: 18.5 C

Is it make sense ?

Best regards,


Just a quick note to say thanks for the help posted here, especially tasasaki who cracked the resolution issue which had me foxed for quite some time  :)

I have this all working nicely now on a Seeeduino Stalker data logger and have posted a small write up along with the Arduino Sketch:


Go Up