Updated and fixed typo examples

This commit is contained in:
miguel5612 2022-03-20 12:53:36 -05:00
parent 990e6878ef
commit 07b6948f76
28 changed files with 302 additions and 302 deletions

View File

@ -50,7 +50,7 @@ We present a unified library for MQ sensors, this library allows to read MQ sign
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
// Setup
MQ4.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
MQ4.setR0(3.86018237); // Value getted on calibration
// Loop
MQ4.init();

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values to get Alcohol concentration
MQ3.setA(0.3934); MQ3.setB(-1.504); //Configure the equation to calculate Alcohol concentration value
/*
Exponential regression:
Gas | a | b
@ -64,30 +64,30 @@ void setup() {
MQ3.init();
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
}
void loop() {
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
alcoholPPM = MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
Serial.print("Alcohol now (PPM): ");
Serial.println(alcoholPPM);
delay(500); //Sampling frequency

View File

@ -47,7 +47,7 @@ void setup() {
//Init serial port
Serial.begin(115200);
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ3.setRL(10);

View File

@ -61,7 +61,7 @@ void setup()
//Set math model to calculate the PPM concentration and the value of constants
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
MQ2.setA(987.99); MQ2.setB(-2.162); // Configurate the ecuation values to get H2 concentration
MQ2.setA(987.99); MQ2.setB(-2.162); // Configure the equation to to calculate H2 concentration
/*
Exponential regression:
@ -84,24 +84,24 @@ void setup()
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
Serial.print(".");
}
MQ2.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
//MQ2.serialDebug(true); uncomment if you want to print the table on the serial port
@ -127,9 +127,9 @@ void setup()
void loop()
{
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
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 and a and b values setted before or in the setup
Serial.print(MQ2.readSensor()); // 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

@ -40,7 +40,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
/*
Exponential regression:
Gas | a | b
@ -63,31 +63,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
void loop() {
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -40,7 +40,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
/*
Exponential regression:
Gas | a | b
@ -63,31 +63,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
void loop() {
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -43,24 +43,24 @@ void setup() {
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
Serial.print(".");
}
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
/*
@ -75,23 +75,23 @@ void setup() {
/************************************************************************************/
MQ4.init();
Serial.println("** Lectures from MQ-4**********");
Serial.println("** Values from MQ-4**********");
Serial.println("| LPG (Linear EQ) | LPG (Exponential EQ) |");
}
void loop() {
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
//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 and a and b values setted before or in the setup
float LPG1 = MQ4.readSensor(); // 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); // Configurate the ecuation values to get CH4 concentration
float LPG2 = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
// 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

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
Note: high concentration MQ-131 sensor.
@ -44,7 +44,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ131.setRegressionMethod(1); //_PPM = a*ratio^b
MQ131.setA(23.943); MQ131.setB(-1.11); // Configurate the ecuation values to get O3 concentration
MQ131.setA(23.943); MQ131.setB(-1.11); // Configure the equation to to calculate O3 concentration
/*
Exponential regression:
@ -65,32 +65,32 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ131.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ131.calibrate(RatioMQ131CleanAir);
Serial.print(".");
}
MQ131.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** 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 :)");
}
void loop() {
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
MQ131.update(); // Update data, the arduino will read the voltage from the analog pin
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
MQ131.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -89,13 +89,13 @@ void loop() {
float CO2 = MQ135.readSensor(); // 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 Tolueno = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Toluen = MQ135.readSensor(); // 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
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
float Acetona = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Aceton = MQ135.readSensor(); // 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
@ -106,9 +106,9 @@ void loop() {
https://www.lavanguardia.com/natural/20190514/462242832581/concentracion-dioxido-cabono-co2-atmosfera-bate-record-historia-humanidad.html
*/
Serial.print(" | "); Serial.print(CO2 + 400);
Serial.print(" | "); Serial.print(Tolueno);
Serial.print(" | "); Serial.print(Toluen);
Serial.print(" | "); Serial.print(NH4);
Serial.print(" | "); Serial.print(Acetona);
Serial.print(" | "); Serial.print(Aceton);
Serial.println(" |");
/*
Exponential regression:
@ -116,9 +116,9 @@ void loop() {
CO | 605.18 | -3.937
Alcohol | 77.255 | -3.18
CO2 | 110.47 | -2.862
Tolueno | 44.947 | -3.445
Toluen | 44.947 | -3.445
NH4 | 102.2 | -2.473
Acetona | 34.668 | -3.369
Aceton | 34.668 | -3.369
*/
delay(500); //Sampling frequency

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -81,7 +81,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
MQ135.setA(102.2); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
MQ135.setA(102.2); MQ135.setB(-2.473); // Configure the equation to to calculate NH4 concentration
/*
Exponential regression:
@ -89,9 +89,9 @@ void setup() {
CO | 605.18 | -3.937
Alcohol | 77.255 | -3.18
CO2 | 110.47 | -2.862
Tolueno | 44.947 | -3.445
Toluen | 44.947 | -3.445
NH4 | 102.2 | -2.473
Acetona | 34.668 | -3.369
Aceton | 34.668 | -3.369
*/
/***************************** MQ Init ********************************************/
@ -104,24 +104,24 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
Serial.print(".");
}
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ135.serialDebug(true);
// Set delay between sensor readings based on sensor details.
@ -138,8 +138,8 @@ void loop() {
float cFactor = 0;
if (!isnan(event.temperature) && !isnan(event.relative_humidity)) cFactor = getCorrectionFactor(event.temperature, event.relative_humidity);
Serial.print("Correction Factor: "); Serial.println(cFactor);
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ135.readSensor(false, cFactor); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
MQ135.readSensor(false, cFactor); // 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
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ135.setRegressionMethod(1); //_PPM = a*ratio^b
MQ135.setA(102.2); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
MQ135.setA(102.2); MQ135.setB(-2.473); // Configure the equation to to calculate NH4 concentration
/*
Exponential regression:
@ -50,9 +50,9 @@ void setup() {
CO | 605.18 | -3.937
Alcohol | 77.255 | -3.18
CO2 | 110.47 | -2.862
Tolueno | 44.947 | -3.445
Toluen | 44.947 | -3.445
NH4 | 102.2 | -2.473
Acetona | 34.668 | -3.369
Aceton | 34.668 | -3.369
*/
/***************************** MQ Init ********************************************/
@ -65,31 +65,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ135.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
Serial.print(".");
}
MQ135.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ135.serialDebug(true);
}
void loop() {
MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ135.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -14,7 +14,7 @@
by Miguel Califa
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -41,7 +41,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
/*
Exponential regression:
Gas | a | b
@ -62,32 +62,32 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ2.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ2.calibrate(RatioMQ2CleanAir);
Serial.print(".");
}
MQ2.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ2.serialDebug(true);
}
void loop() {
MQ2.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ2.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ2.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -41,7 +41,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
/*
Exponential regression:
Gas | a | b
@ -64,31 +64,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
}
void loop() {
MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ303.setRegressionMethod(1); //_PPM = a*ratio^b
MQ303.setA(6.2144); MQ303.setB(-2.894); // Configurate the ecuation values to get Isobutano concentration
MQ303.setA(6.2144); MQ303.setB(-2.894); // Configure the equation to to calculate Isobutano concentration
/*
Exponential regression:
@ -62,31 +62,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ303.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ303.calibrate(RatioMQ303CleanAir);
Serial.print(".");
}
MQ303.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ303.serialDebug(true);
}
void loop() {
MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ303.readSensor(true); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ303.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -44,7 +44,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
MQ309.setA(1000000); MQ309.setB(-4.01); // Configurate the ecuation values to get CO concentration
MQ309.setA(1000000); MQ309.setB(-4.01); // Configure the equation to calculate CO concentration value
/*
Exponential regression:
@ -65,24 +65,24 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ309.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ309.calibrate(RatioMQ309CleanAir);
Serial.print(".");
}
MQ309.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ309.serialDebug(true);
}
@ -94,8 +94,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 be read the voltage on the analog pin
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ309.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}
@ -106,8 +106,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 be read the voltage on the analog pin
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ309.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -53,32 +53,32 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
Serial.print(".");
}
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
Serial.println("*************** Lectures from MQ-4 **********************");
Serial.println("*************** Values from MQ-4 **********************");
Serial.println("| LPG | CH4 | CO | Alcohol | Smoke |");
}
void loop() {
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
/*
Exponential regression:
@ -89,20 +89,20 @@ void loop() {
Alcohol| 60000000000 | -14.01
smoke | 30000000 | -8.308
*/
MQ4.setA(3811.9); MQ4.setB(-3.113); // Configurate the ecuation values to get CH4 concentration
float LPG = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
float CH4 = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
MQ4.setA(200000000000000); MQ4.setB(-19.05); // Configurate the ecuation values to get CH4 concentration
float CO = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
MQ4.setA(60000000000); MQ4.setB(-14.01); // Configurate the ecuation values to get CH4 concentration
float Alcohol = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
MQ4.setA(30000000); MQ4.setB(-8.308); // Configurate the ecuation values to get CH4 concentration
float Smoke = MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
Serial.print("| "); Serial.print(LPG);
Serial.print(" | "); Serial.print(CH4);

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -52,36 +52,36 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
Serial.print(".");
}
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Lectures from MQ-4**********");
Serial.println("** Values from MQ-4**********");
Serial.println("| LPG |");
}
void loop() {
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
//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 and a and b values setted before or in the setup
float LPG = MQ4.readSensor(); // 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

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -41,7 +41,7 @@ void 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); // Configurate the ecuation values to get CH4 concentration
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
/*
Exponential regression:
Gas | a | b
@ -63,31 +63,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
Serial.print(".");
}
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ4.serialDebug(true);
}
void loop() {
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ4.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
MQ5.setA(1163.8); MQ5.setB(-3.874); // Configurate the ecuation values to get H2 concentration
MQ5.setA(1163.8); MQ5.setB(-3.874); // Configure the equation to to calculate H2 concentration
/*
Exponential regression:
Gas | a | b
@ -63,31 +63,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ5.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ5.calibrate(RatioMQ5CleanAir);
Serial.print(".");
}
MQ5.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ5.serialDebug(true);
}
void loop() {
MQ5.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ5.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ5.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configurate the ecuation values to get CH4 concentration
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configure the equation to to calculate CH4 concentration
/*
Exponential regression:
GAS | a | b
@ -63,31 +63,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ6.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ6.calibrate(RatioMQ6CleanAir);
Serial.print(".");
}
MQ6.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ6.serialDebug(true);
}
void loop() {
MQ6.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ6.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ6.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -19,7 +19,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -48,7 +48,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
MQ7.setA(99.042); MQ7.setB(-1.518); // Configurate the ecuation values to get CO concentration
MQ7.setA(99.042); MQ7.setB(-1.518); // Configure the equation to calculate CO concentration value
/*
Exponential regression:
@ -70,24 +70,24 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ7.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ7.calibrate(RatioMQ7CleanAir);
Serial.print(".");
}
MQ7.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ7.serialDebug(true);
}
@ -99,8 +99,8 @@ void loop() {
{
// VH 5 Volts
analogWrite(5, 255); // 255 is DC 5V output
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ7.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}
@ -111,8 +111,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 be read the voltage on the analog pin
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ7.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -42,7 +42,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
MQ8.setA(976.97); MQ8.setB(-0.688); // Configure the equation to to calculate H2 concentration
/*
Exponential regression:
@ -64,31 +64,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ8.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ8.calibrate(RatioMQ8CleanAir);
Serial.print(".");
}
MQ8.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ8.serialDebug(true);
}
void loop() {
MQ8.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ8.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ8.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -53,31 +53,31 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ9.calibrate(RatioMQ9CleanAir);
Serial.print(".");
}
MQ9.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
Serial.println("** Lectures from MQ-9 ****");
Serial.println("** Values from MQ-9 ****");
Serial.println("| LPG | CH4 | CO |");
}
void loop() {
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
/*
Exponential regression:
GAS | a | b
@ -86,14 +86,14 @@ void loop() {
CO | 599.65 | -2.244
*/
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
float LPG = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ9.setA(4269.6); MQ9.setB(-2.648); // Configurate the ecuation values to get LPG concentration
float CH4 = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
MQ9.setA(599.65); MQ9.setB(-2.244); // Configurate the ecuation values to get LPG concentration
float CO = MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in 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
Serial.print("| "); Serial.print(LPG);
Serial.print(" | "); Serial.print(CH4);

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -45,7 +45,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
/*
Exponential regression:
@ -65,10 +65,10 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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
@ -94,15 +94,15 @@ void setup() {
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ9.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ9.calibrate(RatioMQ9CleanAir);
Serial.print(".");
}
MQ9.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ9.serialDebug(true);
}
@ -114,8 +114,8 @@ void loop() {
digitalWrite(PreaheatControlPin5, HIGH);
digitalWrite(PreaheatControlPin14, LOW);
MQ9.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ9.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ9.serialDebug(); // Will print the table on the serial port
}

View File

@ -11,7 +11,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -61,50 +61,50 @@ void setup() {
//init the sensor
MQ2.init();
MQ2.setRegressionMethod(1); //_PPM = a*ratio^b
MQ2.setA(574.25); MQ2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
MQ2.setA(574.25); MQ2.setB(-2.222); // Configure the equation to to calculate LPG concentration
MQ2.setR0(9.659574468);
MQ3.init();
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values to get Alcohol concentration
MQ3.setA(0.3934); MQ3.setB(-1.504); //Configure the equation to calculate Alcohol concentration value
MQ3.setR0(3.86018237);
MQ4.init();
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configure the equation to to calculate CH4 concentration
MQ4.setR0(3.86018237);
MQ5.init();
MQ5.setRegressionMethod(1); //_PPM = a*ratio^b
MQ5.setA(97124); MQ5.setB(-4.918); // Configurate the ecuation values to get Alcohol concentration
MQ5.setA(97124); MQ5.setB(-4.918); //Configure the equation to calculate Alcohol concentration value
MQ5.setR0(71.100304);
MQ6.init();
MQ6.setRegressionMethod(1); //_PPM = a*ratio^b
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configurate the ecuation values to get CH4 concentration
MQ6.setA(2127.2); MQ6.setB(-2.526); // Configure the equation to to calculate CH4 concentration
MQ6.setR0(13.4285714);
MQ7.init();
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
MQ7.setA(99.042); MQ7.setB(-1.518); // Configurate the ecuation values to get CO concentration
MQ7.setA(99.042); MQ7.setB(-1.518); // Configure the equation to calculate CO concentration value
MQ7.setR0(4);
MQ8.init();
MQ8.setRegressionMethod(1); //_PPM = a*ratio^b
MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
MQ8.setA(976.97); MQ8.setB(-0.688); // Configure the equation to to calculate H2 concentration
MQ8.setR0(1);
MQ9.init();
MQ9.setRegressionMethod(1); //_PPM = a*ratio^b
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configure the equation to to calculate LPG concentration
MQ9.setR0(9.42857143);
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float MQ2calcR0 = 0,
@ -117,7 +117,7 @@ void setup() {
MQ9calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
//Update the voltage lectures
//Update the voltage Values
MQ2.update();
MQ3.update();
MQ4.update();
@ -164,7 +164,7 @@ void setup() {
//Print in serial monitor
Serial.println("MQ2 to MQ9 - lecture");
Serial.println("*************************** Lectures from MQ-board ***************************");
Serial.println("*************************** Values from MQ-board ***************************");
Serial.println("| LPG | Alcohol | CH4 | Alcohol | CH4 | CO | H2 | LPG |");
Serial.println("| MQ-2 | MQ-3 | MQ-4 | MQ-5 | MQ-6 | MQ-7 | MQ-8 | MQ-9 |");
//pinMode(calibration_button, INPUT);
@ -192,7 +192,7 @@ void loop() {
void readAllSensors()
{
//Update the voltage lectures
//Update the voltage Values
MQ2.update();
MQ3.update();
MQ4.update();

View File

@ -85,13 +85,13 @@ void loop() {
float CO2 = MQ135.readSensor(); // 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 Tolueno = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Toluen = MQ135.readSensor(); // 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
MQ135.setA(34.668); MQ135.setB(-3.369); // Configure the equation to calculate Aceton concentration value
float Acetona = MQ135.readSensor(); // Sensor will read PPM concentration using the model, a and b values set previously or from the setup
float Aceton = MQ135.readSensor(); // 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
@ -105,9 +105,9 @@ void loop() {
https://www.lavanguardia.com/natural/20190514/462242832581/concentracion-dioxido-cabono-co2-atmosfera-bate-record-historia-humanidad.html
*/
Serial.print(" | "); Serial.print(CO2 + 400);
Serial.print(" | "); Serial.print(Tolueno);
Serial.print(" | "); Serial.print(Toluen);
Serial.print(" | "); Serial.print(NH4);
Serial.print(" | "); Serial.print(Acetona);
Serial.print(" | "); Serial.print(Aceton);
Serial.println(" |");
/*
Exponential regression:
@ -115,9 +115,9 @@ void loop() {
CO | 605.18 | -3.937
Alcohol | 77.255 | -3.18
CO2 | 110.47 | -2.862
Tolueno | 44.947 | -3.445
Toluen | 44.947 | -3.445
NH4 | 102.2 | -2.473
Acetona | 34.668 | -3.369
Aceton | 34.668 | -3.369
*/
delay(500); //Sampling frequency

