Compare commits

...

11 Commits

Author SHA1 Message Date
59a2e5852e Merge pull request #85 from miguel5612/codex/implement-temperature-and-humidity-correction-for-all-exampl
Add optional correction factor to API
2025-06-04 19:30:15 -05:00
30c0979cb4 Extend API for optional correction factor 2025-06-04 19:29:44 -05:00
6f9b00666e Merge pull request #84 from miguel5612/codex/verificar-resolución-del-error--ovf--en-sensor-mq-3
Fix overflow for CH4 calculations
2025-06-04 18:57:29 -05:00
d2e0be3651 Prevent CH4 overflow 2025-06-04 18:54:34 -05:00
3cd2fd8e7d Merge pull request #83 from miguel5612/codex/verificar-requisitos-de-librería-para-arduino
Fix Arduino lint errors and bump library version
2025-06-04 18:34:59 -05:00
2bdb91c1b5 Add keywords file and bump version 2025-06-04 18:34:45 -05:00
42689ff5f3 Merge pull request #81 from miguel5612/codex/actualizar-comentarios-de-pin10-a-pin14
Update UnitTesting pin comments
2025-06-04 18:10:12 -05:00
ea48475a3c Merge pull request #82 from miguel5612/codex/fix-typos-in-repository-files
Fix typos across library
2025-06-04 18:09:59 -05:00
c066b2ec1c Correct typos in source and example files 2025-06-04 18:09:40 -05:00
144f480f6f Fix analog input comments in UnitTesting example 2025-06-04 18:09:24 -05:00
46d416abad Merge pull request #77 from miguel5612/codex/resolver-issues-del-repositorio
Fix RS formula by using VCC
2025-06-04 18:08:28 -05:00
33 changed files with 298 additions and 180 deletions

View File

@ -5,19 +5,21 @@ Este documento resume los problemas reportados en el repositorio y las solucione
## Abiertos
### #75 MQ-3 sensor and CH4 gas reading 'ovf' failure
**Estado:** abierto
**Estado:** resuelto en la rama `main`
El usuario reporta desbordamiento ("ovf") al utilizar valores muy altos en `setA` y `setB` para leer CH4 con un sensor MQ-3. La solución propuesta es revisar los valores utilizados en `setA` y `setB`, ya que `2*10^31` en C++ no corresponde a `2e31`. Se recomienda usar notación exponencial (`2e31`) o `pow(10,31)` y comprobar que los parámetros no excedan el rango de `float`.
**Actualización:** se añadieron validaciones de entrada, predicción de desbordamiento mediante logaritmos y verificación del resultado final para evitar valores "ovf" incluso con coeficientes muy altos. Las nuevas funciones limitan `setA` y `setB` y emplean cálculos en doble precisión.
### #74 possible error in the calculation formula for `_RS_Calc`
**Estado:** resuelto en la rama `work`
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

View File

@ -66,7 +66,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -80,14 +80,15 @@ void setup() {
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
}
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

View File

@ -65,7 +65,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -79,15 +79,16 @@ void setup() {
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
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
}

View File

@ -86,7 +86,7 @@ void setup()
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -100,8 +100,8 @@ void setup()
MQ2.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
//MQ2.serialDebug(true); uncomment if you want to print the table on the serial port
@ -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
}

View File

@ -65,7 +65,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -79,15 +79,16 @@ void setup() {
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
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
}

View File

