diff --git a/MQ135.cpp b/MQ135.cpp index 676ed31..db2a390 100755 --- a/MQ135.cpp +++ b/MQ135.cpp @@ -11,6 +11,8 @@ the datasheet but the information there seems to be wrong. @section HISTORY v1.0 - First release +v1.1 - Add rzero param in constructor, + correcting atmospheric CO2 level for 2019 year */ /**************************************************************************/ @@ -20,20 +22,20 @@ v1.0 - First release /*! @brief Default constructor -@param[in] pin The analog input pin for the readout of the sensor +@param[in] pin The analog input pin for the readout of the sensor +@param[in] rzero Calibration resistance at atmospheric CO2 level */ /**************************************************************************/ - -MQ135::MQ135(uint8_t pin) { +MQ135::MQ135(uint8_t pin, float rzero) { + _rzero = rzero; _pin = pin; } - /**************************************************************************/ /*! @brief Get the correction factor to correct for temperature and humidity -@param[in] t The ambient air temperature +@param[in] t The ambient air temperature in Celsius @param[in] h The relative humidity @return The calculated correction factor @@ -60,7 +62,7 @@ float MQ135::getResistance() { @brief Get the resistance of the sensor, ie. the measurement value corrected for temp/hum -@param[in] t The ambient air temperature +@param[in] t The ambient air temperature in Celsius @param[in] h The relative humidity @return The corrected sensor resistance kOhm @@ -78,7 +80,7 @@ float MQ135::getCorrectedResistance(float t, float h) { */ /**************************************************************************/ float MQ135::getPPM() { - return PARA * pow((getResistance()/RZERO), -PARB); + return PARA * pow((getResistance()/_rzero), -PARB); } /**************************************************************************/ @@ -86,14 +88,14 @@ float MQ135::getPPM() { @brief Get the ppm of CO2 sensed (assuming only CO2 in the air), corrected for temp/hum -@param[in] t The ambient air temperature +@param[in] t The ambient air temperature in Celsius @param[in] h The relative humidity @return The ppm of CO2 in the air */ /**************************************************************************/ float MQ135::getCorrectedPPM(float t, float h) { - return PARA * pow((getCorrectedResistance(t, h)/RZERO), -PARB); + return PARA * pow((getCorrectedResistance(t, h)/_rzero), -PARB); } /**************************************************************************/ @@ -112,7 +114,7 @@ float MQ135::getRZero() { @brief Get the corrected resistance RZero of the sensor for calibration purposes -@param[in] t The ambient air temperature +@param[in] t The ambient air temperature in Celsius @param[in] h The relative humidity @return The corrected sensor resistance RZero in kOhm diff --git a/MQ135.h b/MQ135.h index 22cefec..f1322e3 100755 --- a/MQ135.h +++ b/MQ135.h @@ -11,6 +11,8 @@ the datasheet but the information there seems to be wrong. @section HISTORY v1.0 - First release +v1.1 - Add rzero param in constructor, + correcting atmospheric CO2 level for 2019 year */ /**************************************************************************/ #ifndef MQ135_H @@ -23,8 +25,7 @@ v1.0 - First release /// The load resistance on the board #define RLOAD 10.0 -/// Calibration resistance at atmospheric CO2 level -#define RZERO 76.63 + /// Parameters for calculating ppm of CO2 from sensor resistance #define PARA 116.6020682 #define PARB 2.769034857 @@ -36,14 +37,16 @@ v1.0 - First release #define CORD 0.0018 /// Atmospheric CO2 level for calibration purposes -#define ATMOCO2 397.13 +/// On august 2019 from https://www.co2.earth +#define ATMOCO2 409.95 class MQ135 { private: uint8_t _pin; + float _rzero; public: - MQ135(uint8_t pin); + MQ135(uint8_t pin, float rzero=76.63); float getCorrectionFactor(float t, float h); float getResistance(); float getCorrectedResistance(float t, float h);