Added MQ-8 and MQ-9

pull/33/head
miguel5612 5 years ago
parent fad888dca4
commit f8a57bbdff

@ -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****************************************
Input: pin, type
Output:
Remarks: This function create the sensor object.
************************************************************************************/
MQ131.inicializar();
//pinMode(calibration_button, INPUT);
}
void loop() { //Set math model to calculate the PPM concentration and the value of constants
MQ131.update(); // Update data, the arduino will be read the voltaje in the analog pin MQ9.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
/* /*
// Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: Exponential regression:
MQ131.setRL(10); GAS | a | b
LPG | 1000.5 | -2.186
CH4 | 4269.6 | -2.648
CO | 599.65 | -2.244
*/ */
/*
//Rutina de calibracion - Uncomment if you need (setup too and header) // Calibration setup
if(calibration_button) MQ9.setR0(9.42857143);
{
float R0 = MQ131.calibrate(); /*
MQ131.setR0(R0); //If the RL value is different from 10K please assign your RL value with the following method:
} MQ9.setRL(10);
*/ */
/***************************** 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("***************************"); /***************************** MQ Init ********************************************/
Serial.println("Lectures for MQ-131"); //Remarks: Configure the pin of arduino as input.
Serial.print("Volt: ");Serial.print(MQ131.getVoltage(false));Serial.println(" V"); /************************************************************************************/
Serial.print("R0: ");Serial.print(MQ131.getR0());Serial.println(" Ohm"); MQ9.init();
Serial.print("NOx: ");Serial.print(NOx,2);Serial.println(" ppm"); /***************************** MQ Init ********************************************/
Serial.print("CL2: ");Serial.print(CL2,2);Serial.println(" ppm"); //Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
Serial.print("O3: ");Serial.print(O3,2);Serial.println(" ppm"); //Output: print on serial port the information about sensor and sensor readings
Serial.println("***************************"); //Remarks: Configure the pin of arduino as input.
/************************************************************************************/
MQ9.serialDebug(true);
} }
void loop() {
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.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -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****************************************
Input: pin, type
Output:
Remarks: This function create the sensor object.
************************************************************************************/
MQ8.inicializar();
//pinMode(calibration_button, INPUT);
}
void loop() { //Set math model to calculate the PPM concentration and the value of constants
MQ8.update(); // Update data, the arduino will be read the voltaje in the analog pin MQ8.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
/* MQ8.setA(976.97); MQ8.setB(-0.688); // Configurate the ecuation values to get H2 concentration
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo:
MQ8.setRL(10);
*/
/* /*
//Rutina de calibracion - Uncomment if you need (setup too and header) Exponential regression:
if(calibration_button) GAS | a | b
{ H2 | 976.97 | -0.688
float R0 = MQ8.calibrate(); LPG | 10000000 | -3.123
MQ8.setR0(R0); CH4 | 80000000000000 | -6.666
} CO | 2000000000000000000 | -8.074
Alcohol | 76101 | -1.86
*/ */
/***************************** 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("***************************"); // Calibration setup
Serial.println("Lectures for MQ-8"); MQ8.setR0(1);
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"); //If the RL value is different from 10K please assign your RL value with the following method:
Serial.print("LPG: ");Serial.print(LPG,2);Serial.println(" ppm"); MQ8.setRL(10);
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"); /***************************** MQ Init ********************************************/
Serial.println("***************************"); //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() {
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.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}

@ -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****************************************
Input: pin, type
Output:
Remarks: This function create the sensor object.
************************************************************************************/
MQ9.inicializar();
//pinMode(calibration_button, INPUT);
}
void loop() { //Set math model to calculate the PPM concentration and the value of constants
MQ9.update(); // Update data, the arduino will be read the voltaje in the analog pin MQ9.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
MQ9.setA(1000.5); MQ9.setB(-2.186); // Configurate the ecuation values to get LPG concentration
/* /*
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: Exponential regression:
MQ9.setRL(10); GAS | a | b
LPG | 1000.5 | -2.186
CH4 | 4269.6 | -2.648
CO | 599.65 | -2.244
*/ */
/*
//Rutina de calibracion - Uncomment if you need (setup too and header) // Calibration setup
if(calibration_button) MQ9.setR0(9.42857143);
{
float R0 = MQ9.calibrate(); /*
MQ9.setR0(R0); //If the RL value is different from 10K please assign your RL value with the following method:
} MQ9.setRL(10);
*/ */
/***************************** MQReadSensor ****************************************
Input: Gas - Serial print flag /***************************** MQ Init ********************************************/
Output: Value in PPM //Remarks: Configure the pin of arduino as input.
Remarks: This function use readPPM to read the value in PPM the gas in the air. /************************************************************************************/
************************************************************************************/ MQ9.init();
//Read the sensor and print in serial port /***************************** MQ Init ********************************************/
//Lecture will be saved in lecture variable //Input: setup flag, if this function are on setup will print the headers (Optional - Default value: False)
//float lecture = MQ9.readSensor("", true); // Return LPG concentration //Output: print on serial port the information about sensor and sensor readings
// Options, uncomment where you need //Remarks: Configure the pin of arduino as input.
LPG = MQ9.readSensor("LPG"); // Return LPG concentration /************************************************************************************/
CH4 = MQ9.readSensor("CH4"); // Return CH4 concentration MQ9.serialDebug(true);
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("***************************");
} }
void loop() {
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.serialDebug(); // Will print the table on the serial port
delay(500); //Sampling frequency
}
Loading…
Cancel
Save