diff --git a/docs/issues.md b/docs/issues.md index 13abc96..7b2aa12 100644 --- a/docs/issues.md +++ b/docs/issues.md @@ -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 diff --git a/examples/Alcoholimeter/Alcoholimeter.ino b/examples/Alcoholimeter/Alcoholimeter.ino index 6bca692..73c1b50 100644 --- a/examples/Alcoholimeter/Alcoholimeter.ino +++ b/examples/Alcoholimeter/Alcoholimeter.ino @@ -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 diff --git a/examples/ESP32/ESP32.ino b/examples/ESP32/ESP32.ino index cf7c862..7e16d47 100644 --- a/examples/ESP32/ESP32.ino +++ b/examples/ESP32/ESP32.ino @@ -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 } \ No newline at end of file diff --git a/examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino b/examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino index 9784e9d..8430341 100644 --- a/examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino +++ b/examples/ESP32/ESP32_WROOM_32D/ESP32_WROOM_32D.ino @@ -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 } diff --git a/examples/ESP8266/ESP8266.ino b/examples/ESP8266/ESP8266.ino index 99c1fb2..4eb03c7 100644 --- a/examples/ESP8266/ESP8266.ino +++ b/examples/ESP8266/ESP8266.ino @@ -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 } \ No newline at end of file diff --git a/examples/LinearVsExponential/LinearVsExponential.ino b/examples/LinearVsExponential/LinearVsExponential.ino index 9634e1a..75474d4 100644 --- a/examples/LinearVsExponential/LinearVsExponential.ino +++ b/examples/LinearVsExponential/LinearVsExponential.ino @@ -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!"); diff --git a/examples/MQ-135-ALL/MQ-135-ALL.ino b/examples/MQ-135-ALL/MQ-135-ALL.ino index 8220570..3ffae99 100644 --- a/examples/MQ-135-ALL/MQ-135-ALL.ino +++ b/examples/MQ-135-ALL/MQ-135-ALL.ino @@ -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 diff --git a/examples/MQ-135/MQ-135.ino b/examples/MQ-135/MQ-135.ino index dfbc5e4..27c61b4 100644 --- a/examples/MQ-135/MQ-135.ino +++ b/examples/MQ-135/MQ-135.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-136/MQ-136.ino b/examples/MQ-136/MQ-136.ino index 9c68f01..9b422ce 100644 --- a/examples/MQ-136/MQ-136.ino +++ b/examples/MQ-136/MQ-136.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-2/MQ-2.ino b/examples/MQ-2/MQ-2.ino index 28ade0c..296fbef 100644 --- a/examples/MQ-2/MQ-2.ino +++ b/examples/MQ-2/MQ-2.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-3/MQ-3.ino b/examples/MQ-3/MQ-3.ino index 1266d8e..9779c73 100644 --- a/examples/MQ-3/MQ-3.ino +++ b/examples/MQ-3/MQ-3.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-303A/MQ-303A.ino b/examples/MQ-303A/MQ-303A.ino index 65c3039..3bd4f40 100644 --- a/examples/MQ-303A/MQ-303A.ino +++ b/examples/MQ-303A/MQ-303A.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-309A/MQ-309A.ino b/examples/MQ-309A/MQ-309A.ino index 6141b39..d9d4038 100644 --- a/examples/MQ-309A/MQ-309A.ino +++ b/examples/MQ-309A/MQ-309A.ino @@ -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 } diff --git a/examples/MQ-4-ALL/MQ-4-ALL.ino b/examples/MQ-4-ALL/MQ-4-ALL.ino index 329e747..b9e48a5 100644 --- a/examples/MQ-4-ALL/MQ-4-ALL.ino +++ b/examples/MQ-4-ALL/MQ-4-ALL.ino @@ -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); diff --git a/examples/MQ-4-LINEAR/MQ-4-LINEAR.ino b/examples/MQ-4-LINEAR/MQ-4-LINEAR.ino index 15a5091..e1f45b4 100644 --- a/examples/MQ-4-LINEAR/MQ-4-LINEAR.ino +++ b/examples/MQ-4-LINEAR/MQ-4-LINEAR.ino @@ -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!"); diff --git a/examples/MQ-4/MQ-4.ino b/examples/MQ-4/MQ-4.ino index 0265adc..6341d18 100644 --- a/examples/MQ-4/MQ-4.ino +++ b/examples/MQ-4/MQ-4.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-5/MQ-5.ino b/examples/MQ-5/MQ-5.ino index add61e9..523b895 100644 --- a/examples/MQ-5/MQ-5.ino +++ b/examples/MQ-5/MQ-5.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-6/MQ-6.ino b/examples/MQ-6/MQ-6.ino index bc8308e..d6f2b13 100644 --- a/examples/MQ-6/MQ-6.ino +++ b/examples/MQ-6/MQ-6.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-7/MQ-7.ino b/examples/MQ-7/MQ-7.ino index 5a7eace..5da676a 100644 --- a/examples/MQ-7/MQ-7.ino +++ b/examples/MQ-7/MQ-7.ino @@ -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 } diff --git a/examples/MQ-8/MQ-8.ino b/examples/MQ-8/MQ-8.ino index 14658d3..2f91b32 100644 --- a/examples/MQ-8/MQ-8.ino +++ b/examples/MQ-8/MQ-8.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-9-ALL/MQ-9-ALL.ino b/examples/MQ-9-ALL/MQ-9-ALL.ino index 57ea32b..d1c7b14 100644 --- a/examples/MQ-9-ALL/MQ-9-ALL.ino +++ b/examples/MQ-9-ALL/MQ-9-ALL.ino @@ -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); diff --git a/examples/MQ-9/MQ-9.ino b/examples/MQ-9/MQ-9.ino index d7c3197..595c50a 100644 --- a/examples/MQ-9/MQ-9.ino +++ b/examples/MQ-9/MQ-9.ino @@ -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 } \ No newline at end of file diff --git a/examples/MQ-Board/MQ-Board.ino b/examples/MQ-Board/MQ-Board.ino index be2b3ee..ce78fce 100644 --- a/examples/MQ-Board/MQ-Board.ino +++ b/examples/MQ-Board/MQ-Board.ino @@ -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); diff --git a/examples/MQ135-ADS1115/MQ135-ADS1115.ino b/examples/MQ135-ADS1115/MQ135-ADS1115.ino index 0a2aded..2a4dc3a 100644 --- a/examples/MQ135-ADS1115/MQ135-ADS1115.ino +++ b/examples/MQ135-ADS1115/MQ135-ADS1115.ino @@ -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 diff --git a/examples/UnitTesting/UnitTesting.ino b/examples/UnitTesting/UnitTesting.ino index 67322b8..9fd8569 100644 --- a/examples/UnitTesting/UnitTesting.ino +++ b/examples/UnitTesting/UnitTesting.ino @@ -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); } diff --git a/examples/external_A2D/external_A2D.ino b/examples/external_A2D/external_A2D.ino index b3249e9..6f2938a 100644 --- a/examples/external_A2D/external_A2D.ino +++ b/examples/external_A2D/external_A2D.ino @@ -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 } \ No newline at end of file diff --git a/examples/smokeDetector/smokeDetector.ino b/examples/smokeDetector/smokeDetector.ino index 60e52a4..17b8fe9 100644 --- a/examples/smokeDetector/smokeDetector.ino +++ b/examples/smokeDetector/smokeDetector.ino @@ -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); diff --git a/library.properties b/library.properties index b1e7c3a..1100483 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=MQUnifiedsensor -version=3.0.3 +version=3.0.5 author= Miguel Califa , Yersson Carrillo, Ghiordy Contreras maintainer= Miguel Califa sentence= This library allows you to read the MQ sensors very easily. diff --git a/src/MQUnifiedsensor.cpp b/src/MQUnifiedsensor.cpp index b484c41..5b282c7 100644 --- a/src/MQUnifiedsensor.cpp +++ b/src/MQUnifiedsensor.cpp @@ -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; } diff --git a/src/MQUnifiedsensor.h b/src/MQUnifiedsensor.h index 24874c2..11637c2 100644 --- a/src/MQUnifiedsensor.h +++ b/src/MQUnifiedsensor.h @@ -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