sparkfun / SparkFun_SGP30_Arduino_Library

This is an Arduino library for the SGP30 Air Quality Sensor
Other
13 stars 9 forks source link

Code in Example3_Humidity.ino is inaccurate #5

Open tfppcn opened 4 years ago

tfppcn commented 4 years ago

Subject of the issue

The code to convert RH to AH is inaccurate.

Your workbench

ESP8266

Steps to reproduce

The RHtoAbsolute(float relHumidity, float tempC) function to calculate absolute humidity is inaccurate double eSat = 6.11 * pow(10.0, (7.5 * tempC / (237.7 + tempC))); double vaporPressure = (relHumidity * eSat) / 100; double absHumidity = 1000 * vaporPressure * 100 / ((tempC + 273) * 461.5);

Expected behaviour

Use this code instead double absHumidity = 216.7 * ((relHumidity / 100.0) * 6.112 * exp((17.62 * tempC) / (243.12 + tempC)) / (273.15 + tempC));

Actual behaviour

The new code should return more accurate calculation for absolute humidity

nseidle commented 4 years ago

What makes the original code inaccurate? Typecasting or other?

Assuming it's a formula you've found, where does your code originate?