Home Code Some temperature functions

Some temperature functions

by shedboy71

In previous examples we have had various temperature sensors, most of these will display the humidity and the temperature in celsius but it is easy with a few calculations to add support for other useful data

these should be self explanatory

Code

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}

The kelvin is a unit of measure for temperature based upon an absolute scale. It is one of the seven base units in the International System of Units and is assigned the unit symbol K

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}

In simple terms, the dew point (dew point temperature or dewpoint) is the temperature at which a given concentration of water vapor in air will form dew. More specifically it is a measure of atmospheric moisture.

// dewPoint function NOAA
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
Share

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More