hello, ive hit an issue where my humidity calculations as they are coming up incorrect. im using whats called the wet bulb-dry bulb technique. Hopefully someone here is familiar and can lend a hand as im very new to this and currently tinkercad. the issue with the last part labelled HumidityCalculations
and the equation im following is here
// LCD library
#include <LiquidCrystal.h>
// Initialize the LCD library
LiquidCrystal LCD(12,11,5,4,3,2);
// Defines analog pin A0 as Temperature Sensor input
int SensorTempPin=0;
// Defines analog pin A1 as Temperature Sensor input
int SensorTempPin1=1;
void setup() {
// Defines the number of columns and rows on the LCD
LCD.begin(16,2);
// Print the message on the LCD
LCD.print("Temp: Hum:");
// Change cursor to first column and second row of LCD
LCD.setCursor(0,1);
// Print the message on the LCD
LCD.print(" & ");
}
void loop() {
// Read the voltage on the Temperature Sensor
int SensorTempVoltage=analogRead(SensorTempPin);
// Converts the voltage read
float Voltage=SensorTempVoltage*5;
Voltage/=1024;
// Converts read voltage to Degrees Celsius
float TemperatureC=(Voltage-0.5)*100;
// Change cursor to first column and second row of LCD
LCD.setCursor(0,1);
// Prints the temperature in degrees Celsius
LCD.print(TemperatureC);
// Read the voltage on the Temperature Sensor
int SensorTempVoltage1=analogRead(SensorTempPin1);
// Converts the voltage read
float Voltage1=SensorTempVoltage1*5;
Voltage1/=1024;
// Converts read voltage to Degrees Celsius
float TemperatureC1=(Voltage1-0.5)*100;
// Change cursor to first column and second row of LCD
LCD.setCursor(8,1);
// Prints the temperature in degrees Celsius
LCD.print(TemperatureC1);
//HumidityCalculations
float DryBulb=(17.502*SensorTempVoltage/240.97+SensorTempVoltage);
float Wetbulb=(17.502*SensorTempVoltage1/240.97+SensorTempVoltage1);
float a=6.112*(2.71828182845904*DryBulb);
float b=6.112*(2.71828182845904*Wetbulb);
float RelativeHumidity = ((b-0.6687451584*(1+0.00115*SensorTempVoltage1)*(SensorTempVoltage-SensorTempVoltage1))/a)*100;
LCD.setCursor(10,0);
LCD.print(RelativeHumidity);
}
y = (17.502*Tw)/(240.87+Tw)
ew = 6.112*e^y
e^y = ew/6.112
y = ln(ew/6.112)
y = ln(ew) - ln(6.112)
y = ln(ew) - 1.8115
ln(ew) = 1.8115 + y
log(ew)/log(e) = 1.8115 + y
log(ew) = 0.4343*(1.8115 + y) = x
ew = pow(10, x)
The fact that the entire "derivation" is totally unnecessary, that you don't explain where some of the "magic numbers" come from, and that you end up using pow(10, x) when working with a formula that does not involve powers of 10.
Is your effort intended to be instructive for someone else?
If your constants are carried to enough significant digits, the results are identical (MathCAD carries a and b to a large number of significant digits...only 2 or 3 shown here):
But, as @jremington said, the "derivation" is totally unnecessary.
```
// LCD library
#include <LiquidCrystal.h>
// Initialize the LCD library
LiquidCrystal LCD(12,11,5,4,3,2);
// Defines analog pin A0 as Temperature Sensor input
int SensorTempPin=0;
// Defines analog pin A1 as Temperature Sensor input
int SensorTempPin1=1;
int N=0.6687451584;
void setup() {
// Defines the number of columns and rows on the LCD
LCD.begin(16,2);
// Print the message on the LCD
LCD.print("Temp: Hum:");
// Change cursor to first column and second row of LCD
LCD.setCursor(0,1);
// Print the message on the LCD
LCD.print(" & ");
}
void loop() {
// Read the voltage on the Temperature Sensor
int SensorTempVoltage=analogRead(SensorTempPin);
// Converts the voltage read
float Voltage=SensorTempVoltage*5;
Voltage/=1024;
// Converts read voltage to Degrees Celsius
float TemperatureC=(Voltage-0.5)*100;
// Change cursor to first column and second row of LCD
LCD.setCursor(0,1);
// Prints the temperature in degrees Celsius
LCD.print(TemperatureC);
// Read the voltage on the Temperature Sensor
int SensorTempVoltage1=analogRead(SensorTempPin1);
// Converts the voltage read
float Voltage1=SensorTempVoltage1*5;
Voltage1/=1024;
// Converts read voltage to Degrees Celsius
float TemperatureC1=(Voltage1-0.5)*100;
// Change cursor to first column and second row of LCD
LCD.setCursor(8,1);
// Prints the temperature in degrees Celsius
LCD.print(TemperatureC1);
//HumidityCalculations
float a = 6.112*exp(17.502*SensorTempVoltage/(240.97 + SensorTempVoltage));
float b = 6.112*exp(17.502*SensorTempVoltage1/(240.97 + SensorTempVoltage1));
float RelativeHumidity = ((b-0.6687451584*(1+0.00115*SensorTempVoltage1)*(SensorTempVoltage-SensorTempVoltage1))/a)*100;
LCD.setCursor(10,0);
LCD.print(RelativeHumidity);
}
But not natural anti-log, which is confusing as the equations are all given using powers of e.
Physics uses e^x and ln(x) precisely because that's how nature (and mathematics come to that) works.
In C/C++ exp(x) calculates e^x and log(x) calculates ln(x). log10() and pow() might be appropriate for decibel conversions but are complicating things here.
I am not required natural anti-log; but, the decimal anti-log. Moreover, a man with ignorance moves in a way that his inquisitive mind thinks logical though primitive.
The original expression of the OP is:
ew = 6.112*e^ ((17.502*Tw)/(240.87+Tw))
Let us take: y = (17.502*Tw)/(240.87+Tw)
==> ew = 6.112*e^y
==> e^y = ew/6.112
==> y = ln(ew/6.112)
==> y = ln(ew) - ln(6.112)
==> y = ln(ew) - 1.8115
==> ln(ew) = 1.8115 + y
==> log(ew)/log(e) = 1.8115 + y
==> log(ew)/0.4343 = 1.8115 + y
==> log(ew) = 0.4343*(1.8115 +y)
==> log(ew) = 04343*(1.8115+(17.502*Tw)/(240.87+Tw))
Implementation:
float x = 0.4343*(1.8115+(17.502*Tw)/(240.87+Tw)); //for Tw = 78, x = 2.6460
where: x = log(ew)
==> ew = 10^x
Implementation:
float ew = pow(10, x); //10^2.6460 = 442.59
Final Codes:
float x = 0.4343*(1.8115+(17.502*Tw)/(240.87+Tw));
float ew = pow(10, x); //10^2.6460 = 442.59
Serial.println(ew, 2);
My approach appeared complicated because you know the exp() function. It was rather enjoyable to me to see the log transformation from one base to another that I saw in school 52 years ago.
it is the value of "e" that is raised to the power of the value in the parenthesis in the Relative Humidity Equations you posted. values such as e or pi are defined in math.h