Using an HS1101 humidity sensor

I have an Arduino sampling temperature(DS18B20) in my house & sending it to a web server so I can graph it. I thought it would be nice to get humidity too, so I needed a sensor. Unfortunately, I went cheap and didn't research this enough: I bought a couple of Parallax HS1101 sensors. I was expecting to just read an analog pin, do a bit of computation & be done. Instead, it looks like I need to add a 555 and ancillary circuitry, which I could do, but do I have to? Writing the code is no issue - I wrote C for a living for a while, but the electronics? That's the dark side.

However, looking at the Parallax circuit for the stamp, it looks like this thing is just a variable capacitance device affected by humidity. Can I connect it's output to an analog pin with a large pulldown on it, set an analog pin to digital out, set it high, set it back to analog read and record the decay? What of the 220 ohm resistor the Parallax circuit uses between the arduino pin & the device? I sincerely don't know enough to decide whether this is feasible so advice or abuse would be equally welcome.

Maybe you could provide us with a direct link to the data sheet.

Have you tried searching for an Arduino library for a similar device?

Somewhere in Arduino land... somebody created some code to emulate the BASIC STAMP RCTIME function.

AHA found it: http://www.arduino.cc/en/Tutorial/RCtime

You can probably use this tutorial above and reference the SAMPLE PARALLAX code to get it working.

It clearly relies on STAMP processor speed (the RHCONSTANT value) so you will need to experiment... :frowning:

Perfect, got it working with that exact sketch. Thanks for your help.

COuld you please post the final sketch ? (HW & Software)

It really is the literal code given in the example sketch pwillard linked, with a longer delay in loop i.e.:

int sensorPin = 4;              // 220 or 1k resistor connected to this pin
long result = 0;
void setup()                    // run once, when the sketch starts
{
   Serial.begin(9600);
   Serial.println("start");      // a personal quirk 
}
void loop()                     // run over and over again
{

   Serial.println( RCtime(sensorPin) );
   delay(1000);

}

long RCtime(int sensPin){
   long result = 0;
   pinMode(sensPin, OUTPUT);       // make pin OUTPUT
   digitalWrite(sensPin, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
   delay(1);                       // wait a  ms to make sure cap is discharged

   pinMode(sensPin, INPUT);        // turn pin into an input and time till pin goes low
   digitalWrite(sensPin, LOW);     // turn pullups off - or it won't work
   while(digitalRead(sensPin)){    // wait for pin to go low
      result++;
   }

   return result;                   // report results   
}

The circuit diagram is attached.

Glad to help out.

I actually have one of these sensors as well... but I opted to use the SHT-11 instead.

I think we need to talk to mr WildBill... we need to urge you into using a freebie drawing tool or using IRFANVIEW to crop your hand sketches. Way to much blank space in that schematic, sir.

Trimmed it a little bit :wink: Also took the opportunity to correct it. That's a 1M resistor, not a 1K - d'oh!

So i have recently begun working with this sensor as well, however i have been having some trouble getting readings from outside the house to make any sense. Have you guys have good results? If anyone who has got this to work has any tips i'd love to hear them!

Basically i built the 555 timer circuit as indicated in the data sheet HS1101 Datasheet pdf - RELATIVE HUMIDITY SENSOR - Humirel and it works very well using the frequency counter library. After several different attempts of trying salt solution calibrations etc ... i calibrated it with a wetbulb/drybulb at approx 87% ( bathroom after a shower with no exhaust fan) and 28% ( outlet of a dehumidifier ) and the readings seem to be very accurate and consistent. The problem is i tried it outside this morning, where I am it was below 0C and there was frost so the humidity should have been very high,(weather center said 85%) but the sensor read 32%!

So my question is does this sensor actually read RH like it claims, or absolute humidity? Does it need thermometer correction? Or maybe the temp compensation curve for the 555 is not proper? if thats the case i could just correct it with software ?

Eventually i'd like to use one of these sensors outside but so far i can only get good readings at 22C ...!

hello everyone
I want to use the HS1101 humidity sensor, and I do not know if I should use the ne555 or to connect directly to an Arduino analog input
thank you

Well, in my experience capacitative humidity sensors require extra calibration and fine tuning.

I currently have both DHT11 and HS1101 (actually a HTF3223 module), and I have the following readings at the moment. Both sensors are on my computer desk, temperature is 26C. DHT11: 27%, HTF3223: 45.16%. I'm using the interrupt-based frequency counting method for the latter.

Without a calibrated humidity meter, what are the choices to get these right?

hello and thank you ...
So I can directly connect the sensor Arduino

hello,
how to get results is given by Ardu-ion on a PC network
thank you.

While I was trying to figure the HS1101 out, I ordered a Honeywell sensor: Safety and Productivity Solutions | Honeywell. Yesterday, I decided to hook it up. It's very simple, 5V in, voltage pretty much in proportion to humidity out. So I stuck it on the breadboard, wrote a few lines of code and fired it up. It just worked. Curiously, I'm not elated, in fact I feel a little bit cheated; just worked? Where's the fun in that?

const float Vsupply=1024.0;
const int   analogHumidityPin = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
float Vout = analogRead(analogHumidityPin);
float RelativeHumidity=(Vout/Vsupply)*100.0;
Serial.print((int)Vout);
Serial.print(" ");
Serial.print(RelativeHumidity);
Serial.println("%");
delay(500);
}

