From 1924e21e61386c2a7eae167c868e3b168ef7d384 Mon Sep 17 00:00:00 2001 From: miguel5612 Date: Wed, 29 May 2019 20:41:04 -0500 Subject: [PATCH] Added comments --- examples/MQ-2/MQ-2.ino | 18 ++++++++++++++++-- src/MQUnifiedsensor.cpp | 3 +-- src/MQUnifiedsensor.h | 8 +++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/examples/MQ-2/MQ-2.ino b/examples/MQ-2/MQ-2.ino index 9e8aee1..45b5581 100644 --- a/examples/MQ-2/MQ-2.ino +++ b/examples/MQ-2/MQ-2.ino @@ -20,18 +20,32 @@ #define pin A0 //Analog input 0 of your arduino #define type 2 //MQ2 +/***************************** MQInicializar**************************************** + Input: pin, type + Output: + Remarks: This function create the sensor object. + ************************************************************************************/ //Declare Sensor - MQUnifiedsensor MQ2(pin, type); void setup() { //Init serial port Serial.begin(115200); + /***************************** MQInicializar**************************************** + Input: + Output: + Remarks: This function configure the pinMode + ************************************************************************************/ //init the sensor 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 int lecture = MQ2.readSensor("", true); delay(400); diff --git a/src/MQUnifiedsensor.cpp b/src/MQUnifiedsensor.cpp index 6593d73..670406c 100644 --- a/src/MQUnifiedsensor.cpp +++ b/src/MQUnifiedsensor.cpp @@ -141,8 +141,7 @@ double MQUnifiedsensor::calibrate() { float R0; //Define variable for R0 float sensorValue; //Define variable for analog readings sensor_volt = this->getVoltage(); //Convert average to voltage - RS_air = (5.0-sensor_volt)/sensor_volt; // omit *RL - R0 = RS_air / _ratioInCleanAir; //Calculate R0 + R0 = sensor_volt / _ratioInCleanAir; //Calculate R0 return R0; } double MQUnifiedsensor::getVoltage() { diff --git a/src/MQUnifiedsensor.h b/src/MQUnifiedsensor.h index 8f283d3..b034cf8 100644 --- a/src/MQUnifiedsensor.h +++ b/src/MQUnifiedsensor.h @@ -7,6 +7,8 @@ //Count of posible lectures #define lecturesAvailable 19 +/************************Hardware Related Macros************************************/ + //Index in the nameLecture vector #define defaultMQ2 "LPG" // LPG #define defaultMQ3 "Alcohol" // Alcohol @@ -21,6 +23,7 @@ #define defaultMQ303 "Isobutano" //Isobutano #define defaultMQ309 "CO" //CO +/*****************************Globals***********************************************/ #define RatioMQ2CleanAir 1 #define RatioMQ3CleanAir 2 #define RatioMQ4CleanAir 3 @@ -34,12 +37,15 @@ #define RatioMQ303CleanAir 135 #define RatioMQ309CleanAir 303 +/***********************Software Related Macros************************************/ + #define ADC_RESOLUTION 10 // for 10bit analog to digital converter. #define retries 50 #define retry_interval 20 -//Values consolidated +/**********************Application Related Macros**********************************/ /* 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 _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"};