Background
It is common to find apartments without proper ventilation in Germany (where I live). This is not even legal in Sweden (where I come from). Without proper ventilation, you face a whole range of issues with the indoor climate, bad air and particles is just a start, condense and mold is at the other end of the spectrum. This triggered the idea to let my next project be a hygrometer. That and a wish to build a nice balcony greenhouse this year.
Looking for input on approaches you find a whole lot of questions and discussions in this forum, but not so much solid information, so that's why I decided to post my project here. It far from perfect, but it is at least a working end-to-end circuit and sketch to look at and perhaps get inspired by.
Notes
I believe my algorithm to measure the relative humidity has some issues, but I haven't gotten to a point where I can say what and why. Just notice a few odd things and "jumps" in my data. Ultimately it might be down to the crude approach of using a lookup table and interpolation to come up with the value. Input more than welcome!
Another thing to note is the (unusual?) way the EFS-10 humidity sensor works. You have to drive it with a square wave and then the impedance of the sensor will vary with the relative humidity. Not the most straight forward thing to use, at least if you are a inexperienced like me. Still haven't found any good sources for dealing with such sensors. If you have any pointers, it would be very welcome.
Many thanks to MarkT who provided the crucial pointers and code snippets to get me on the right track!
I believe my algorithm to measure the relative humidity has some issues, but I haven't gotten to a point where I can say what and why. Just notice a few odd things and "jumps" in my data. Ultimately it might be down to the crude approach of using a lookup table and interpolation to come up with the value. Input more than welcome!
As the table is 2 dimensional you should interpolate in 2D - so both for temperature and humidity.
something like this
float a = (realTemperature - rounded temp from table index) / stepsize in table
float b = idem for hum.
rH1 = (1-a) * lut[t][h] + (a)* lut[t+1][h];
rH2 = (1-a) * lut[t][h+1] + (a)* lut[t+1][h+1];
rH = (1-b) * rH1 + (b)*rH2;
Small things
byte tmp = (byte) rint(temp);
simpler
byte tmp = (byte)(temp + 0.5);
byte t = (tmp - (tmp % 5))/5;
simpler
byte t = tmp /5;
integer division truncates
do { } while (lookupTable[tIndex][rIndex] > r && rIndex++ < 8);
can be
while (lookupTable[tIndex][rIndex] > r && rIndex++ < 8);
I got the sensor as a present and really don't know so much about it other than it being sold by Conrad.de. It is the first time I use it and I can't say it was very easy. I am not used to generating AC signals to drive a sensor and then having to work out the impendance of it from the (volt) value you get from analogRead() didn't make it easier. Now add 2d-interpolation to that and everything gets a little too complex for a beginner like myself.
The LM335 is a common and easy-to-use temperaure sensor in a three-pin transistor like package. Didn't give me any trouble at all and pretty much worked the first time I hooked it up.
I am trying to incorporate your suggestions now BTW. Will report back once I have it working, hopefully tonight.
the URL to the lookup table is actually in the source code in the sketch,
Oops missed that one
If the 2D interpolation is too hard please let me know so I can give it a try.
you must first check if the measurement is within the matrix (2D interpolation) or at its border (1D interpolation)
This will explain the math in detail - Bilinear interpolation - Wikipedia -
but the essence is in the first two lines and the picture at the top right.
I did some reading and some thinking to understand it on my own and came up with a slightly modified implementation from your code hint, but basically it is the same (2d interpolation).
Did a test run, including a big ventilation of the apartment (opening all windows) and kept a manual log from my reference setup (analog hygrometer and digital themometer) and it looks really good! The setup keeps within +/- 0.4C from the reference thermometer and a few % from what the analog hygrometer shows.
With the old approach, I would get strange bumps in the reading while ventilating and in the settling period following that. I guess because I would jump between temperature rows in the lookup table as the temperature dropped and rose again.
Thanks again for your patience and helpful advice!
Went back to upload the latest version of the data file (have it running) and then I see a sudden jump of almost 10% relative humidity!
Checkout the jump at 12:34 http://wohnung.se/arduino/hygrometer/data.html
This is 35min after I closed all windows and everything should be stable really.
Need to take a look at the debug printouts to see what is going on.
I think the whole thing works and I made a silly mistake while reading the results. I also learned something new about our indoor climate perhaps.
First:
I think the apparatus works. My reference, the analog meter, showed the same value and has continued to do so. That means my circuit and the analog meter either both work or have the same kind of strange issue (not likely).
Second: (my reading mistake)
I said 12:34, because that is what I read on the graph and at 12:34 everything was static and quiet. HOWEVER I didn't think about the time zone when writing my script to convert the timestamps to JSON data. The timestamp is CET and 12:34 is in reality 13:34. At 13:34 my wife came home after having run 15km in the Munich Winterlauf Series.
Needless to say the door to the stairwells was open for a while and she was wet and still perspired after having run in the wet weather.
We then closed the door and no windows where opened for a couple of hours. Two hours later (15:39 CET) we vented the flat again and the humidity dropped again.
I ended up on this thread because I had just come across a humidity sensor and was considering making a humidity/temperature monitor. The one I found was Honeywell HIH-4000-0019 (datasheet) which has a simple 3-pin arrangement of Vcc, GND and analog output which is linearly related to relative humidity. (I found it on sale on eBay). I notice that temperature compensation is a simple quadratic, rather than requiring 2D interpolation.
robtillaart:
now you have humidity and temp you can calc the dewpoint.
Wow! Thanks! That might prove useful actually, both in terms of tracking mold conditions and in the balcony greenhouse I hope to build in a month or two.