Hey wildbill:

How does your HS1101 sensors results compare to Honeywell sensor HIH-4000?
Any input on this will help.

Thank you.

just worked? Where's the fun in that?

Once and a while in the future you will wish for such "luck" :wink:

The fun is now you can think of adding new functionalities, actions to be taken at certain humidity levels (motors valve, airco's etc) , logging the levels and analyse them day vs night (add an RTC!!) ... There is always fun around the corner !

(using UNO)
Got this circuit working with code below. Used a storebought humidity gauge to calibrate, according to Parallax datasheet, the function is linear. Could have tried to calibrate using the result++, but I found the micros() method gave me better results. Is this off base? i am a newb.

Regardless, using a 2M pull down resistor, I get spot on humidity readings using a script that averages mulitple readings of the capacitor decay time in microseconds and is calibrated using a slope of .1667 and offset of -67.00. -- The averaging gives much more consistent readings than one-off reads.

don't make readDelay too small or it will affect the sensor readings. An accurate read could take a few seconds if your sample size is large.

thoughts? i am sure this script could be tidied up a bit... would love feedback, I am just happy I am getting accurate reads!

int sensorPin1 = 4;

long result = 0;
unsigned long time1=0;
unsigned long time2=0;

long readingsPer=20.0;
long readDelay=200.0;

#define RH1(time) ((.1667*time)-67)

void setup() // run once, when the sketch starts
{

Serial.begin(9600);
Serial.println("start"); // a personal quirk
}
void loop() // run over and over again
{
long H=RH1(evalHumid(readingsPer, sensorPin1));
Serial.println("");
Serial.println(H);
Serial.println("
");
delay(1000);

}

long evalHumid(long samples, int sPin){
long avgtime=0;
for (int i=0;i<samples;i++){
RCtime(sPin);
avgtime+= decayTime(3);
}
avgtime=avgtime/samples;
return(avgtime);

}

long RCtime(int sensPin){
long result = 0;
pinMode(sensPin, OUTPUT); // make pin OUTPUT
digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged

pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensPin, LOW);// turn pullups off - or it won't work
decayTime(1);
while(digitalRead(sensPin)){ // wait for pin to go low
//result++;
}
decayTime(2);
delay(readDelay);
//return result; // report results
}

long decayTime(int input){
if (input==1){
time1=micros();
}
if (input==2 ){
time2=micros();
}
if (input==3){
return (time2-time1);
}
}

Hi there, I've been struggling with this sensor, I have used your code, but still I don't get the results done well. I'm comparing it to a SHT15 sensor.
My question is, how do you calculate the slope and the difference, in this case RH1(time) ((.1667*time)-67) ??
For example, for a 60% humidity, I get 242 as a reading. I have tried increasing the 67 to 247 to get the same results, but when I put it on a 75% humidity environment, the results goes to 108, which obviously is off the chart.

Please enlight my path!

Thanks
Greetings
Giovanni

gmorchio:
Hi there, I've been struggling with this sensor, I have used your code, but still I don't get the results done well....

Me too...

start
_____
226
_____
_____
225
_____
_____
224
_____

but... reading the device Documentation from here http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/27920-HS1101-v1.0.pdf seems that getting the RH is simple as:

TDecay= 2.4•%RH + RHconstant

			endTime=micros()-startTime;
			endTime=endTime*10;
			endTime=endTime-HS1101_RH_CONSTANT;
			endTime=(endTime)/24;

also in this way readings seems meaningless... may be my hs1101 is broken? What happens if polarity is inverted?

What happens if polarity is inverted

Hmm. I don't recall it having a polarity. It is essentially a "humidity" variable non polarized capacitor.