I am not sure on the logic of computing algebra. My code and compile errors are below. I think my problem is in my syntax (of the operator ^), and would appreciate someone pointing me in the right direction. I have also tried " ^= "
invalid operands of types 'double' and 'double' to binary 'operator^'
sketch_nov29a.ino: In function 'int getHumidity()':
sketch_nov29a:457: error: invalid operands of types 'double' and 'double' to binary 'operator^'
sketch_nov29a:459: error: conflicting declaration 'float e'
sketch_nov29a:448: error: 'e' has a previous declaration as 'const float e'
sketch_nov29a:461: error: invalid operands of types 'double' and 'double' to binary 'operator^'
sketch_nov29a:463: error: conflicting declaration 'float e'
sketch_nov29a:448: error: 'e' has a previous declaration as 'const float e'
int getHumidity(){
sensors.requestTemperatures();
float temp0 = sensors.getTempC(t0);
float temp1 = sensors.getTempC(t1);
const float p_sta = 754; //local atmospheric pressure constant in millibars
const float e = 2.7182818;
float t_w = temp0; //wet-bulb temperature in *C
float t = temp1; //air temperature in *C
float e_w = 6.112*e^(17.67*t_w/t+243.5); //vapour pressure in relation to wet-bulb temperature
float e = e_w - p_sta*(t-t_w)*0.00066*(1+(0.0015*t_w)); //actual vapour pressure
float e_s = 6.112*e^(17.67*t/t+243.5); //saturated vapour pressure
int rh = (e/e_s)*100;
Serial.print(rh);
}
Why you use operators without checking the correct syntax in a language reference? XD
Languague C reference, see in this page what the real use of ^ operator:
Cheers for the advice everyone. I have updated my sketch to use pow() and have reduced my floats to 5 decimals. I am having problems with the arithmetic however. My guess is that using the pow() function is resulting in numbers too large to be floats? Serial prints the result as follows:
"Temp0 is : 21.75 Temp1 is : 21.75 e_s is : inf e_w is : inf e is : inf R/H is : 0"
int printHumidity(){
sensors.requestTemperatures();
float e = 2.71828; // the number e, used to calculate e_s and e_w
float temp0 = sensors.getTempC(t0);
float temp1 = sensors.getTempC(t1);
float t_w = temp0; //wet-bulb temperature in *C
float t = temp1; //air temperature in *C
const float p_sta = 754; //local atmospheric pressure constant in millibars
float e_s = 6.112 * pow(e, (17.67 * t / t + 243.5)); //saturated vapour pressure
float e_w = 6.112 * pow(e, (17.67*t_w/t+243.5)); //vapour pressure in relation to wet-bulb temperature
e = e_w - p_sta * (t - t_w) * 0.00066 *(1 + (0.0015 * t_w)); //actual vapour pressure
int rh = (e/e_s)*100;
Serial.print("Temp0 is : ");
Serial.print(temp0);
Serial.print ("\t");
Serial.print("Temp1 is : ");
Serial.print(temp1);
Serial.print ("\t");
Serial.print("e_s is : ");
Serial.print(e_s);
Serial.print ("\t");
Serial.print("e_w is : ");
Serial.print(e_w);
Serial.print ("\t");
Serial.print("e is :");
Serial.print(e);
Serial.print ("\t");
Serial.print("R/H is :");
Serial.print(rh);
Serial.print("\n");
}
Guess I will never know how accurate this is, but it appears to be right! exp() worked a charm. I did have to make adjustments to my parenthesis. Cheers everyone, I will have to do a write-up at some stage as this should be far more reliable that those DHT**'s !
"Temp0 is : 18.00 Temp1 is : 20.50 e_s is : 24.10 e_w is : 20.39 e is :19.11 R/H is :79"
int printHumidity(){
sensors.requestTemperatures();
float temp0 = sensors.getTempC(t0);
float temp1 = sensors.getTempC(t1);
float t_w = temp0; //wet-bulb temperature in *C
float t = temp1; //air temperature in *C
const float p_sta = 754.0; //local atmospheric pressure constant in millibars
float e_s = 6.112 * exp((17.67 * t) / (t + 243.5)); //saturated vapour pressure
float e_w = 6.112 * exp((17.67 * t_w) / (t + 243.5)); //vapour pressure in relation to wet-bulb temperature
e = e_w - p_sta * (t - t_w) * 0.00066 *(1 + (0.0015 * t_w)); //actual vapour pressure
int rh = ((e/e_s)*100.0);
}