mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Respect upper and down limits from datasheet indicating 0 PPM or 9999 PPM
This commit is contained in:
parent
886bfd9981
commit
b2616295a3
@ -107,8 +107,12 @@ float MQUnifiedsensor::readSensor(String nameLectureRequeired, bool print)
|
||||
setSensorCharacteristics(nameLectureRequeired, print); //In this function update _a and _b
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
_ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
if(_ratio <= 0 || _ratio>100) _ratio = 0.01; //No negative values accepted or upper datasheet recomendation.
|
||||
_PPM= _a*pow(_ratio, _b);
|
||||
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
if(_PPM > 10000) _PPM = 9999; //No negative values accepted or upper datasheet recomendation.
|
||||
|
||||
if(print)
|
||||
{
|
||||
@ -522,7 +526,9 @@ float MQUnifiedsensor::calibrate(boolean print) {
|
||||
float RS_air; //Define variable for sensor resistance
|
||||
float R0; //Define variable for R0
|
||||
RS_air = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Calculate RS in fresh air
|
||||
if(RS_air < 0) RS_air = 0; //No negative values accepted.
|
||||
R0 = RS_air/_ratioInCleanAir; //Calculate R0
|
||||
if(R0 < 0) R0 = 0; //No negative values accepted.
|
||||
if(print)
|
||||
{
|
||||
Serial.println("*******Calibrating*********");
|
||||
|
@ -273,14 +273,14 @@ class MQUnifiedsensor
|
||||
|
||||
private:
|
||||
/************************Private vars************************************/
|
||||
int _pin, _type, _lecturePosInArray;
|
||||
double _R0;
|
||||
byte _pin, _type, _lecturePosInArray;
|
||||
byte _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
byte _ratioInCleanAir, _sensor_volt;
|
||||
byte _RLValue = 10; //Value in KiloOhms
|
||||
float _R0, RS_air, _ratio, _PPM, _RS_Calc;
|
||||
float _b;
|
||||
double _a;
|
||||
String _nameLectureRequeired;
|
||||
float _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
int _RLValue = 10; //Value in KiloOhms
|
||||
float _PPM, _RS_Calc;
|
||||
float _ratioInCleanAir, _sensor_volt, RS_air, _a, _b, _ratio;
|
||||
|
||||
};
|
||||
|
||||
#endif //MQUnifiedsensor_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user