View File

@ -15,7 +15,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin - For this example this doesn't matter
Please make sure arduino A0 pin represents the analog input configured on #define pin - For this example this doesn't matter
You will connect your sensor to your external A2D Sensor
This example code is in the public domain.
@ -52,7 +52,7 @@ void setup() {
//Set math model to calculate the PPM concentration and the value of constants
MQ3.setRegressionMethod(1); //_PPM = a*ratio^b
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configure the equation to to calculate Benzene concentration
/*
Exponential regression:
Gas | a | b
@ -72,25 +72,25 @@ void setup() {
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
int yourA2DValue = random(0, 1024); // 10-bit emulation
MQ3.setADC(yourA2DValue);// Update data, the arduino will be read the voltage on the analog pin
MQ3.setADC(yourA2DValue);// Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ3.calibrate(RatioMQ3CleanAir);
Serial.print(".");
}
MQ3.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ3.serialDebug(true);
@ -98,8 +98,8 @@ void setup() {
void loop() {
int yourA2DValue = random(0, 1024); // 10-bit emulation
MQ3.setADC(yourA2DValue); // Update data, the arduino will be read the voltage on the analog pin
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
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
MQ3.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

View File

@ -11,7 +11,7 @@
Wiring:
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
Please take care, arduino A0 pin represent the analog input configured on #define pin
Please make sure arduino A0 pin represents the analog input configured on #define pin
This example code is in the public domain.
@ -37,7 +37,7 @@ void setup() {
Serial.begin(115200);
//Set math model to calculate the PPM concentration and the value of constants
MQ4.setRegressionMethod(1); //_PPM = a*ratio^b
MQ4.setA(30000000); MQ4.setB(-8.308); // Configurate the ecuation values to get CH4 concentration
MQ4.setA(30000000); MQ4.setB(-8.308); // Configure the equation to to calculate CH4 concentration
/*
Exponential regression:
Gas | a | b
@ -57,24 +57,24 @@ void setup() {
*/
/***************************** MQ CAlibration ********************************************/
// Explanation:
// In this routine the sensor will measure the resistance of the sensor supposing before was pre-heated
// and now is on clean air (Calibration conditions), and it will setup R0 value.
// We recomend execute this routine only on setup or on the laboratory and save on the eeprom of your arduino
// This routine not need to execute to every restart, you can load your R0 if you know the value
// 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.
// 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.");
float calcR0 = 0;
for(int i = 1; i<=10; i ++)
{
MQ4.update(); // Update data, the arduino will be read the voltage on the analog pin
MQ4.update(); // Update data, the arduino will read the voltage from the analog pin
calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
Serial.print(".");
}
MQ4.setR0(calcR0/10);
Serial.println(" done!.");
if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
if(calcR0 == 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(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);}
/***************************** MQ CAlibration ********************************************/
MQ4.serialDebug(true);
}
@ -88,7 +88,7 @@ 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 and a and b values setted before or in the setup
float smokePPM = MQ4.readSensor(); // 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);