Humidity calculations

i get that now thanks. do you what im missing as the reading isnt coming out as it should

float c = (17.502*SensorTempVoltage/(240.97+SensorTempVoltage));
  float a = 6.112*pow(2.71828182845904,c);
  
float d =(17.502*SensorTempVoltage1/(240.97+SensorTempVoltage1));
  float b = 6.112*pow(2.71828182845904,d);
                     
  	float RelativeHumidity = (100*(b-N*(1+0.00115*SensorTempVoltage1)*(SensorTempVoltage-SensorTempVoltage1)))/a;                 
	                          
                    
       

What do you think the reading should be?

Why use this expression, when the exp() function is built in?
float b = 6.112*pow(2.71828182845904,d);

Did you not read ALL of reply #4, or reply #10?

Your advice was confusing, and bad.

But a good exercise?

i input the dry and wet temperatures and the humidity should be lower
http://www.ringbell.co.uk/info/humid.htm
for example 24.71 & 21.78 should be 77% and im getting 84%

float c = (17.502*SensorTempVoltage/(240.97+SensorTempVoltage));
  float a = 6.112*pow(2.71828182845904,c);

Is "SensorTempVoltage" the temperature, in degrees Celsius?

Are Td = 24.71 degC and Tw = 21.78 degC ?

yes

void setup() {
Serial.begin(115200);
float Td=24.71, Tw=21.78;
float ed = 6.112*exp(17.502*Td/(240.97 + Td));
float ew = 6.112*exp(17.502*Tw/(240.97 + Tw));
float rh = 100.0*(ew-0.668745*(1+0.00115*Tw)*(Td-Tw))/ed;
Serial.print("RH = ");
Serial.println(rh);  //prints RH = 77.32
}
void loop() {}

The relative humidity is: 77.33% and not 84%!
This is the sketch-1: using primitive approach @GolamMostafa

void setup()
{
  Serial.begin(9600);
  float Td = 24.71;
  float Tw = 21.78;
  
  float x =  0.4343 * (1.8115 + (17.502 * Tw) / (240.87 + Tw));
  float ew = pow(10, x);  //10^x
  //Serial.println(ew, 2);
  //------------------------------------
  float y =  0.4343 * (1.8115 + (17.502 * Td) / (240.87 + Td));
  float ed = pow(10, y);  //10^y
  //Serial.println(ed, 2);
  //-----------------------------

  float humidity = ((ew-0.6687451584*(1+0.00115*Tw)*(Td-Tw))/ed)*100;
  Serial.print("Relative Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
}

void loop() 
{

}

This is the Sketch-2 using exp() function of @jremington which gives 77.32%.

void setup()
{
  Serial.begin(9600);
  float Td = 24.71;
  float Tw = 21.78;

  float ed = 6.112 * exp(17.502 * Td / (240.97 + Td));
  float ew = 6.112 * exp(17.502 * Tw / (240.97 + Tw));

  float humidity = ((ew - 0.6687451584 * (1 + 0.00115 * Tw) * (Td - Tw)) / ed) * 100;
  Serial.print("Relative Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
}

void loop() 
{

}

Yes! It is for the pupil who will be asked to evaluate ew without using the exp() function.

Pointless lesson. Nature does not know or care that humans have ten fingers, which is why the natural logarithm is used in the sciences, rather than log base 10.

Aren't you a bit harsh here? The guy tried to help, developed his math skills, learned that in C the log() function defaults to ln() (in contrast to normal calculators that default to 10 as a base). That defaults always need checking ( you think e is the default base, he thinks 10 is the default base). And he showed that with some creativity he was able to get his sketch working without knowing about exp() function.
It did not help OP (but maybe OP was also unaware of the defaults in C), but it has certainly helped him understanding. For me it has confirmed that you must always try to get the defaults or assumptions on the table as people are not always aware of common practices in another field.
Of course his creativity did not improve the code readability. But he took the challenge and succeeded. In my opinion that is what engineering is about...

1 Like

Hi, @bulman20
Welcome to the forum.

Have you built this project, or are we in the world of simulation?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

In good old days, we were asked to write multi-line codes to convert a lower-case letter into upper-case letter. We consulted the ASCII Tables for the numerical values of the alphabets of the English Language and then derived the realtionship between the ASCII Codes of the lower-case and upper-case letters. Once our tasks were done, the teacher introduced the toupper() function.

In response to the question of why the function was not introduced earlier, the teacher replied that "information/data hiding/abstraction" is not the attitude of a school. It is practiced by the business house to save money (savings of time and energy).

In the learning (not training) school, the teacher gathers ideas from the pupils first and then helps them putting those ideas together to solve their problems. And of course, the teacher brings new/advanced ideas (from his own collection) to the pupils as the time progresses.

Hi,

And that way you appreciate how that function works and just because there is a function for what you were asked to do, there will not be a function for many situations you encounter.

Tom.... :smiley: :+1: :coffee: :australia:

1 Like

Human mind can imagine so many things that go beyond the apprehension of the machine. The C/C++ Compiler contain a limited (though huge in counts) number of ready-made routines (the functions) which possibly has not contained a function that can be a helpful for @TomGeorge to solve his newly created idea. In this case, @TomGeorge has to write his own codes, assign a name to them and include it as myfunction() in one of the header files of the Compiler.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.