Go Down

Topic: Calculating absolute humidity (Read 1 time) previous topic - next topic

sx3000

Hello world,

I'm working on a small project where I'm measuring temperature and humidity in my garret/boxroom and then transmit the data to a KNX based home automation system.
I'm using an Arduino Pro Mini and the Adafruit BME280.

I'm sucessfully reading out data and transmitting the raw values to the bus,

But now, I want the arduino to evaluate the values and calculate the absolute humidity.
The board is up and running and I can't really use it for testing, because it's logging so I'm asking here if I'm doing things right here or if I need to tweak this code?

This project is my very first arduino project ever, so I'm a real noob actually :) Even with the coding part.

Code: [Select]
if (bme.getTemperature_C() < -10) {
  Serial.print(2,2 * (bme.getHumidity()/100); serial.print("g/m3);
}
Else if (bme.getTemperature_C() > -10 and bme.getTemperature_C() < -8) {
  Serial.print(2,5 * (bme.getHumidity()/100); serial.print("g/m3);
}
Else if (bme.getTemperature_C() > -8 and bme.getTemperature_C() < -6) {
  Serial.print(3 * (bme.getHumidity()/100); serial.print("g/m3);
}
Else {
serial.print("Can't calculate Absolute humidity")
}



jremington

#1
Aug 28, 2016, 12:20 am Last Edit: Aug 28, 2016, 12:21 am by jremington
You can practice writing code without needing access to the sensor.

That fragment has many syntax errors and won't compile.

1. Floating point numbers cannot contain a comma.
2. Literal strings (character arrays) must be enclosed in double quotes.
3. Observe character case. Serial.print is not the same as serial.print
4. Balance parentheses.

allanhurst

#2
Aug 28, 2016, 12:49 am Last Edit: Aug 28, 2016, 01:05 am by allanhurst
I recently bought a BME280, and it's a wonderful gadget.

But mine only tells me atmospheric pressure and temperature - I don't see how you can get humidity from that...

regards

Allan.

DaveEvans

But now, I want the arduino to evaluate the values and calculate the absolute humidity.
Formulas for converting relative humidity to absolute humidity are usually considerably more complex than your snippet.  Where did you get that?

Did you try Google?  This was the second hit on a search for absolute humidity equation.

Suggest double-checking your results with a psychometric chart.


sx3000

#4
Aug 28, 2016, 09:19 am Last Edit: Aug 28, 2016, 09:29 am by sx3000
Good morning guys! (9 AM in Sweden).

@DaveEvans, yes I tried to google and stumbled over this chart which is showing how much water in g/m3 air can contain at maximum at a certain temperature and multiply it with the measured RH.
This might not be the most scientific way to calculate, but maybe it's accurate enough to keep an eye on the levels in the garret/boxroom?
The chart I'm using can be found here:
http://www.lfs-web.se/fukt-temperatur.gif

@allanhurst, mine is Adafruit, and reading out humidity was described in the library and example code provided from Adafruit. But I'm using the Cactus library now, because it allow me set temperature offset.

@Jreminton, thanks for your input I will a look at the code and see if I understand you.
Regarding #1, it is okay to use 2.5 (while 2,5 is not okay)?
Could you please give an example of #2, I'm not I followed you there.

Here comes a small rev of the code. Found the verify/compile option :D
Code: [Select]
if (bme.getTemperature_C() < -10) {
  Serial.print(2.2 * (bme.getHumidity()/100)); Serial.print("g/m3");
}
else if (bme.getTemperature_C() > -10 and bme.getTemperature_C() < -8) {
  Serial.print(2.5 * (bme.getHumidity()/100)); Serial.print("g/m3");
}
else if (bme.getTemperature_C() > -8 and bme.getTemperature_C() < -6) {
  Serial.print(3 * (bme.getHumidity()/100)); Serial.print("g/m3");
}
else {
Serial.print("Can't calculate Absolute humidity");
}


Thanks!

sx3000

#5
Aug 28, 2016, 10:53 am Last Edit: Aug 28, 2016, 12:37 pm by sx3000
Okay, so I came to the conclusion that using the chart and IF strings, this will generate massive amount of code. Instead I will do the calulation on my own and I've took a look at DaveEvans link.
But I'm doing something seriously wrong with the code, and I can't figure out what I'm doing wrong, but I do get errors.

Here's the code:
Code: [Select]
int BaseLog = 2.71828;
int Temperature = bme.getTemperature_C();
int Humidity = bme.getHumidity();
int AbsoluteHumidity = (6.112 * BaseLog ^ ((17.67 * Temperature)/(Temperature + 243.5)) * Humidity * 2.1674) / (273.15 + Temperature);
Serial.print(AbsoluteHumidity);


This generates this error code while verifying;
Code: [Select]
exit status 1
invalid operands of types 'double' and 'double' to binary 'operator^'



edit
Managed to use the pow() and get it to verify/compile. :) Wow, this is fun!!
Code: [Select]
int BaseLog = 2.71828;
int Temperature = bme.getTemperature_C();
int Humidity = bme.getHumidity();
int AbsoluteHumidity = (6.112 * pow(BaseLog,((17.67 * Temperature)/(Temperature + 243.5))) * Humidity * 2.1674) / (273.15 + Temperature);
Serial.print(AbsoluteHumidity);


edit #3
Realized that int don't give decimals, so I made a small adjustment by changing them to float.
Code: [Select]
float Temperature = bme.getTemperature_C();
float Humidity = bme.getHumidity();
float AbsoluteHumidity = (6.112 * pow(2.71828,((17.67 * Temperature)/(Temperature + 243.5))) * Humidity * 2.1674) / (273.15 + Temperature);
Serial.print(AbsoluteHumidity); Serial.print("\t"); Serial.print(Temperature); Serial.print("\t"); Serial.println(Humidity); Serial.print("\t"); Serial.println(bme.getPressure_MB());

DaveEvans

#6
Aug 28, 2016, 07:38 pm Last Edit: Aug 29, 2016, 02:15 am by DaveEvans
stumbled over this chart which is showing how much water in g/m3 air can contain at maximum at a certain temperature and multiply it with the measured RH.
This might not be the most scientific way to calculate, but maybe it's accurate enough to keep an eye on the levels in the garret/boxroom?
Well, that sounds like a reasonable approximation, but only you can know if it is accurate enough.  It would be easy enough to check.

Okay, so I came to the conclusion that using the chart and IF strings, this will generate massive amount of code.
A "massive amount of code" compared to the code for the rather complex formula?  Does the amount of code really matter?  It's just cut/paste/change a number.  Are you running out of memory?

Regarding the approximate method:

Do you need to do the entire table (from -10 to +30)?  It might be simpler if you use a lookup table.

Or, if you want to stay with the if/else if approach, a cleaner way than what you've been doing (IMHO) would be to use the if/else if statement only to assign the multipliers to a variable and then do the calculation and printing after that statement.

Or, perhaps even simpler yet, fit a curve through the data of the table (in the range you want to use), and dispense with the if/else ifs ('course, that would be an approximation to an approximation... :) )  For example, a straight line (y=mx+b) might be just fine for a small temperature range.  A polynomial with more terms might fit a wider range.


dwightthinker

Just an off the wall way of measuring absolute amount of water vapor.
If you know the temperature and the barometric pressure, one can split
one of those ping sensors to measure the velocity of sound.
(transmitter and receiver at ends of a tube )
Knowing that one can calculate, from the change in density, the ratio
of water vapor to air. The velocity of sound is directly related to the
density. Density is related to the temperature and pressure.  ;)
Dwight

jremington

#8
Sep 02, 2016, 04:19 am Last Edit: Sep 02, 2016, 04:26 am by jremington
In fact for dry air the velocity of sound depends strongly on the temperature , and not significantly on the pressure or (as many believe) the altitude.

Humidity has a tiny effect (much less than 1% change in velocity from 0 to 100% saturation) due to the change in the average mass of the "air molecules" and would probably not be measurable using an Arduino and ultrasonic transducers.

dwightthinker

It seems Remington is right. Not much good there.
There is an interesting web page on the subject:

http://www.sengpielaudio.com/calculator-airpressure.htm

It does seem that the humidity does have a significant effect
on the loss of amplitude of sound over some distance.
There is a chart showing significant loss of 10KHz over 30 meters
One wonders about higher frequencies, say 32KHz or even 100KHz.
There is a knee in the curve at lower humidities. That would
make an ambiguous reading at lower humidity.
Interesting.
Dwight

MarkT

In fact for dry air the velocity of sound depends strongly on the temperature , and not significantly on the pressure or (as many believe) the altitude.

Humidity has a tiny effect (much less than 1% change in velocity from 0 to 100% saturation) due to the change in the average mass of the "air molecules" and would probably not be measurable using an Arduino and ultrasonic transducers.
And indoors air you are breathing will have an increasing and unknown amount of CO2 replacing the O2 and
reducing the speed of sound, which might mask the signal from H2O which increases the speed.

Using relative humidity sensor and temperature is limited by the poor accuracy of polymer relative
humidity sensor, but I think the precise methods are things like IR spectroscopy which are neither
simple or cheap.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

GeeksTips

Isn't the DHT22 Temperature and Humidity a better option? I remember that the Arduino library has already a method for absolute humidity calculation and hum index also, or maybe i'm wrong ...
Author at GeeksTips.com

MarkT

In fact for dry air the velocity of sound depends strongly on the temperature , and not significantly on the pressure or (as many believe) the altitude.

Humidity has a tiny effect (much less than 1% change in velocity from 0 to 100% saturation) due to the change in the average mass of the "air molecules" and would probably not be measurable using an Arduino and ultrasonic transducers.
It would be best measured by tracking the resonant frequency of something like an organ tube,
since frequency is easy to measure - but you would then have to use an Arduino that has a quartz
crystal as system clock, not a ceramic resonator.  And accurately measure the temperature of the actual
air in the tube.  And you might have to account for CO2 if this was in a confined area with humans
breathing nearby.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Eheran

Since the dewpoint is directly proportional to the water content, this formula might get you somewhere:

dew = 243.04 * (log(relhumidity / 100.0) + ((17.625 * temperature) / (243.04 + temperature)))   / (17.625 - log(relhumidity / 100.0) - ((17.625 * temperature) / (243.04 + temperature)));


Everything in °C or hPa.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy