Merge pull request #85 from miguel5612/codex/implement-temperature-and-humidity-correction-for-all-exampl

Add optional correction factor to API
master
Miguel Angel Califa Urquiza 10 months ago committed by GitHub
commit 59a2e5852e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -17,9 +17,9 @@ El usuario reporta desbordamiento ("ovf") al utilizar valores muy altos en `setA
Se detectó que la resistencia del sensor se calculaba con `_VOLT_RESOLUTION` en lugar del voltaje de alimentación real. Se añadieron los métodos `setVCC` y `getVCC` y se modificaron las ecuaciones para usar `VCC`. Esta corrección se refleja en la versión 3.0.1 de la biblioteca.
### #70 Parameters to model temperature and humidity dependence
**Estado:** abierto
**Estado:** resuelto en la rama `work`
Los usuarios solicitan factores de corrección para temperatura y humedad aplicables a otros sensores (MQ-4 y MQ-8) además del MQ-135. Aún no se han añadido estos parámetros. Se anima a la comunidad a contribuir con implementaciones y ejemplos.
Se añadieron variables opcionales de "correction factor" en todos los ejemplos y se extendieron las funciones `calibrate` y `readSensorR0Rs` para aceptar este parámetro opcional. Así, el usuario puede ajustar las lecturas en función de temperatura y humedad cuando el datasheet lo permita. Los coeficientes deben consultarse para cada sensor.
### #67 Sensor won't finish the Calibration process if done in clean air
**Estado:** abierto

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
alcoholPPM = MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
alcoholPPM = MQ3.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.print("Alcohol now (PPM): ");
Serial.println(alcoholPPM);
delay(500); //Sampling frequency

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ3.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -129,7 +129,8 @@ void loop()
{
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
//MQ2.serialDebug(); // Will print the table on the serial port
Serial.print(MQ2.readSensor()); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
Serial.print(MQ2.readSensor(false, correctionFactor)); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.println(" PPM");
delay(500); //Sampling frequency
}

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ3.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -81,17 +81,18 @@ void setup() {
void loop() {
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
float correctionFactor = 0; // Optional environmental correction
//https://jayconsystems.com/blog/understanding-a-gas-sensor
//Set math model to calculate the PPM concentration and the value of constants
MQ4.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)
MQ4.setA(-0.318); MQ4.setB(1.133); // A -> Slope, B -> Intersect with X - Axis
float LPG1 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float LPG1 = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
//Set math model to calculate the PPM concentration and the value of constants
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
float LPG2 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float LPG2 = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
// exposure to 2000 ppm of LPG gas is immediately dangerous to life and health. In this section
if(LPG1>=2000 || LPG2>=2000) Serial.println("Warning - Very high concentrations detected!");

@ -78,24 +78,25 @@ void setup() {
void loop() {
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
float correctionFactor = 0; // Optional environmental correction
MQ135.setA(605.18); MQ135.setB(-3.937); // Configure the equation to calculate CO concentration value
float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(77.255); MQ135.setB(-3.18); //Configure the equation to calculate Alcohol concentration value
float Alcohol = MQ135.readSensor(); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
float Alcohol = MQ135.readSensor(false, correctionFactor); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(110.47); MQ135.setB(-2.862); // Configure the equation to calculate CO2 concentration value
float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO2 = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(44.947); MQ135.setB(-3.445); // Configure the equation to calculate Toluen concentration value
float Toluen = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Toluen = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configure the equation to calculate NH4 concentration value
float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float NH4 = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
float Aceton = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Aceton = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.print("| "); Serial.print(CO);
Serial.print(" | "); Serial.print(Alcohol);
// Note: 400 Offset for CO2 source: https://github.com/miguel5612/MQSensorsLib/issues/29

@ -89,7 +89,8 @@ void setup() {
void loop() {
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -82,7 +82,8 @@ void setup() {
void loop() {
MQ136.update(); // Update data, the arduino will read the voltage from the analog pin
MQ136.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ136.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ136.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
MQ2.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ2.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ2.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -88,7 +88,8 @@ void setup() {
void loop() {
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ3.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -86,7 +86,8 @@ void setup() {
void loop() {
MQ303.update(); // Update data, the arduino will read the voltage from the analog pin
MQ303.readSensor(true); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ303.readSensor(true, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ303.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -95,7 +95,8 @@ void loop() {
// VH 0.9 Volts
analogWrite(5, 2); // 255 is 100%, 2.295 is aprox 0.9% of Duty cycle for 60s
MQ309.update(); // Update data, the arduino will read the voltage from the analog pin
MQ309.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ309.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ309.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}
@ -107,7 +108,8 @@ void loop() {
// VL 0.2 Volts
analogWrite(5, 1); // 255 is 100%, 0.51 is aprox 0.2% of Duty cycle for 120s
MQ309.update(); // Update data, the arduino will read the voltage from the analog pin
MQ309.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor2 = 0; // Optional environmental correction
MQ309.readSensor(false, correctionFactor2); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ309.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -79,6 +79,7 @@ void setup() {
void loop() {
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
float correctionFactor = 0; // Optional environmental correction
/*
Exponential regression:
@ -90,19 +91,19 @@ void loop() {
smoke | 30000000 | -8.308
*/
MQ4.setA(3811.9); MQ4.setB(-3.113); // Configure the equation to to calculate CH4 concentration
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float LPG = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
float CH4 = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CH4 = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ4.setA(200000000000000); MQ4.setB(-19.05); // Configure the equation to to calculate CH4 concentration
float CO = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ4.setA(60000000000); MQ4.setB(-14.01); // Configure the equation to to calculate CH4 concentration
float Alcohol = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Alcohol = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ4.setA(30000000); MQ4.setB(-8.308); // Configure the equation to to calculate CH4 concentration
float Smoke = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Smoke = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.print("| "); Serial.print(LPG);
Serial.print(" | "); Serial.print(CH4);

@ -81,7 +81,8 @@ void loop() {
//https://jayconsystems.com/blog/understanding-a-gas-sensor
MQ4.setA(-0.318); MQ4.setB(1.133); // A -> Slope, B -> Intersect with X - Axis
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
float LPG = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
// exposure to 2000 ppm of LPG gas is immediately dangerous to life and health. In this section
if(LPG>=2000) Serial.println("Warning - Very high concentrations detected!");

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ4.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ5.update(); // Update data, the arduino will read the voltage from the analog pin
MQ5.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ5.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ5.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -87,7 +87,8 @@ void setup() {
void loop() {
MQ6.update(); // Update data, the arduino will read the voltage from the analog pin
MQ6.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ6.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ6.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -100,7 +100,8 @@ void loop() {
// VH 5 Volts
analogWrite(5, 255); // 255 is DC 5V output
MQ7.update(); // Update data, the arduino will read the voltage from the analog pin
MQ7.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ7.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ7.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}
@ -112,7 +113,8 @@ void loop() {
// VH 1.4 Volts
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
MQ7.update(); // Update data, the arduino will read the voltage from the analog pin
MQ7.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor2 = 0; // Optional environmental correction
MQ7.readSensor(false, correctionFactor2); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ7.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -88,7 +88,8 @@ void setup() {
void loop() {
MQ8.update(); // Update data, the arduino will read the voltage from the analog pin
MQ8.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ8.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ8.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -78,6 +78,7 @@ void setup() {
void loop() {
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
float correctionFactor = 0; // Optional environmental correction
/*
Exponential regression:
GAS | a | b
@ -87,13 +88,13 @@ void loop() {
*/
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
float LPG = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float LPG = MQ9.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ9.setA(4269.6); MQ9.setB(-2.648); // Configure the equation to to calculate LPG concentration
float CH4 = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CH4 = MQ9.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ9.setA(599.65); MQ9.setB(-2.244); // Configure the equation to to calculate LPG concentration
float CO = MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO = MQ9.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.print("| "); Serial.print(LPG);
Serial.print(" | "); Serial.print(CH4);

@ -115,7 +115,8 @@ void loop() {
digitalWrite(PreaheatControlPin14, LOW);
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
MQ9.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ9.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ9.serialDebug(); // Will print the table on the serial port
}

@ -201,15 +201,16 @@ void readAllSensors()
MQ7.update();
MQ8.update();
MQ9.update();
float correctionFactor = 0; // Optional environmental correction
//Read the sensor and print in serial port
float MQ2Lecture = MQ2.readSensor();
float MQ3Lecture = MQ3.readSensor();
float MQ4Lecture = MQ4.readSensor();
float MQ5Lecture = MQ5.readSensor();
float MQ6Lecture = MQ6.readSensor();
float MQ7Lecture = MQ7.readSensor();
float MQ8Lecture = MQ8.readSensor();
float MQ9Lecture = MQ9.readSensor();
float MQ2Lecture = MQ2.readSensor(false, correctionFactor);
float MQ3Lecture = MQ3.readSensor(false, correctionFactor);
float MQ4Lecture = MQ4.readSensor(false, correctionFactor);
float MQ5Lecture = MQ5.readSensor(false, correctionFactor);
float MQ6Lecture = MQ6.readSensor(false, correctionFactor);
float MQ7Lecture = MQ7.readSensor(false, correctionFactor);
float MQ8Lecture = MQ8.readSensor(false, correctionFactor);
float MQ9Lecture = MQ9.readSensor(false, correctionFactor);
Serial.print("| "); Serial.print(MQ2Lecture);
Serial.print(" | "); Serial.print(MQ3Lecture);

@ -74,24 +74,25 @@ void loop() {
short adc0 = ads.readADC_SingleEnded(0);
float voltios = (adc0 * factorEscala)/1000.0;
MQ135.externalADCUpdate(voltios); // Update data, the arduino will read the voltage from the analog pin
float correctionFactor = 0; // Optional environmental correction
MQ135.setA(605.18); MQ135.setB(-3.937); // Configure the equation to calculate CO concentration value
float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(77.255); MQ135.setB(-3.18); //Configure the equation to calculate Alcohol concentration value
float Alcohol = MQ135.readSensor(); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
float Alcohol = MQ135.readSensor(false, correctionFactor); // SSensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(110.47); MQ135.setB(-2.862); // Configure the equation to calculate CO2 concentration value
float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float CO2 = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(44.947); MQ135.setB(-3.445); // Configure the equation to calculate Toluen concentration value
float Toluen = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Toluen = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configure the equation to calculate NH4 concentration value
float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float NH4 = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
float Aceton = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Aceton = MQ135.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
Serial.print("| "); Serial.print(CO);
Serial.print(" | "); Serial.print(Alcohol);
// Note: 200 Offset for CO2 source: https://github.com/miguel5612/MQSensorsLib/issues/29

@ -251,7 +251,8 @@ test(MQ303A_VoltResolution)
float vRes = 4.7;
MQ303A.setVoltResolution(vRes);
MQ303A.setADC(100); // provide dummy ADC value
MQ303A.readSensor(true); // dummy read for MQ303A
float correctionFactor = 0; // Optional environmental correction
MQ303A.readSensor(true, correctionFactor); // dummy read for MQ303A
assertEqualFloat(MQ303A.getVoltResolution(), vRes);
}

@ -99,7 +99,8 @@ void setup() {
void loop() {
int yourA2DValue = random(0, 1024); // 10-bit emulation
MQ3.setADC(yourA2DValue); // Update data, the arduino will read the voltage from the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
MQ3.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -88,7 +88,8 @@ void setup() {
//Read the sensor and print in serial port
//Lecture will be saved in lecture variable
MQ4.update();
float smokePPM = MQ4.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float correctionFactor = 0; // Optional environmental correction
float smokePPM = MQ4.readSensor(false, correctionFactor); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
if(smokePPM > 1000) {Serial.println("Warning: High concentrations of smoke detected");}
MQ4.serialDebug(); // Will print the table on the serial port
delay(400);

@ -1,5 +1,5 @@
name=MQUnifiedsensor
version=3.0.3
version=3.0.5
author= Miguel Califa <miguelangel5612@gmail.com>, Yersson Carrillo<miguelangel5612@gmail.com>, Ghiordy Contreras<miguelangel5612@gmail.com>
maintainer= Miguel Califa <miguelangel5612@gmail.com>
sentence= This library allows you to read the MQ sensors very easily.

@ -215,12 +215,13 @@ float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool in
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recommendation.
return _PPM;
}
float MQUnifiedsensor::readSensorR0Rs()
float MQUnifiedsensor::readSensorR0Rs(float correctionFactor)
{
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
_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
_ratio += correctionFactor;
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recommendation.
double ppm;
if(_regressionMethod == 1){
@ -242,7 +243,7 @@ float MQUnifiedsensor::readSensorR0Rs()
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recommendation.
return _PPM;
}
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
float MQUnifiedsensor::calibrate(float ratioInCleanAir, float correctionFactor) {
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
/*
V = I x R
@ -259,7 +260,8 @@ float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
float R0; //Define variable for R0
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
R0 = RS_air/ratioInCleanAir; //Calculate R0
R0 += correctionFactor;
if(R0 < 0) R0 = 0; //No negative values accepted.
return R0;
}

@ -34,9 +34,9 @@ class MQUnifiedsensor
void setADC(int value); //For external ADC Usage
//user functions
float calibrate(float ratioInCleanAir);
float calibrate(float ratioInCleanAir, float correctionFactor = 0.0);
float readSensor(bool isMQ303A = false, float correctionFactor = 0.0, bool injected=false);
float readSensorR0Rs();
float readSensorR0Rs(float correctionFactor = 0.0);
float validateEcuation(float ratioInput = 0);
//get function for info

Loading…
Cancel
Save