Shop OBEX P1 Docs P2 Docs Learn Events
SHT11 Sensor: Incorrect Readings, Calibration? — Parallax Forums

SHT11 Sensor: Incorrect Readings, Calibration?

fmcfmc Posts: 5
edited 2013-02-11 15:30 in Accessories
I am using the SHT11 Sensor with Wiring/Arduino and getting temperature readings of -40 C, -40 F and -4.5% humidity in a room that is not colder freezing cold.

I am curious if anyone recognizes this as a clear-cut problem on my end.
Very grateful for any ideas.

Thanks

FM

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-02-06 00:10
    Can you post your code?
  • fmcfmc Posts: 5
    edited 2013-02-06 00:15
    Of course, sorry it is below...

    And these are the connections on the board:
    Pin 1 SHT11 ---> pin 10 on Arduino / "dataPin"
    Pin 3 SHT11 --->Pin 11 on Arduino / "clockPin"
    Pin 4 SHT11 --> Ground on Arduino
    Pin 8 SHT11 ---> 5v Arduino (also tried 3.3V)

    Thank you. Tell me I am an idiot, tell me anything...
    ---

    /**
    * ReadSHT1xValues
    *
    * Read temperature and humidity values from an SHT1x-series (SHT10,
    * SHT11, SHT15) sensor.
    *
    * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
    * www.practicalarduino.com
    */


    #include <SHT1x.h>


    // Specify data and clock connections and instantiate SHT1x object
    #define dataPin 10
    #define clockPin 11
    SHT1x sht1x(dataPin, clockPin);


    void setup()
    {
    Serial.begin(38400); // Open serial connection to report values to host
    Serial.println("Starting up");
    }


    void loop()
    {
    float temp_c;
    float temp_f;
    float humidity;
    float humidityOffset = 40;
    float tempOffset = 112;


    // Read values from the sensor
    temp
    _c = sht1x.readTemperatureC() + tempOffset;
    temp_f = sht1x.readTemperatureF() + tempOffset;
    humidity = sht1x.readHumidity() + humidityOffset;


    // Print the values to the serial port
    Serial.print("Temperature: ");
    Serial.print(temp_c, DEC);
    Serial.print("C / ");
    Serial.print(temp_f, DEC);
    Serial.print("F. Humidity: ");
    Serial.print(humidity);
    Serial.println("%");


    delay(2000);
    }
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2013-02-06 01:17
    I don't know C but two things look odd in your code:
    1) do you need "sht1x" repeated in your line to initiate the object?
    2) why is the "temp_c" reading line split into two lines? Is your code that way?

    Almost all of my errors with Sensirion devices are crazy readings like yours and it is because I swapped thedata and clock lines. Are you using Parallax's SHT11 module?
  • fmcfmc Posts: 5
    edited 2013-02-06 07:31
    Thank you so much -- the weird space in my code is gone but was not the problem. Sorry
    I don't know C but two things look odd in your code:
    1) do you need "sht1x" repeated in your line to initiate the object?
    --
    Almost all of my errors with Sensirion devices are crazy readings like yours and it is because I swapped thedata and clock lines. Are you using Parallax's SHT11 module?

    Do mean that i should remove something in here?

    SHT1x sht1x(dataPin, clockPin);

    Yes....I have SHST11 the Sensirion -- I have tried swapping the clock and data lines too. Should I be moving onto a different part of the breadboard maybe or trying different digital pins on my Uno? I seem to get consistent readings even when wildly changing the way things are routed to Uno.

    I also just discovered I have this problem with the [TMP36] temp sensor. If two sensors are wildly off and I am following instruction manuals to the T maybe I need to try another Uno?


  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-02-06 08:44
    Do you have a pullup resistor on the SHT11 data line, or else is it included on whatever module you are using? Less important, but there should also be a pulldown resistor on the clock line.

    The device driver is in the sht1x.read.... functions, but if you have copied those verbatim from the article, they are unlikely to be the problem.
  • fmcfmc Posts: 5
    edited 2013-02-06 08:55
    Hi - so I literally just restarted Wiring and now I am getting perfectly accurate readings. I had already tried restarting multiple times to no avail. This is actually unsettling....

    The data sheet says the "The 4.7 kΩ pull-down resistor on the clock is optional but may be required if your application experiences sensor lock-up. "

    I'm an idiot -- do these wacky negative readings = sensor lock up?


    It also has 330 Ω 4.7 kΩ on the data line and says "The module includes a data-line pull-up"

    Thank you for all your help and ideas...I'm still confused by this moody sensor.
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2013-02-06 12:58
    They can be moody at times with noisy wiring, etc. I have a little more detail on my site regarding the pullup/pulldown add-ons. http://www.aestheticacoustics.com/SHT11_01.htm
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-02-06 14:22
    It sounds like you might have the Parallax module, #28018? It has the 330Ω series resistor plus 4.7kΩ pullup, and the clock pulldown is optional.

    The negative readings and the wackiness could in fact be accounted for by the lack of the pulldown on the clock line. The deal is that the clock line has to be low when the power is applied to the chip, and since it is an input and microprocessor pins start as inputs, there is a certain amount of chance as to how it comes up. It may be affected by how you wave your hand and other vaguaries. Only a small proportion of SHT11s seem to have the problem, but true to Murphy, the first one you try is bound to be one of the unlucky ones. The pulldown does not have to be 4.7k. It can be quite a high value, 100k or 1M, and will suffice to hold the pin low until µP pin is driven as a low output.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2013-02-06 14:52
    fmc wrote: »
    Thank you so much -- the weird space in my code is gone but was not the problem. Sorry

    Do mean that i should remove something in here?

    SHT1x sht1x(dataPin, clockPin);

    As others have noted the behavior is more likely to be related to the circuit. ALL sensors can be wacky and moody. The more sensitive it is, the more you have to be mindful how it's hooked up.

    On the above, you have it correct here. This line is just a shortcut constructor, and says to create an object called sht1x from the SHT1x class. To make your code more readable, you could change the object name from sht1x to something more descriptive. In Microsoftese it would be something like MySensor; camcelcased it would be mySensor. (Not that MySensor is descriptive, but it's just to give you the idea.)

    -- Gordon

  • mynegationmynegation Posts: 1
    edited 2013-02-06 19:17
    Just today I assembled SHT11 + Arduino and used the same source code. At first attempt I got nonsensical results (lower than -40 in C and F) and negative humidity. Turns out my data wire from pin 1 on SHT11 was attached to 9 on Arduino, not to 10, as source code specifies. Once I got wiring right everything started to work fine.

    Your wires may go to the right pins, but I would still check pin numbers first and quality of the wiring second.
  • GarethGareth Posts: 278
    edited 2013-02-07 02:56
    Edit :- (Duhhh... just read your reply above....sorry)
    Your code is OK..........

    I set up a "Due" with my SHT11 and your code gives this output.
    Starting up
    Temperature: 136.2200012207C / 187.6319885253F. Humidity: 63.88%
    Temperature: 136.2699890136C / 187.7219848632F. Humidity: 63.97%
    Temperature: 136.2299957275C / 187.5599975585F. Humidity: 63.73%


    The integrated code example in the IDE 18 (my old faithfull ide which never fails) (gives this which is correct):-
    Starting up
    Temperature: 23.7399978637C / 74.7859954833F. Humidity: 24.39%
    Temperature: 23.7299995422C / 74.7679977416F. Humidity: 24.39%
    Temperature: 23.7199974060C / 74.7859954833F. Humidity: 24.39%

    Your code is working...... taking into account your offset values!!......
    .... i guess either your sensor is zapped or wires are too long or maybe the data/clk pins are reversed......
    ... or the SHT library is suspect.....

    Hope this helps..... Gareth
  • fmcfmc Posts: 5
    edited 2013-02-11 15:30
    thank you all so much for your replies - my email did not notify me of these responses and i feel like a huge dip-- for not being grateful immediately for these kind responses. thank you!!!
Sign In or Register to comment.