Hi all, I have had some trouble trying to calculate sea level pressure using Arduino. Using absolute pressure figures from a sensor I have been able calculate sea level pressure which is useful for monitoring weather by using an Excel spreadsheet. The problem is, I haven't been able to get the formula to work properly for Arduino. Here is the formula I use for Excel:
=F2EXP(G2/(29.3H2))
F2 is absolute pressure, G2 is altitude in meters, which I use as 556 for where I live, and H2 is temperature in Kelvin, so T+273.15 works to get that figure.
I keep getting wild readings as if the syntax isn't right in Arduino.
In this example code that I can use to get for absolute pressure, (P,2) is the function to obtain that, but I've noticed P seems to work fine as well as it rounds to 2 decimals. Can anyone help me with this so I can get it working in Arduino like in Excel? Here is my code. Thank you.
What BMP280 library are you using? I have found this:
But it's clearly not what you are using as it lacks the methods you seem to be calling. Aside from anything else, this bmp.startMeasurment(); is misspelled. Who wrote this code?
Also, as liudr mntioned, you post about some equation you use, but I don't see it anywhere in your code and I don't know what it has to do with your sketch not working.
If you are getting weird results, possibilities are:
sensor not working/not wired up
the delay() business not being done right
bmp.getTemperatureAndPressure(T,P);
I suspect that
you wrote the library
you thought that assigning a value to a parameter would write back the result to the place where it was called from
This only happens if the parameter is declared as a reference.
I think that T and P contain ribbish off the stack. To test, explicitly assign zero to T and P before calling the methods to take the reading.
liudr:
In equation 2, there is a negative sign inside the exponent:
You fail to understand the problem is computing the pressure at sea level given a reading
at altitude, not the other way. Sea level pressure is higher.
GoBraves21:
I haven't been able to get the formula to work properly for Arduino. Here is the formula I use for Excel:
=F2EXP(G2/(29.3H2))
F2 is absolute pressure, G2 is altitude in meters, which I use as 556 for where I live, and H2 is temperature in Kelvin, so T+273.15 works to get that figure.
Try this:
void setup() {
// put your setup code here, to run once:
Serial.begin (115200) ;
float F2 = 101000.0;
float G2 = 556;
float T = 25.0 ;
Serial.println (F2 * exp (G2 / (29.3 * (T + 273.15)))) ;
}
void loop () {}
Even simpler and close enough for practical purposes:
MarkT:
You fail to understand the problem is computing the pressure at sea level given a reading
at altitude, not the other way. Sea level pressure is higher.
Yeah, you're right. The OP needs explain this more clearly than giving out Excel cell references.
Thanks a lot Mark! I like the spaces in there too, so it's not so cluttered. The EXP function was what was throwing it off for me I believe. I didn't realize exp in lowercase had to be used. I didn't have to use any float variables for this either.
The Adafruit library for whatever reason would not work for me as someone asked about that.
There is a misspelling indeed in this part of the code bmp.startMeasurment(), but the library seems to work well and it's the simplest I've found at least with an example.
By the way, with that library, here is the formula in Arduino if you want sea level air pressure in millibars so you can compare with your local weather: (P * exp (556 / (29.3 * (T + 273.15))));
Just to let everyone know for sure so there's no confusion, P is the absolute pressure reading and T is temperature in Celsius. The 556 is height in meters, so obviously change that for you.
Being in the U.S., we mainly use pressure in inches so here is that formula:
(P * exp (556 / (29.3 * (T + 273.15)))*0.0295301);
Thanks again for the help and responses, especially to Mark!