Wrong result but right formula

Hi Guys,

I have a Problem. I want to calculate the absolute Humidity from relative and Temperature.

I have the formula from the internet Berechnung von Taupunkt und relativer Feuchte. I tried it in Excel and with my Smartphone and with these two i got the right result.

But my Arduino UNO gives me 0,01. Thats wrong. I already tried it with clinch but i got the same (wrong) result.

Here is a part of my code.

float t = 20; // Temp in °C
  float rF = 50;  // Rel Feuchte
  float tK = 293.15; //Temp in K
  
  float sdd = 6.1078*exp((7.5*t)/(237.3+t)); //Sättigungsdampfdruck in hPa
  float dd = (rF/100)*sdd; //Dampfdruck in hPa
  float v = log10(dd/6.1078);
  float tD = (237.3*v)/(7.5-v);

  Serial.print(tD);
  Serial.print("\n");

  double aF;
  aF = exp(5)*18.016/8314.3*rF/100*6.1078*exp((7.5*t)/(237.3+t))/tK; // Absolute Feuchte g/m³

  Serial.print(aF);

the Calculate of tD is also wrong! what is my mistake ? :~

Hope you can help me. =(

for aF is thr right result aF = 8,66 and for tD = 50

Sorry for my english i am german :smiley:

Maybe you should consider using usigned floats, or even doubles instead

/Danjel

Thanks for your answer, but that dont work :frowning:

Maybe you should consider using usigned floats

Ever seen one?

On AVR Arduinos, float and double are both 32 bits.,

I went through and worked it outside of the Arduino and get
-1.50
006.
It appears that the Arduino is doing exactly what you tell it to.

:astonished:
Ok ...
well ... then i have to work on the formula.

an other question is
10^5 the same as exp(5) ?

10^5 the same as exp(5)

No, 10 XOR 5 is not the same as exp(5)

No I mean "Math" ^

like 10³
(³)

OK i got the problem.

I have to use pow(10,5) not exp(5)

XD

Thank you all for your help :slight_smile:

I have to use pow(10,5)

Keep in mind that pow() expects floats and returns a float. pow(10, 5) will not return 1000000.000000.

pow(10, 5) will not return 1000000

Thank goodness! :wink:

You describe tK as "temp in K", when it isn't. It is the difference between the C and K scales.

Actually 273 is the difference between the C and K scales.

And you have multiple appearances of the constant 237 in your code. Is this a typing error ?

Your floating point calculations can be seriously optimised. You need to be careful if you rely on
the multiplications and divisions being done in the "correct" order. I'd be inclined to put a lot
more parentheses in those expressions.

  float t = 20; // Temp in °C
  float rF = 50;  // Rel Feuchte
  float tK = 293.15; //Temp in K

This coding is not a good idea. You have two places you need to change the code, for the actual temperature. If it becomes now 25 degrees, you have to change both t and also tK. If you change t to 25 and don't also change tK to 298.15, then your result will be rubbish.

This would be better.

  float t = 20 ;     //  an input,  change this
  float rF = 50 ;   //   an input
  const float KCconst = 273.15  ;
  float tK = t+KCconst ;    // depends on t,  automatically,  you don't need to manually change this

And then go and replace all the other occurences of 273 ( and 237 ) in your code, by KCconst.

I went and read that German website, you have about 4 mistakes in your implementation of the calculation of aF, so the title of this thread is misleading, to say the least.

Keep in mind that pow() expects floats and returns a float. pow(10, 5) will not return 1000000.000000.

Sure it will (assuming that your extra zero is a typo, and you meant 100000.0
There's a fine prototype for pow() telling the compiler that the function requires floating point arguments, and the compiler will automatically cast the arguments appropriately (or give you a warning for the cases where it can't.)

danjeln:
Maybe you should consider using usigned floats, or even doubles instead

/Danjel

Is that like a metric crescent wrench?

RPN?

Doc