@ -45,7 +45,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -59,8 +59,8 @@ void setup() {
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
/*
@ -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!");

View File

@ -67,7 +67,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -81,8 +81,8 @@ void setup() {
MQ131.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ131.serialDebug(true);
Serial.println("Ignore Ratio = RS/R0, for this example we will use readSensorR0Rs, the ratio calculated will be R0/Rs. Thanks :)");

View File

@ -55,7 +55,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -69,8 +69,8 @@ void setup() {
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Values from MQ-135 ****");
Serial.println("| CO | Alcohol | CO2 | Toluen | NH4 | Aceton |");
@ -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

View File

@ -106,7 +106,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -120,8 +120,8 @@ void setup() {
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ135.serialDebug(true);
// Set delay between sensor readings based on sensor details.

View File

@ -67,7 +67,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -81,15 +81,16 @@ void setup() {
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ135.serialDebug(true);
}
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
}

View File

@ -60,7 +60,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -74,15 +74,16 @@ void setup() {
MQ136.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ136.serialDebug(true);
}
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
}

View File

@ -64,7 +64,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -78,8 +78,8 @@ void setup() {
MQ2.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ2.serialDebug(true);
@ -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
}

View File

@ -66,7 +66,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -80,15 +80,16 @@ void setup() {
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
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
}

View File

@ -64,7 +64,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -78,15 +78,16 @@ void setup() {
MQ303.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ303.serialDebug(true);
}
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
}

View File

@ -67,7 +67,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -81,8 +81,8 @@ void setup() {
MQ309.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ309.serialDebug(true);
}
@ -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
}

View File

@ -55,7 +55,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -69,8 +69,8 @@ void setup() {
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
Serial.println("*************** Values from MQ-4 **********************");
@ -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);

View File

@ -54,7 +54,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -68,8 +68,8 @@ void setup() {
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Values from MQ-4**********");
@ -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!");

View File

@ -65,7 +65,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -79,15 +79,16 @@ void setup() {
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ4.serialDebug(true);
}
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
}

View File

@ -65,7 +65,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -79,15 +79,16 @@ void setup() {
MQ5.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ5.serialDebug(true);
}
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
}

View File

@ -65,7 +65,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -79,15 +79,16 @@ void setup() {
MQ6.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ6.serialDebug(true);
}
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
}

View File

@ -72,7 +72,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -86,8 +86,8 @@ void setup() {
MQ7.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ7.serialDebug(true);
}
@ -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
}

View File

@ -66,7 +66,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -80,15 +80,16 @@ void setup() {
MQ8.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ8.serialDebug(true);
}
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
}

View File

@ -55,7 +55,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -69,8 +69,8 @@ void setup() {
MQ9.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Values from MQ-9 ****");
Serial.println("| LPG | CH4 | CO |");
@ -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);

View File

@ -67,7 +67,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
// ISSUE 44 - MQ9 needs a low/high temperature cycle like MQ7 #44
@ -101,8 +101,8 @@ void setup() {
MQ9.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ9.serialDebug(true);
}
@ -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
}

View File

@ -103,7 +103,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -158,8 +158,8 @@ void setup() {
Serial.print(MQ8calcR0/10); Serial.print(" | ");
Serial.print(MQ9calcR0/10); Serial.println(" |");
if(isinf(MQ2calcR0) || isinf(MQ3calcR0) || isinf(MQ4calcR0) || isinf(MQ5calcR0) || isinf(MQ6calcR0) || isinf(MQ7calcR0) || isinf(MQ8calcR0) || isinf(MQ9calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(MQ2calcR0 == 0 || MQ3calcR0 == 0 || MQ4calcR0 == 0 || MQ5calcR0 == 0 || MQ6calcR0 == 0 || MQ7calcR0 == 0 || MQ8calcR0 == 0 || MQ9calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
if(isinf(MQ2calcR0) || isinf(MQ3calcR0) || isinf(MQ4calcR0) || isinf(MQ5calcR0) || isinf(MQ6calcR0) || isinf(MQ7calcR0) || isinf(MQ8calcR0) || isinf(MQ9calcR0)) {Serial.println("Warning: Connection issue found, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(MQ2calcR0 == 0 || MQ3calcR0 == 0 || MQ4calcR0 == 0 || MQ5calcR0 == 0 || MQ6calcR0 == 0 || MQ7calcR0 == 0 || MQ8calcR0 == 0 || MQ9calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
//Print in serial monitor
@ -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);

View File

@ -62,8 +62,8 @@ void setup(void)
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Values from MQ-135 ****");
Serial.println("| CO | Alcohol | CO2 | Toluen | NH4 | Aceton |");
@ -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

View File

@ -27,11 +27,11 @@
#define Pin7 (A7) //Analog input 7 of your arduino
#define Pin8 (A8) //Analog input 8 of your arduino
#define Pin9 (A9) //Analog input 9 of your arduino
#define Pin10 (A10) //Analog input 9 of your arduino
#define Pin11 (A11) //Analog input 9 of your arduino
#define Pin12 (A12) //Analog input 9 of your arduino
#define Pin13 (A13) //Analog input 9 of your arduino
#define Pin14 (A14) //Analog input 9 of your arduino
#define Pin10 (A10) //Analog input 10 of your arduino
#define Pin11 (A11) //Analog input 11 of your arduino
#define Pin12 (A12) //Analog input 12 of your arduino
#define Pin13 (A13) //Analog input 13 of your arduino
#define Pin14 (A14) //Analog input 14 of your arduino
#define PWMPin (5) // Pin connected to mosfet
/***********************Software Related Macros************************************/
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
@ -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);
}

