Compare commits

..

1 Commits

Author SHA1 Message Date
c066b2ec1c Correct typos in source and example files 2025-06-04 18:09:40 -05:00
33 changed files with 102 additions and 162 deletions

View File

@ -68,7 +68,6 @@ float ppmCH4 = MQ4.readSensor();
* AO -> Analog Output of the sensor
##### Data of board that you should have
* RL Value in KOhms
* If the sensor uses a different supply voltage than the ADC reference, call `yourSensor.setVCC(<voltage>);`
##### Graph
![Wiring_MQSensor](https://raw.githubusercontent.com/miguel5612/MQSensorsLib_Docs/master/static/img/Points_explanation.jpeg)
#### RS/R0 value (From datasheet of your sensor)
@ -174,10 +173,6 @@ Examples/MQ-board.ino
* [Data sheets](https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Datasheets) - Curves and behavior for each sensor, using logarithmic graphs.
* [Main purpose](https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/bg.jpg) - Every sensor has high sensibility for a specific gas or material.
## Issues
Consulte [docs/issues.md](docs/issues.md) para un resumen de los problemas abiertos y sus soluciones.
## Contributing
Please read [CONTRIBUTING.md](https://github.com/miguel5612/MQSensorsLib/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

View File

@ -1,31 +0,0 @@
# Issues y soluciones
Este documento resume los problemas reportados en el repositorio y las soluciones propuestas o implementadas.
## Abiertos
### #75 MQ-3 sensor and CH4 gas reading 'ovf' failure
**Estado:** abierto
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`.
### #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
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.
### #67 Sensor won't finish the Calibration process if done in clean air
**Estado:** abierto
Se reporta que la calibración se detiene mostrando un mensaje de "Conection issue" cuando se intenta calibrar el sensor MQ-135 en aire limpio. La recomendación del mantenedor es revisar la conexión física y probar el sensor con un programa básico para asegurar su correcto funcionamiento antes de usar la librería. Aún no se ha implementado un cambio en el código.
## Cerrados destacados
Para obtener más información sobre todos los issues cerrados, consulte la página de [Issues en GitHub](https://github.com/miguel5612/MQSensorsLib/issues?q=is%3Aissue+is%3Aclosed).

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,8 +80,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 ********************************************/
}

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

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,8 +79,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);
}

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,8 +79,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);
}

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 ********************************************/
/*

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 |");

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,8 +81,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);
}

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,8 +74,8 @@ 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);
}

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);

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,8 +80,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);
}

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() {
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);
}

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);
}

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 **********************");

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**********");

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,8 +79,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);
}

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,8 +79,8 @@ 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);
}

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,8 +79,8 @@ 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);
}

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);
}

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,8 +80,8 @@ 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);
}

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 |");

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);
}

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

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 |");

View File

@ -237,24 +237,15 @@ test(MQ303A_Ethanol)
{
MQ303A.setRegressionMethod(1); //_PPM = a*ratio^b
MQ303A.setA(3.4916); MQ303A.setB(-2.432); // Configure the equation to to calculate Ethanol concentration
MQ303A.init();
MQ303A.init();
MQ303A.setR0(10);
int ppmExp=944;
int PPM = MQ303A.setRsR0RatioGetPPM(0.1); // Send and Rs/R0 and return PPM (Using datasheet)
assertEqual(PPM,ppmExp);
}
test(MQ303A_VoltResolution)
{
float vRes = 4.7;
MQ303A.setVoltResolution(vRes);
MQ303A.setADC(100); // provide dummy ADC value
MQ303A.readSensor(true); // dummy read for MQ303A
assertEqualFloat(MQ303A.getVoltResolution(), vRes);
}
test(MQ309A_CO)
{
MQ309A.setRegressionMethod(1); //_PPM = a*ratio^b

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);

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);
}

View File

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

@ -10,7 +10,6 @@ MQUnifiedsensor::MQUnifiedsensor(String Placa, float Voltage_Resolution, int ADC
//this->_type = type; //MQ-2, MQ-3 ... MQ-309A
//this->_placa = Placa;
this-> _VOLT_RESOLUTION = Voltage_Resolution;
this-> _VCC = Voltage_Resolution;
this-> _ADC_Bit_Resolution = ADC_Bit_Resolution;
}
MQUnifiedsensor::MQUnifiedsensor(String Placa, String type) {
@ -42,10 +41,6 @@ void MQUnifiedsensor::setVoltResolution(float voltage_resolution)
{
_VOLT_RESOLUTION = voltage_resolution;
}
void MQUnifiedsensor::setVCC(float vcc)
{
_VCC = vcc;
}
void MQUnifiedsensor::setPin(int pin) {
this->_pin = pin;
}
@ -64,10 +59,6 @@ float MQUnifiedsensor::getVoltResolution()
{
return _VOLT_RESOLUTION;
}
float MQUnifiedsensor::getVCC()
{
return _VCC;
}
String MQUnifiedsensor::getRegressionMethod()
{
if(_regressionMethod == 1) return "Exponential";
@ -94,8 +85,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
Serial.println("Contributors: Andres A. Martinez - Juan A. Rodríguez - Mario A. Rodríguez O ");
Serial.print("Sensor: "); Serial.println(_type);
Serial.print("ADC voltage: "); Serial.print(_VOLT_RESOLUTION); Serial.println(" VDC");
Serial.print("Sensor supply (VCC): "); Serial.print(_VCC); Serial.println(" VDC");
Serial.print("Supply voltage: "); Serial.print(_VOLT_RESOLUTION); Serial.println(" VDC");
Serial.print("ADC Resolution: "); Serial.print(_ADC_Bit_Resolution); Serial.println(" Bits");
Serial.print("R0: "); Serial.print(_R0); Serial.println("");
Serial.print("RL: "); Serial.print(_RL); Serial.println("");
@ -116,7 +106,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
else
{
Serial.print("|"); Serial.print(_adc); Serial.print("| v = ADC*"); Serial.print(_VOLT_RESOLUTION); Serial.print("/"); Serial.print((pow(2, _ADC_Bit_Resolution)) - 1); Serial.print(" | "); Serial.print(_sensor_volt);
Serial.print(" | RS = ((" ); Serial.print(_VCC ); Serial.print("*RL)/Voltage) - RL| "); Serial.print(_RS_Calc); Serial.print(" | Ratio = RS/R0| ");
Serial.print(" | RS = ((" ); Serial.print(_VOLT_RESOLUTION ); Serial.print("*RL)/Voltage) - RL| "); Serial.print(_RS_Calc); Serial.print(" | Ratio = RS/R0| ");
Serial.print(_ratio); Serial.print( " | ");
if(_regressionMethod == 1) Serial.print("ratio*a + b");
else Serial.print("pow(10, (log10(ratio)-b)/a)");
@ -152,43 +142,41 @@ float MQUnifiedsensor::validateEcuation(float ratioInput)
float MQUnifiedsensor::readSensor(bool isMQ303A, float correctionFactor, bool injected)
{
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
float voltRes = _VOLT_RESOLUTION; // preserve global resolution
if(isMQ303A) {
voltRes = voltRes - 0.45; //Calculations for RS using mq303a sensor look wrong #42
_VOLT_RESOLUTION = _VOLT_RESOLUTION - 0.45; //Calculations for RS using mq303a sensor look wrong #42
}
_RS_Calc = ((_VCC*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
if(!injected) _ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
_ratio += correctionFactor;
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
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recommendation.
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analysis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear equation
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(_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.
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recommendation.
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recommendation.
return _PPM;
}
float MQUnifiedsensor::readSensorR0Rs()
{
//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
_RS_Calc = ((_VOLT_RESOLUTION*_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
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recommendation.
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analysis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear equation
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(_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.
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recommendation.
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recommendation.
return _PPM;
}
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
@ -206,7 +194,7 @@ float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
*/
float RS_air; //Define variable for sensor resistance
float R0; //Define variable for R0
RS_air = ((_VCC*_RL)/_sensor_volt)-_RL; //Calculate RS in fresh air
RS_air = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Calculate RS in fresh air
if(RS_air < 0) RS_air = 0; //No negative values accepted.
R0 = RS_air/ratioInCleanAir; //Calculate R0
if(R0 < 0) R0 = 0; //No negative values accepted.
@ -243,7 +231,7 @@ float MQUnifiedsensor:: setRsR0RatioGetPPM(float value)
float MQUnifiedsensor::getRS()
{
//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
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
return _RS_Calc;
}

View File

@ -22,7 +22,6 @@ class MQUnifiedsensor
void setB(float b);
void setRegressionMethod(int regressionMethod);
void setVoltResolution(float voltage_resolution = 5);
void setVCC(float vcc = 5);
void setPin(int pin = 1);
void serialDebug(bool onSetup = false); //Show on serial port information about sensor
void setADC(int value); //For external ADC Usage
@ -39,7 +38,6 @@ class MQUnifiedsensor
float getR0();
float getRL();
float getVoltResolution();
float getVCC();
String getRegressionMethod();
float getVoltage(bool read = true, bool injected = false, int value = 0);
float stringTofloat(String & str);
@ -53,7 +51,6 @@ class MQUnifiedsensor
byte _pin = 1;
byte _firstFlag = false;
float _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
float _VCC = 5.0; // Sensor supply voltage
float _RL = 10; //Value in KiloOhms
byte _ADC_Bit_Resolution = 10;
byte _regressionMethod = 1; // 1 -> Exponential || 2 -> Linear