AirQualityClick on A0 on Nucleo-F411RE
Revision 0:964a928b323e, committed 2015-04-14
- Comitter:
- Guillaume31
- Date:
- Tue Apr 14 11:36:17 2015 +0000
- Commit message:
- AirQualityClick on A0 on Nucleo-F411RE
Changed in this revision
Air.cpp | Show annotated file Show diff for this revision Revisions of this file |
Air.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 964a928b323e Air.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Air.cpp Tue Apr 14 11:36:17 2015 +0000 @@ -0,0 +1,98 @@ +#include "mbed.h" +#include "Air.h" + +Air::Air (PinName pin): _pin (pin) { +} + +/**************************************************************************/ +/*! +@brief Get the correction factor to correct for temperature and humidity + +@param[in] t The ambient air temperature +@param[in] h The relative humidity + +@return The calculated correction factor +*/ +/**************************************************************************/ +float Air::getCorrectionFactor(float t, float h) { + return CORA * (double)t * t - (double)CORB * t + CORC - ((double)h-33.)*CORD; +} + +/**************************************************************************/ +/*! +@brief Get the correction factor to correct for temperature and humidity +a +@return The sensor resistance in kOhm +*/ +/**************************************************************************/ +float Air::getResistance() { + double val = _pin.read(); + return ((1023./(double)val) * 5. - 1.)*RLOAD; +} + +/**************************************************************************/ +/*! +@brief Get the resistance of the sensor, ie. the measurement value corrected + for temp/hum + +@param[in] t The ambient air temperature +@param[in] h The relative humidity + +@return The corrected sensor resistance kOhm +*/ +/**************************************************************************/ +float Air::getCorrectedResistance(float t, float h) { + return getResistance()/getCorrectionFactor(t, h); +} + +/**************************************************************************/ +/*! +@brief Get the ppm of CO2 sensed (assuming only CO2 in the air) + +@return The ppm of CO2 in the air +*/ +/**************************************************************************/ +float Air::getPPM() { + return PARA * pow(((double)getResistance()/RZERO), -PARB); +} + +/**************************************************************************/ +/*! +@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] h The relative humidity + +@return The ppm of CO2 in the air +*/ +/**************************************************************************/ +float Air::getCorrectedPPM(float t, float h) { + return PARA * pow(((double)getCorrectedResistance(t, h)/RZERO), -PARB); +} + +/**************************************************************************/ +/*! +@brief Get the resistance RZero of the sensor for calibration purposes + +@return The sensor resistance RZero in kOhm +*/ +/**************************************************************************/ +float Air::getRZero() { + return getResistance() * pow((ATMOCO2/PARA), (1./PARB)); +} + +/**************************************************************************/ +/*! +@brief Get the corrected resistance RZero of the sensor for calibration + purposes + +@param[in] t The ambient air temperature +@param[in] h The relative humidity + +@return The corrected sensor resistance RZero in kOhm +*/ +/**************************************************************************/ +float Air::getCorrectedRZero(float t, float h) { + return getCorrectedResistance(t, h) * pow((ATMOCO2/PARA), (1./PARB)); +}
diff -r 000000000000 -r 964a928b323e Air.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Air.h Tue Apr 14 11:36:17 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef AIR +#define AIR + +#include "mbed.h" + +/// 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 + +/// Parameters to model temperature and humidity dependence +#define CORA 0.00035 +#define CORB 0.02718 +#define CORC 1.39538 +#define CORD 0.0018 + +/// Atmospheric CO2 level for calibration purposes +#define ATMOCO2 397.13 + +class Air { + private: + AnalogIn _pin; + public: + Air (PinName pin); + float getCorrectionFactor(float t, float h); + float getResistance(); + float getCorrectedResistance(float t, float h); + float getPPM(); + float getCorrectedPPM(float t, float h); + float getRZero(); + float getCorrectedRZero(float t, float h); +}; +#endif