|
|
|
@ -9,6 +9,10 @@
|
|
|
|
|
modified 23 May 2019
|
|
|
|
|
by Miguel Califa
|
|
|
|
|
|
|
|
|
|
Updated library usage
|
|
|
|
|
modified 26 March 2020
|
|
|
|
|
by Miguel Califa
|
|
|
|
|
|
|
|
|
|
This example code is in the public domain.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
@ -31,79 +35,38 @@ MQUnifiedsensor MQ3(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
|
|
|
|
float CH4, LPG, CO, Alcohol, Hexane, Benzine;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
//Init the serial port communication - to debug the library
|
|
|
|
|
Serial.begin(9600); //Init serial port
|
|
|
|
|
//init the sensor
|
|
|
|
|
/***************************** MQInicializar****************************************
|
|
|
|
|
Input: pin, type
|
|
|
|
|
Output:
|
|
|
|
|
Remarks: This function create the sensor object.
|
|
|
|
|
************************************************************************************/
|
|
|
|
|
MQ3.setRegressionMethod("Exponential");
|
|
|
|
|
|
|
|
|
|
//Set math model to calculate the PPM concentration and the value of constants
|
|
|
|
|
MQ3.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
|
|
|
|
|
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values to get Benzene concentration
|
|
|
|
|
|
|
|
|
|
// Calibration setup
|
|
|
|
|
MQ3.setR0(3.86018237);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo:
|
|
|
|
|
//If the RL value is different from 10K please assign your RL value with the following method:
|
|
|
|
|
MQ3.setRL(10);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/***************************** MQ Init ********************************************/
|
|
|
|
|
//Remarks: Configure the pin of arduino as input.
|
|
|
|
|
/************************************************************************************/
|
|
|
|
|
MQ3.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.
|
|
|
|
|
/************************************************************************************/
|
|
|
|
|
MQ3.serialDebug(true);
|
|
|
|
|
|
|
|
|
|
//pinMode(calibration_button, INPUT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 a and b values setted before or on setup
|
|
|
|
|
MQ3.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
|
|
|
|
MQ3.serialDebug(); // Will print the table on the serial port
|
|
|
|
|
/*
|
|
|
|
|
//Rutina de calibracion - Uncomment if you need (setup too and header)
|
|
|
|
|
if(calibration_button)
|
|
|
|
|
{
|
|
|
|
|
float R0 = MQ3.calibrate();
|
|
|
|
|
MQ3.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 = MQ3.readSensor("", true); // Return Alcohol concentration
|
|
|
|
|
// Options, uncomment where you need
|
|
|
|
|
/*
|
|
|
|
|
MQ3.setA(2*10^31); MQ3.setB(19.01); // Configurate the ecuation values
|
|
|
|
|
CH4 = MQ3.readSensor(); // Return CH4 concentration
|
|
|
|
|
|
|
|
|
|
MQ3.setA(44771); MQ3.setB(-3.245); // Configurate the ecuation values
|
|
|
|
|
LPG = MQ3.readSensor(); // Return LPG concentration
|
|
|
|
|
|
|
|
|
|
MQ3.setA(521853); MQ3.setB(-3.821); // Configurate the ecuation values
|
|
|
|
|
CO = MQ3.readSensor(); // Return CO concentration
|
|
|
|
|
|
|
|
|
|
MQ3.setA(0.3934); MQ3.setB(-1.504); // Configurate the ecuation values
|
|
|
|
|
Alcohol = MQ3.readSensor(); // Return Alcohol concentration
|
|
|
|
|
|
|
|
|
|
MQ3.setA(7585.3); MQ3.setB(-2.849); // Configurate the ecuation values
|
|
|
|
|
Hexane = MQ3.readSensor(); // Return Hexane concentration
|
|
|
|
|
|
|
|
|
|
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values
|
|
|
|
|
Benzine = MQ3.readSensor(); // Return Benzene concentration
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Serial.println("***************************");
|
|
|
|
|
Serial.println("Lectures for MQ-3");
|
|
|
|
|
Serial.print("Volt: ");Serial.print(MQ3.getVoltage(false));Serial.println(" V");
|
|
|
|
|
Serial.print("R0: ");Serial.print(MQ3.getR0());Serial.println(" Ohm");
|
|
|
|
|
Serial.print("CH4: ");Serial.print(CH4,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.print("LPG: ");Serial.print(LPG,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.print("CO: ");Serial.print(CO,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.print("Alcohol: ");Serial.print(Alcohol,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.print("Hexane: ");Serial.print(Hexane,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.print("Benzine: ");Serial.print(Benzine,2);Serial.println(" mg/L");
|
|
|
|
|
Serial.println("***************************");
|
|
|
|
|
*/
|
|
|
|
|
delay(500); //Sampling frequency
|
|
|
|
|
}
|