mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-07-25 21:51:04 +03:00
doc: add issues summary
This commit is contained in:
@ -10,6 +10,7 @@ MQUnifiedsensor::MQUnifiedsensor(String Placa, float Voltage_Resolution, int ADC
|
||||
//this->_type = type; //MQ-2, MQ-3 ... MQ-309A
|
||||
//this->_placa = Placa;
|
||||
this-> _VOLT_RESOLUTION = Voltage_Resolution;
|
||||
this-> _VCC = Voltage_Resolution;
|
||||
this-> _ADC_Bit_Resolution = ADC_Bit_Resolution;
|
||||
}
|
||||
MQUnifiedsensor::MQUnifiedsensor(String Placa, String type) {
|
||||
@ -41,6 +42,10 @@ void MQUnifiedsensor::setVoltResolution(float voltage_resolution)
|
||||
{
|
||||
_VOLT_RESOLUTION = voltage_resolution;
|
||||
}
|
||||
void MQUnifiedsensor::setVCC(float vcc)
|
||||
{
|
||||
_VCC = vcc;
|
||||
}
|
||||
void MQUnifiedsensor::setPin(int pin) {
|
||||
this->_pin = pin;
|
||||
}
|
||||
@ -59,6 +64,10 @@ float MQUnifiedsensor::getVoltResolution()
|
||||
{
|
||||
return _VOLT_RESOLUTION;
|
||||
}
|
||||
float MQUnifiedsensor::getVCC()
|
||||
{
|
||||
return _VCC;
|
||||
}
|
||||
String MQUnifiedsensor::getRegressionMethod()
|
||||
{
|
||||
if(_regressionMethod == 1) return "Exponential";
|
||||
@ -85,7 +94,8 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
|
||||
Serial.println("Contributors: Andres A. Martinez - Juan A. Rodríguez - Mario A. Rodríguez O ");
|
||||
|
||||
Serial.print("Sensor: "); Serial.println(_type);
|
||||
Serial.print("Supply voltage: "); Serial.print(_VOLT_RESOLUTION); Serial.println(" VDC");
|
||||
Serial.print("ADC voltage: "); Serial.print(_VOLT_RESOLUTION); Serial.println(" VDC");
|
||||
Serial.print("Sensor supply (VCC): "); Serial.print(_VCC); Serial.println(" VDC");
|
||||
Serial.print("ADC Resolution: "); Serial.print(_ADC_Bit_Resolution); Serial.println(" Bits");
|
||||
Serial.print("R0: "); Serial.print(_R0); Serial.println(" KΩ");
|
||||
Serial.print("RL: "); Serial.print(_RL); Serial.println(" KΩ");
|
||||
@ -106,7 +116,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
|
||||
else
|
||||
{
|
||||
Serial.print("|"); Serial.print(_adc); Serial.print("| v = ADC*"); Serial.print(_VOLT_RESOLUTION); Serial.print("/"); Serial.print((pow(2, _ADC_Bit_Resolution)) - 1); Serial.print(" | "); Serial.print(_sensor_volt);
|
||||
Serial.print(" | RS = ((" ); Serial.print(_VOLT_RESOLUTION ); Serial.print("*RL)/Voltage) - RL| "); Serial.print(_RS_Calc); Serial.print(" | Ratio = RS/R0| ");
|
||||
Serial.print(" | RS = ((" ); Serial.print(_VCC ); Serial.print("*RL)/Voltage) - RL| "); Serial.print(_RS_Calc); Serial.print(" | Ratio = RS/R0| ");
|
||||
Serial.print(_ratio); Serial.print( " | ");
|
||||
if(_regressionMethod == 1) Serial.print("ratio*a + b");
|
||||
else Serial.print("pow(10, (log10(ratio)-b)/a)");
|
||||
@ -145,7 +155,7 @@ float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool in
|
||||
if(isMQ303A) {
|
||||
_VOLT_RESOLUTION = _VOLT_RESOLUTION - 0.45; //Calculations for RS using mq303a sensor look wrong #42
|
||||
}
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
_RS_Calc = ((_VCC*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
if(!injected) _ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
|
||||
_ratio += correctionFactor;
|
||||
@ -164,7 +174,7 @@ float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool in
|
||||
float MQUnifiedsensor::readSensorR0Rs()
|
||||
{
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
_RS_Calc = ((_VCC*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
_ratio = this->_R0/_RS_Calc; // Get ratio RS_air/RS_gas <- INVERTED for MQ-131 issue 28 https://github.com/miguel5612/MQSensorsLib/issues/28
|
||||
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
|
||||
@ -194,7 +204,7 @@ float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
||||
*/
|
||||
float RS_air; //Define variable for sensor resistance
|
||||
float R0; //Define variable for R0
|
||||
RS_air = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Calculate RS in fresh air
|
||||
RS_air = ((_VCC*_RL)/_sensor_volt)-_RL; //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.
|
||||
@ -231,7 +241,7 @@ float MQUnifiedsensor:: setRsR0RatioGetPPM(float value)
|
||||
float MQUnifiedsensor::getRS()
|
||||
{
|
||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
_RS_Calc = ((_VCC*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||
return _RS_Calc;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class MQUnifiedsensor
|
||||
void setB(float b);
|
||||
void setRegressionMethod(int regressionMethod);
|
||||
void setVoltResolution(float voltage_resolution = 5);
|
||||
void setVCC(float vcc = 5);
|
||||
void setPin(int pin = 1);
|
||||
void serialDebug(bool onSetup = false); //Show on serial port information about sensor
|
||||
void setADC(int value); //For external ADC Usage
|
||||
@ -38,6 +39,7 @@ class MQUnifiedsensor
|
||||
float getR0();
|
||||
float getRL();
|
||||
float getVoltResolution();
|
||||
float getVCC();
|
||||
String getRegressionMethod();
|
||||
float getVoltage(bool read = true, bool injected = false, int value = 0);
|
||||
float stringTofloat(String & str);
|
||||
@ -51,6 +53,7 @@ class MQUnifiedsensor
|
||||
byte _pin = 1;
|
||||
byte _firstFlag = false;
|
||||
float _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
|
||||
float _VCC = 5.0; // Sensor supply voltage
|
||||
float _RL = 10; //Value in KiloOhms
|
||||
byte _ADC_Bit_Resolution = 10;
|
||||
byte _regressionMethod = 1; // 1 -> Exponential || 2 -> Linear
|
||||
|
Reference in New Issue
Block a user