Added MQ-8 and MQ-9

This commit is contained in:
miguel5612 2020-03-26 13:09:10 -05:00
parent fad888dca4
commit f8a57bbdff
3 changed files with 142 additions and 150 deletions

View File

@ -1,7 +1,7 @@
/* /*
MQUnifiedsensor Library - reading an MQ131 MQUnifiedsensor Library - reading an MQ9
Demonstrates the use a MQ131 sensor. Demonstrates the use a MQ9 sensor.
Library originally added 01 may 2019 Library originally added 01 may 2019
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
@ -9,6 +9,10 @@
modified 23 May 2019 modified 23 May 2019
by Miguel Califa by Miguel Califa
Updated library usage
modified 26 March 2020
by Miguel Califa
This example code is in the public domain. This example code is in the public domain.
*/ */
@ -17,61 +21,55 @@
#include <MQUnifiedsensor.h> #include <MQUnifiedsensor.h>
//Definitions //Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino #define pin A0 //Analog input 0 of your arduino
#define type 131 //MQ131 #define type "MQ-8" //MQ9
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
//#define calibration_button 13 //Pin to calibrate your sensor //#define calibration_button 13 //Pin to calibrate your sensor
//Declare Sensor //Declare Sensor
MQUnifiedsensor MQ131(pin, type); MQUnifiedsensor MQ9(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
//Variables
float NOx, CL2, O3;
void setup() { void setup() {
//Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port Serial.begin(9600); //Init serial port
//init the sensor
/***************************** MQInicializar**************************************** //Set math model to calculate the PPM concentration and the value of constants
Input: pin, type MQ9.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
Output: MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
Remarks: This function create the sensor object.
************************************************************************************/ /*
MQ131.inicializar(); Exponential regression:
//pinMode(calibration_button, INPUT); GAS | a | b
LPG | 1000.5 | -2.186
CH4 | 4269.6 | -2.648
CO | 599.65 | -2.244
*/
// Calibration setup
MQ9.setR0(9.42857143);
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ9.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.serialDebug(true);
} }
void loop() { void loop() {
MQ131.update(); // Update data, the arduino will be read the voltaje in the analog pin 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
// Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: MQ9.serialDebug(); // Will print the table on the serial port
MQ131.setRL(10); delay(500); //Sampling frequency
*/ }
/*
//Rutina de calibracion - Uncomment if you need (setup too and header)
if(calibration_button)
{
float R0 = MQ131.calibrate();
MQ131.setR0(R0);
}
*/
/***************************** MQReadSensor ****************************************
Input: Gas - Serial print flag
Output: Value in PPM
Remarks: This function use readPPM to read the value in PPM the gas in the air.
************************************************************************************/
//Read the sensor and print in serial port
//Lecture will be saved in lecture variable
//float lecture = MQ131.readSensor("", true); // Return O3 concentration
// Options, uncomment where you need
NOx = MQ131.readSensor("NOx"); // Return NOx concentration
CL2 = MQ131.readSensor("CL2"); // Return CL2 concentration
O3 = MQ131.readSensor("O3"); // Return O3 concentration
Serial.println("***************************");
Serial.println("Lectures for MQ-131");
Serial.print("Volt: ");Serial.print(MQ131.getVoltage(false));Serial.println(" V");
Serial.print("R0: ");Serial.print(MQ131.getR0());Serial.println(" Ohm");
Serial.print("NOx: ");Serial.print(NOx,2);Serial.println(" ppm");
Serial.print("CL2: ");Serial.print(CL2,2);Serial.println(" ppm");
Serial.print("O3: ");Serial.print(O3,2);Serial.println(" ppm");
Serial.println("***************************");
}

View File

@ -9,6 +9,10 @@
modified 23 May 2019 modified 23 May 2019
by Miguel Califa by Miguel Califa
Updated library usage
modified 26 March 2020
by Miguel Califa
This example code is in the public domain. This example code is in the public domain.
*/ */
@ -17,65 +21,57 @@
#include <MQUnifiedsensor.h> #include <MQUnifiedsensor.h>
//Definitions //Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino #define pin A0 //Analog input 0 of your arduino
#define type 8 //MQ8 #define type "MQ-8" //MQ8
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
//#define calibration_button 13 //Pin to calibrate your sensor //#define calibration_button 13 //Pin to calibrate your sensor
//Declare Sensor //Declare Sensor
MQUnifiedsensor MQ8(pin, type); MQUnifiedsensor MQ8(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
//Variables
float H2, LPG, CH4, CO, Alcohol;
void setup() { void setup() {
//Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port Serial.begin(9600); //Init serial port
//init the sensor
/***************************** MQInicializar**************************************** //Set math model to calculate the PPM concentration and the value of constants
Input: pin, type MQ8.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
Output: MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
Remarks: This function create the sensor object.
************************************************************************************/ /*
MQ8.inicializar(); Exponential regression:
//pinMode(calibration_button, INPUT); GAS | a | b
H2 | 976.97 | -0.688
LPG | 10000000 | -3.123
CH4 | 80000000000000 | -6.666
CO | 2000000000000000000 | -8.074
Alcohol | 76101 | -1.86
*/
// Calibration setup
MQ8.setR0(1);
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ8.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ8.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ8.serialDebug(true);
} }
void loop() { void loop() {
MQ8.update(); // Update data, the arduino will be read the voltaje in the analog pin 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
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: MQ8.serialDebug(); // Will print the table on the serial port
MQ8.setRL(10); delay(500); //Sampling frequency
*/ }
/*
//Rutina de calibracion - Uncomment if you need (setup too and header)
if(calibration_button)
{
float R0 = MQ8.calibrate();
MQ8.setR0(R0);
}
*/
/***************************** MQReadSensor ****************************************
Input: Gas - Serial print flag
Output: Value in PPM
Remarks: This function use readPPM to read the value in PPM the gas in the air.
************************************************************************************/
//Read the sensor and print in serial port
//Lecture will be saved in lecture variable
//float lecture = MQ8.readSensor("", true); // Return H2 concentration
// Options, uncomment where you need
H2 = MQ8.readSensor("H2"); // Return CH4 concentration
LPG = MQ8.readSensor("LPG"); // Return LPG concentration
CH4 = MQ8.readSensor("CH4"); // Return CH4 concentration
CO = MQ8.readSensor("CO"); // Return CO concentration
Alcohol = MQ8.readSensor("Alcohol"); // Return Alcohol concentration
Serial.println("***************************");
Serial.println("Lectures for MQ-8");
Serial.print("Volt: ");Serial.print(MQ8.getVoltage(false));Serial.println(" V");
Serial.print("R0: ");Serial.print(MQ8.getR0());Serial.println(" Ohm");
Serial.print("H2: ");Serial.print(H2,2);Serial.println(" ppm");
Serial.print("LPG: ");Serial.print(LPG,2);Serial.println(" ppm");
Serial.print("CH4: ");Serial.print(CH4,2);Serial.println(" ppm");
Serial.print("CO: ");Serial.print(CO,2);Serial.println(" ppm");
Serial.print("Alcohol: ");Serial.print(Alcohol,2);Serial.println(" ppm");
Serial.println("***************************");
}

View File

@ -9,6 +9,10 @@
modified 23 May 2019 modified 23 May 2019
by Miguel Califa by Miguel Califa
Updated library usage
modified 26 March 2020
by Miguel Califa
This example code is in the public domain. This example code is in the public domain.
*/ */
@ -17,61 +21,55 @@
#include <MQUnifiedsensor.h> #include <MQUnifiedsensor.h>
//Definitions //Definitions
#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino #define pin A0 //Analog input 0 of your arduino
#define type 9 //MQ9 #define type "MQ-9" //MQ9
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
//#define calibration_button 13 //Pin to calibrate your sensor //#define calibration_button 13 //Pin to calibrate your sensor
//Declare Sensor //Declare Sensor
MQUnifiedsensor MQ9(pin, type); MQUnifiedsensor MQ9(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
//Variables
float CO, CH4, LPG;
void setup() { void setup() {
//Init the serial port communication - to debug the library
Serial.begin(9600); //Init serial port Serial.begin(9600); //Init serial port
//init the sensor
/***************************** MQInicializar**************************************** //Set math model to calculate the PPM concentration and the value of constants
Input: pin, type MQ9.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
Output: MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
Remarks: This function create the sensor object.
************************************************************************************/ /*
MQ9.inicializar(); Exponential regression:
//pinMode(calibration_button, INPUT); GAS | a | b
LPG | 1000.5 | -2.186
CH4 | 4269.6 | -2.648
CO | 599.65 | -2.244
*/
// Calibration setup
MQ9.setR0(9.42857143);
/*
//If the RL value is different from 10K please assign your RL value with the following method:
MQ9.setRL(10);
*/
/***************************** MQ Init ********************************************/
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.init();
/***************************** MQ Init ********************************************/
//Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//Output: print on serial port the information about sensor and sensor readings
//Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.serialDebug(true);
} }
void loop() { void loop() {
MQ9.update(); // Update data, the arduino will be read the voltaje in the analog pin 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
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: MQ9.serialDebug(); // Will print the table on the serial port
MQ9.setRL(10); delay(500); //Sampling frequency
*/ }
/*
//Rutina de calibracion - Uncomment if you need (setup too and header)
if(calibration_button)
{
float R0 = MQ9.calibrate();
MQ9.setR0(R0);
}
*/
/***************************** MQReadSensor ****************************************
Input: Gas - Serial print flag
Output: Value in PPM
Remarks: This function use readPPM to read the value in PPM the gas in the air.
************************************************************************************/
//Read the sensor and print in serial port
//Lecture will be saved in lecture variable
//float lecture = MQ9.readSensor("", true); // Return LPG concentration
// Options, uncomment where you need
LPG = MQ9.readSensor("LPG"); // Return LPG concentration
CH4 = MQ9.readSensor("CH4"); // Return CH4 concentration
CO = MQ9.readSensor("CO"); // Return CO concentration
Serial.println("***************************");
Serial.println("Lectures for MQ-9");
Serial.print("Volt: ");Serial.print(MQ9.getVoltage(false));Serial.println(" V");
Serial.print("R0: ");Serial.print(MQ9.getR0());Serial.println(" Ohm");
Serial.print("CO: ");Serial.print(CO,2);Serial.println(" ppm");
Serial.print("LPG: ");Serial.print(LPG,2);Serial.println(" ppm");
Serial.print("CH4: ");Serial.print(CH4,2);Serial.println(" ppm");
Serial.println("***************************");
}