Skip to content

Commit

Permalink
absolute pressure + relative pressure(F) to inHg automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed Jun 11, 2019
1 parent aa95279 commit b19fd36
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
38 changes: 36 additions & 2 deletions MeteoFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ float MeteoFunctions::ft_m(float feet) {
* Converts hPa to inHg
*/
float MeteoFunctions::hPa_inHg(float hPa) {
return 0.02952998751 * hPa;
return hPa * 0.02952998751;
}

/**
Expand All @@ -107,6 +107,20 @@ float MeteoFunctions::inHg_hPa(float inHg) {
return inHg / 0.02952998751;
}

/**
* Converts g/m3 to gr/ft3
*/
float MeteoFunctions::gm3_grft3(float gm3) {
return gm3 * 0.0283168466;
}

/**
* Converts gr/ft3 to g/m3
*/
float MeteoFunctions::grft3_gm3(float grft3) {
return grft3 / 0.0283168466;
}

/**
* Calculates humidex in Celsius
*/
Expand Down Expand Up @@ -268,5 +282,25 @@ float MeteoFunctions::relativePressure_c(float abs_pressure, float height_m, flo
* Calculates relative pressure
*/
float MeteoFunctions::relativePressure_f(float abs_pressure, float height_ft, float temp_f) {
return relativePressure_c(abs_pressure, ft_m(height_ft), f_c(temp_f));
return hPa_inHg(relativePressure_c(abs_pressure, ft_m(height_ft), f_c(temp_f)));
}

/**
* Calculates absolute humidity
*/
float MeteoFunctions::absoluteHumidity_c(float temp_c, float humidity) {
double abs = 6.112 * exp(17.67 * temp_c / (temp_c + 243.5));
abs *= humidity * 2.1674;
abs /= (273.15 + temp_c);

return static_cast<float>(abs);
}

/**
* Calculates absolute humidity
*/
float MeteoFunctions::absoluteHumidity_f(float temp_f, float humidity) {
return gm3_grft3(absoluteHumidity_c(f_c(temp_f), humidity));
}


6 changes: 5 additions & 1 deletion MeteoFunctions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MIT License
Copyright (c) 2018 Pavel Slama
Copyright (c) 2019 Pavel Slama
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -42,6 +42,8 @@ class MeteoFunctions {
float knToMs(float kn);
float m_ft(float meters);
float ft_m(float feet);
float gm3_grft3(float gm3);
float grft3_gm3(float grft3);
float hPa_inHg(float hPa);
float inHg_hPa(float inHg);
float humidex_c(float temp_c, float humidity);
Expand All @@ -59,6 +61,8 @@ class MeteoFunctions {
float cloudBase_f(float temp_f, float humidity);
float relativePressure_c(float abs_pressure, float height_m, float temp_c);
float relativePressure_f(float abs_pressure, float height_ft, float temp_f);
float absoluteHumidity_c(float temp_c, float humidity);
float absoluteHumidity_f(float temp_f, float humidity);
};

#endif // METEOFUNCTIONS_H
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Do you have your own meteo station based on Arduino or Mbed? and ever wondered h
- Apparent temperature
- Cloud height base
- Relative pressure
- Absolute humidity

Let's add them to your project. You don't need any special sensors, it's just a math. Here is a class that do that for you. Supports both **Celsius** and **Fahrenheit**.
Let's add them to your project. You don't need any special sensors, it's just a math. Here is a class that do that for you. Supports both **Celsius** and **Fahrenheit**, please navigate to full example.

## Example
```cpp
Expand Down Expand Up @@ -67,7 +68,10 @@ void loop() {

Serial.print(" metres\n: ");
Serial.print(calc.relativePressure_c(pressure, above_sea, temp));
Serial.println(" Pa");

Serial.print(" Pa\nAbsolute humidity: ");
Serial.print(calc.absoluteHumidity_c(temp, humidity));
Serial.println(" g/m3\n");

delay(5000);
}
Expand Down
12 changes: 9 additions & 3 deletions examples/MeteoFunctions/MeteoFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ void loop() {

Serial.print(" metres\nRelative pressure: ");
Serial.print(calc.relativePressure_c(pressure, above_sea, temp));
Serial.println(" Pa\n");

Serial.print(" Pa\nAbsolute humidity: ");
Serial.print(calc.absoluteHumidity_c(temp, humidity));
Serial.println(" g/m3\n");

#elif defined(FAHRENHEIT)
Serial.print("Wind speed: ");
Expand Down Expand Up @@ -98,8 +101,11 @@ void loop() {
Serial.print(calc.cloudBase_f(temp, humidity));

Serial.print(" feet\nRelative pressure: ");
Serial.print(calc.hPa_inHg(calc.relativePressure_f(pressure, above_sea, temp)));
Serial.println(" inHg\n");
Serial.print(calc.relativePressure_f(pressure, above_sea, temp));

Serial.print(" inHg\nAbsolute humidity: ");
Serial.print(calc.absoluteHumidity_f(temp, humidity));
Serial.println(" gr/ft3\n");
#endif
delay(5000);
}
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msToMph KEYWORD2
msToKn KEYWORD2
m_f KEYWORD2
f_m KEYWORD2
gm3_grft3 KEYWORD2
grft3_gm3 KEYWORD2
humidex_c KEYWORD2
humidex_f KEYWORD2
dewPoint_c KEYWORD2
Expand All @@ -21,3 +23,5 @@ cloudBase_m KEYWORD2
cloudBase_f KEYWORD2
relativePressure_c KEYWORD2
relativePressure_f KEYWORD2
absoluteHumidity_c KEYWORD2
absoluteHumidity_f KEYWORD2
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"email": "info@pavelslama.cz",
"url": "https://github.com/pilotak"
},
"version": "1.0.4",
"version": "1.1.0",
"frameworks": "arduino, mbed",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ paragraph=extend your meteo station by calculating other meteorologist values
url=https://github.com/pilotak/MeteoFunctions
includes=MeteoFunctions.h
category=Data Processing
version=1.0.4
version=1.1.0
architectures=*

0 comments on commit b19fd36

Please sign in to comment.