View File

@ -37,7 +37,7 @@
//Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 -> This value can have any number, we recomend use A0
#define pin A0 //Analog input 0 -> This value can have any number, we recommend use A0
#define type "MQ-3 With A2D External connected" //MQ3
#define ADC_Bit_Resolution 10 // Resolution of your external A2D
#define RatioMQ3CleanAir 60 //RS / R0 = 60 ppm
@ -74,7 +74,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -89,8 +89,8 @@ void setup() {
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
@ -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
}

View File

@ -59,7 +59,7 @@ void setup() {
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposedly before being pre-heated
// and on clean air (Calibration conditions), setting up R0 value.
// We recomend executing this routine only on setup in laboratory conditions.
// We recommend executing this routine only on setup in laboratory conditions.
// This routine does not need to be executed on each restart, you can load your R0 value from eeprom.
// Acknowledgements: https://jayconsystems.com/blog/understanding-a-gas-sensor
Serial.print("Calibrating please wait.");
@ -73,8 +73,8 @@ void setup() {
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
if(isinf(calcR0)) {Serial.println("Warning: Connection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 0){Serial.println("Warning: Connection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
/***************************** MQ CAlibration ********************************************/
MQ4.serialDebug(true);
}
@ -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);

29
keywords.txt Normal file
View File

@ -0,0 +1,29 @@
MQUnifiedsensor KEYWORD1
init KEYWORD2
update KEYWORD2
externalADCUpdate KEYWORD2
setR0 KEYWORD2
setRL KEYWORD2
setA KEYWORD2
setB KEYWORD2
setRegressionMethod KEYWORD2
setVoltResolution KEYWORD2
setVCC KEYWORD2
setPin KEYWORD2
setADC KEYWORD2
serialDebug KEYWORD2
calibrate KEYWORD2
readSensor KEYWORD2
readSensorR0Rs KEYWORD2
validateEcuation KEYWORD2
getVoltage KEYWORD2
setRsR0RatioGetPPM KEYWORD2
getRS KEYWORD2
stringTofloat KEYWORD2
getA KEYWORD2
getB KEYWORD2
getR0 KEYWORD2
getRL KEYWORD2
getVoltResolution KEYWORD2
getVCC KEYWORD2
getRegressionMethod KEYWORD2

View File

@ -1,5 +1,5 @@
name=MQUnifiedsensor
version=3.0.1
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.

View File

@ -1,4 +1,6 @@
#include "MQUnifiedsensor.h"
#include <float.h>
#include <math.h>
#define retries 2
#define retry_interval 20
@ -21,11 +23,39 @@ void MQUnifiedsensor::init()
{
pinMode(_pin, INPUT);
}
static inline double safePow(double base, double exp){
if(exp == 0.0) return 1.0;
if(exp == 1.0) return base;
if(exp == 2.0) return base * base;
return pow(base, exp);
}
static inline bool willOverflow(double log_ppm){
static const double maxLog = log10((double)FLT_MAX);
static const double minLog = log10((double)FLT_MIN);
return (log_ppm > maxLog || log_ppm < minLog);
}
void MQUnifiedsensor::setA(float a) {
this->_a = a;
if(isinf(a) || isnan(a)) {
this->_a = 0;
} else if(a > MQ_MAX_A) {
this->_a = MQ_MAX_A;
} else if(a < -MQ_MAX_A) {
this->_a = -MQ_MAX_A;
} else {
this->_a = a;
}
}
void MQUnifiedsensor::setB(float b) {
this->_b = b;
if(isinf(b) || isnan(b)) {
this->_b = 0;
} else if(b > MQ_MAX_B) {
this->_b = MQ_MAX_B;
} else if(b < -MQ_MAX_B) {
this->_b = -MQ_MAX_B;
} else {
this->_b = b;
}
}
void MQUnifiedsensor::setR0(float R0) {
this->_R0 = R0;
@ -134,20 +164,23 @@ void MQUnifiedsensor::externalADCUpdate(float volt)
}
float MQUnifiedsensor::validateEcuation(float ratioInput)
{
//Serial.print("Ratio input: "); Serial.println(ratioInput);
//Serial.print("a: "); Serial.println(_a);
//Serial.print("b: "); Serial.println(_b);
//Usage of this function: Unit test on ALgorithmTester example;
if(_regressionMethod == 1) _PPM= _a*pow(ratioInput, _b);
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor
double ppm_log = (log10(ratioInput)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
double ppm;
if(_regressionMethod == 1){
if(ratioInput <= 0 || _a == 0) return 0;
double logppm = log10((double)_a) + (double)_b * log10((double)ratioInput);
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
//Serial.println("Regression Method: "); Serial.println(_regressionMethod);
//Serial.println("Result: "); Serial.println(_PPM);
return _PPM;
else
{
if(ratioInput <= 0 || _a == 0) return 0;
double logppm = (log10((double)ratioInput)-(double)_b)/(double)_a;
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
if(isinf(ppm) || isnan(ppm)) ppm = FLT_MAX;
_PPM = (float)ppm;
return _PPM;
}
float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool injected)
{
@ -161,37 +194,56 @@ float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool in
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;
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
double ppm_log = (log10(_ratio)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recommendation.
double ppm;
if(_regressionMethod == 1){
if(_ratio <= 0 || _a == 0) return 0;
double logppm = log10((double)_a) + (double)_b * log10((double)_ratio);
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
else
{
if(_ratio <= 0 || _a == 0) return 0;
double logppm = (log10((double)_ratio)-(double)_b)/(double)_a;
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
if(ppm < 0) ppm = 0; //No negative values accepted or upper datasheet recommendation.
if(isinf(ppm) || isnan(ppm)) ppm = FLT_MAX;
_PPM = (float)ppm;
//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
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
double ppm_log = (log10(_ratio)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
_ratio += correctionFactor;
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recommendation.
double ppm;
if(_regressionMethod == 1){
if(_ratio <= 0 || _a == 0) return 0;
double logppm = log10((double)_a) + (double)_b * log10((double)_ratio);
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
else
{
if(_ratio <= 0 || _a == 0) return 0;
double logppm = (log10((double)_ratio)-(double)_b)/(double)_a;
if(willOverflow(logppm)) ppm = (logppm > 0) ? FLT_MAX : 0.0;
else ppm = safePow(10.0, logppm);
}
if(ppm < 0) ppm = 0; //No negative values accepted or upper datasheet recommendation.
if(isinf(ppm) || isnan(ppm)) ppm = FLT_MAX;
_PPM = (float)ppm;
//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
@ -208,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;
}

View File

@ -3,6 +3,12 @@
#include <Arduino.h>
#include <stdint.h>
#include <float.h>
#include <math.h>
// Maximum coefficients allowed for the regression model
#define MQ_MAX_A 1e30
#define MQ_MAX_B 100.0
/***********************Software Related Macros************************************/
@ -28,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