mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-25 10:10:01 +03:00
Added comments
This commit is contained in:
parent
1a4c91528d
commit
1924e21e61
@ -20,18 +20,32 @@
|
|||||||
#define pin A0 //Analog input 0 of your arduino
|
#define pin A0 //Analog input 0 of your arduino
|
||||||
#define type 2 //MQ2
|
#define type 2 //MQ2
|
||||||
|
|
||||||
|
/***************************** MQInicializar****************************************
|
||||||
|
Input: pin, type
|
||||||
|
Output:
|
||||||
|
Remarks: This function create the sensor object.
|
||||||
|
************************************************************************************/
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
|
|
||||||
MQUnifiedsensor MQ2(pin, type);
|
MQUnifiedsensor MQ2(pin, type);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Init serial port
|
//Init serial port
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
/***************************** MQInicializar****************************************
|
||||||
|
Input:
|
||||||
|
Output:
|
||||||
|
Remarks: This function configure the pinMode
|
||||||
|
************************************************************************************/
|
||||||
//init the sensor
|
//init the sensor
|
||||||
MQ2.inicializar();
|
MQ2.inicializar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
/***************************** 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
|
//Read the sensor and print in serial port
|
||||||
int lecture = MQ2.readSensor("", true);
|
int lecture = MQ2.readSensor("", true);
|
||||||
delay(400);
|
delay(400);
|
||||||
|
@ -141,8 +141,7 @@ double MQUnifiedsensor::calibrate() {
|
|||||||
float R0; //Define variable for R0
|
float R0; //Define variable for R0
|
||||||
float sensorValue; //Define variable for analog readings
|
float sensorValue; //Define variable for analog readings
|
||||||
sensor_volt = this->getVoltage(); //Convert average to voltage
|
sensor_volt = this->getVoltage(); //Convert average to voltage
|
||||||
RS_air = (5.0-sensor_volt)/sensor_volt; // omit *RL
|
R0 = sensor_volt / _ratioInCleanAir; //Calculate R0
|
||||||
R0 = RS_air / _ratioInCleanAir; //Calculate R0
|
|
||||||
return R0;
|
return R0;
|
||||||
}
|
}
|
||||||
double MQUnifiedsensor::getVoltage() {
|
double MQUnifiedsensor::getVoltage() {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
//Count of posible lectures
|
//Count of posible lectures
|
||||||
#define lecturesAvailable 19
|
#define lecturesAvailable 19
|
||||||
|
|
||||||
|
/************************Hardware Related Macros************************************/
|
||||||
|
|
||||||
//Index in the nameLecture vector
|
//Index in the nameLecture vector
|
||||||
#define defaultMQ2 "LPG" // LPG
|
#define defaultMQ2 "LPG" // LPG
|
||||||
#define defaultMQ3 "Alcohol" // Alcohol
|
#define defaultMQ3 "Alcohol" // Alcohol
|
||||||
@ -21,6 +23,7 @@
|
|||||||
#define defaultMQ303 "Isobutano" //Isobutano
|
#define defaultMQ303 "Isobutano" //Isobutano
|
||||||
#define defaultMQ309 "CO" //CO
|
#define defaultMQ309 "CO" //CO
|
||||||
|
|
||||||
|
/*****************************Globals***********************************************/
|
||||||
#define RatioMQ2CleanAir 1
|
#define RatioMQ2CleanAir 1
|
||||||
#define RatioMQ3CleanAir 2
|
#define RatioMQ3CleanAir 2
|
||||||
#define RatioMQ4CleanAir 3
|
#define RatioMQ4CleanAir 3
|
||||||
@ -34,12 +37,15 @@
|
|||||||
#define RatioMQ303CleanAir 135
|
#define RatioMQ303CleanAir 135
|
||||||
#define RatioMQ309CleanAir 303
|
#define RatioMQ309CleanAir 303
|
||||||
|
|
||||||
|
/***********************Software Related Macros************************************/
|
||||||
|
|
||||||
#define ADC_RESOLUTION 10 // for 10bit analog to digital converter.
|
#define ADC_RESOLUTION 10 // for 10bit analog to digital converter.
|
||||||
#define retries 50
|
#define retries 50
|
||||||
#define retry_interval 20
|
#define retry_interval 20
|
||||||
|
|
||||||
//Values consolidated
|
/**********************Application Related Macros**********************************/
|
||||||
/* Gas, Value of m (Slope) and b (Cut on x axis) points */
|
/* Gas, Value of m (Slope) and b (Cut on x axis) points */
|
||||||
|
//Values consolidated
|
||||||
const String PROGMEM _MQ2[18] = {"H2","-2.2459","2.9845","LPG","-2.2879","2.7901","CO","-2.6208","3.6075","Alcohol","-3.1157","4.5134","Propane","-2.7028","3.5595","Benzene","-2.2879","2.7901"};
|
const String PROGMEM _MQ2[18] = {"H2","-2.2459","2.9845","LPG","-2.2879","2.7901","CO","-2.6208","3.6075","Alcohol","-3.1157","4.5134","Propane","-2.7028","3.5595","Benzene","-2.2879","2.7901"};
|
||||||
const String PROGMEM _MQ3[18] = {"LPG","-3.1851","4.7048","CH4","-17.531","28.785","CO","-4.339","6.4432","Alcohol","-1.435","0.4103","Benzene","-2.7009","0.632","Hexane","-2.7268","3.6299"};
|
const String PROGMEM _MQ3[18] = {"LPG","-3.1851","4.7048","CH4","-17.531","28.785","CO","-4.339","6.4432","Alcohol","-1.435","0.4103","Benzene","-2.7009","0.632","Hexane","-2.7268","3.6299"};
|
||||||
const String PROGMEM _MQ4[15] = {"LPG","-2.5818","3.6303","CH4","0.9873","2.6386","CO","-5.5945","5.6693","Alcohol","-11.89","9.0375","smoke","-11.189","9.0375"};
|
const String PROGMEM _MQ4[15] = {"LPG","-2.5818","3.6303","CH4","0.9873","2.6386","CO","-5.5945","5.6693","Alcohol","-11.89","9.0375","smoke","-11.189","9.0375"};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user