Go Down

Topic: Yet another Humidity and Temperature logger (Read 3200 times) previous topic - next topic

Anders 2009


Hi,
just a quick word from me to share my design and code for a setup I built over Christmas to measure relative humidity in our apartment.

Code, images and circuit documentation can be found here: https://github.com/aweijnitz/Hygrometer

Sample data from logging the output (with sub sequent sub sampling) can be viewed here: http://wohnung.se/arduino/hygrometer/data.html

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!

Cheers!

Anders 

Anders 2009


Ah!
Forgot.

Next, I hope to rig everything on the Data Logging shield from Adafruit to remove the need to use my laptop as data collector.
http://www.adafruit.com/products/1141

Anything I should think about?

Thanks!

Anders


robtillaart

Quote
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
Code: [Select]

  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
Code: [Select]
  byte tmp = (byte) rint(temp);
simpler
Code: [Select]
  byte tmp = (byte)(temp + 0.5);

Code: [Select]
byte t = (tmp - (tmp % 5))/5;
simpler
Code: [Select]
byte t = tmp /5;
integer division truncates

Code: [Select]
do { } while (lookupTable[tIndex][rIndex] > r && rIndex++ < 8);
can be
Code: [Select]
while (lookupTable[tIndex][rIndex] > r && rIndex++ < 8);

succes
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Anders 2009

Hey,
great advice! Thanks!

I too have been thinking about interpolating in 2d, but made it a priority to get all moving parts working together first.

Good points about the small stuff as well. Will work them into the next version, as I implement you 2d suggestion.

Many thanks!

Anders

robtillaart

You're welcome,

Can you tell anything about the sensors used?
And the source of the table of RH? link?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Anders 2009


Sure,
the URL to the lookup table is actually in the source code in the sketch, just by the lookup table itself. :-)
It's from the data sheet for the EFS-10 humidity sensor. Here: http://www.produktinfo.conrad.com/datenblaetter/150000-174999/156545-da-01-en-Feuchtesensor_EFS10.pdf

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.

Anders


robtillaart

Quote
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 - http://en.wikipedia.org/wiki/Bilinear_interpolation -
but the essence is in the first two lines and the picture at the top right.

Succes!

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Anders 2009


Success! :-)

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.

The new graphs are available on the same URL as before: http://wohnung.se/arduino/hygrometer/data.html

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!

Anders





Anders 2009


.... and there I jinxed it *sigh*

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.

Regardless, it works a lot better than before.

Anders


Anders 2009


on the other hand the analog hygrometer agrees on the new value.

*confused*

robtillaart

Good to hear the 2D interpolation is working. As I said it is not much more difficult than 1D interpolation if you get the idea.

Please post your new code, as the bump still appears it should be in the code somehow.
This can be (1) in the math/code itself or (2) in the table.



Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Could it be that water is condensing in the rH meter?
Or that the air was not moving?
When you opened the windows there was definitely more flow..

thinking...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Anders 2009

#12
Jan 06, 2013, 05:21 pm Last Edit: Jan 06, 2013, 05:41 pm by Anders 2009 Reason: 1
Thanks for coming back on it!

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 have time zone corrected the conversion tool and uploaded the latest data as illustration.
Same place: http://wohnung.se/arduino/hygrometer/data.html

Thanks again for all the help and friendly support!

Anders







Anders 2009


Quote
Please post your new code,


I pushed the latest code to github: https://github.com/aweijnitz/Hygrometer

robtillaart

Good to hear it works well,
BTW I quickly checked the table from the PDF and it matches the values in your code .

Fun that you can detect the humidity created by people so well.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up