Shop OBEX P1 Docs P2 Docs Learn Events
HS1101 Humidity Sensor - C code — Parallax Forums

HS1101 Humidity Sensor - C code

Hi all,

I have this sensor and want to put him to work.
I have read the pdf that is included (bs2) yet I am unable to understand the connection diagram and the code after modification is not showing a proper value.
Has anyone tried to write a C code? Could someone give me a picture of a plan english and for a dummy like me diagram for connection?
Thank you very much!

Comments

  • If you are using Safari on an iMac, the connection diagram may be more or less blank. (Oddly enough, it is fine if I download to an iPad running Safari). Anyway, I have attached the diagram herewith. Sorry I scanned it upside down.

    There are examples of spin code and Ard**n* C code in the Parallax HS1101 documentation.

    Parallax, I have attached a copy of the pertinent page when I download (today) to my iMac. I have noticed the same problem on a lot of the older Nuts & Volts columns. Further info on request.

    tc
    1700 x 2338 - 1M
    1700 x 2338 - 1M
  • I have read this and doesnt work. Any other sensor that might to the trick?
  • johnproko,

    You forgot to mention that you are using a Propeller.

    Propeller C has an rc-time function that works similarly to the BS2 RCTIME command but the value that rc-time returns will not match the BS2 value since the Propeller is a lot faster than the BS2.

    You should be able to use the same circuit as the BS2 but the 10M resistor may need to be changed depending on what values rc_time gives. The Linear Approximation formula was developed only for the BS2 so you will need to collect data points to come up with a Propeller formula.
    For example running the shower for a while should close to 100% RH, while a very hot day in the desert will be near 0.
    To come up with an accurate formula you will need some kind of reference for what the "true" RH is.
    The more data points you have over a wider range, the better your approximation will be.
    Excel or a scientific calculator will do Linear Regression and give you the slope and intercept value that you can then place in the program to get correct results.

    This program builds in SimpleIDE but I don't have the sensor to test it.

    To get data points I suggest you increase the pause value so you can record the rc_time value and then place a print statement after rc_time so you can see the raw rc_time value.

    Good Luck!
    /*
      HS1101 Relative Humidity Sensor (#27920)
      Displays relative humidity in the Debug Terminal.
    
      Derived from Relative Humidity Reading.bs2
      TDecay = 2.4 • %RH + RHconstant (Linear approximation for BS2 only)
        %RH = (Tdecay - RHconstant) / 2.4
        %RH = [(Tdecay *10) - (RHconstant * 10)] / (2.4 * 10)
        *** Multiplying everything by 10 gets rid of the decimal point. ***
      Converted from PBASIC to C
    
      P7 - 200 ohm ----- HS1101 ----- Vss
                     |_ 10 M-Ohm _|
    
      y = mx + b ---> RH = m * (Time Delay) + b
        %RH = [(Tdecay * 10) - (RHintercept * 10)] / (RHslope * 10)
    */
    
    #include "simpletools.h"                      // Include simpletools
    
      // Declare Variables
      int decay;                                  // Decay Time - Varies as RH changes
      int humidity;                               // RH derived by Linear Approximation
    
      // Declare Relative Humidity (RH) Linear Approximation Constants
      const int RHintercept = 12169;              // Y-Intercept * 10 (BS2 value)
      const int RHslope = 24;                     // Slope * 10 (BS2 value)
    
    int main()                                    // main function
    {
      while(1)                                    // Endless loop
      {
        high(7);                                  // Set P7 high
        pause(1);                                 // Wait for circuit to charge
        decay = rc_time(7, 1);                    // Measure decay time on P7
        decay = decay * 10;                       // Multiply by 10 to remove decimal point from equation
        humidity = (decay - RHintercept) / RHslope;         // Integer Only Math
        print("Relative Humidity = %d %%\n", humidity);     // Display decay time
        pause(100);                               // Wait 1/10th of a second
      }
    }
    
  • Hi again,

    I am trying to get the done but nothing.
    All i get is 2709%. Currently using a BS2 because my propeller has no usb.
    I copied the code from the sensors page pdf.
    this is a photo of the wiring.
    Hope it makes sense.
    640 x 480 - 60K
  • I didn't have an HS1101, but I simulated it with silver mica caps adding up to 167 pF, +- 5%. I chose this value from the data sheet that has a curve of capacitance vs. humidity.

    I used a 10M +- 10% parallel resistor and a 220 ohm resistor in series with I/O 7.

    When I ran the program, I consistently got a "time" of just over 200. Multiplier by 10 yields just over 2000. Of course, when the correction factor of 12,000- odd is applied, the result goes negative and everything just gets worse from there on. And I got a humidity of 2300%, which is all wet.

    I *do* think there is something wrong with Parallax's program or diagram or something.
  • just like the photo I posted?
    I get a humidity from 2690 to 2718. I am trying to compare the result with the weather forecast.
    Until now I am more confused than I was.
  • Further more I found that connecting the sensor to a 50cm wire gets you a two digit result yet it is constanlty changing.
  • Attached is a graph showing capacitance vs humidity for the HS1101. You can see it varies from 163 pF for 0% humidity to 201 pF for 100%. Very small change in capacitance and very small capacitance all together. Adding 50 cm of wire would add enough capacitance to overwhelm what you are trying to measure.

    I measured RCTIME with values varying from 157 pF to 200 pF and got results varying from 1100 to 1370. I choose 1150 as corresponding to 0% humidity. So I plugged in 11500 for RHconstant and changed the divisor of 24 to 21 to get 100% to correspond to 200 pF.

    I have used the Am2303 / DHT22 to measure humidity. Here is a link to a note I wrote using it with propellor.
    Am2303 driver

    I haven't tried it with BS2; I do not know if you can measure 50 usec pulses with BS2.
    1362 x 931 - 565K
  • could you post a photo please showing the capacitor and wiring?
  • here is a photo. It looks pretty much like yours. This is 169 pF: 100 + 47 + 22
    3648 x 2736 - 2M
Sign In or Register to comment.