diff --git a/.vscode/ipch/63d08c61adeaa260/mmap_address.bin b/.vscode/ipch/63d08c61adeaa260/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/63d08c61adeaa260/mmap_address.bin differ diff --git a/.vscode/ipch/82e5fbe353da52d9/mmap_address.bin b/.vscode/ipch/82e5fbe353da52d9/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/82e5fbe353da52d9/mmap_address.bin differ diff --git a/.vscode/ipch/b854ba25c8dcfec0/mmap_address.bin b/.vscode/ipch/b854ba25c8dcfec0/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/b854ba25c8dcfec0/mmap_address.bin differ diff --git a/Release/19052019_Test1.zip b/Release/19052019_Test1.zip new file mode 100644 index 0000000..024351a Binary files /dev/null and b/Release/19052019_Test1.zip differ diff --git a/examples/MQ4/MQ4.ino b/examples/MQ4/MQ4.ino new file mode 100644 index 0000000..154f4e4 --- /dev/null +++ b/examples/MQ4/MQ4.ino @@ -0,0 +1,12 @@ +#include + + +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..97ed754 --- /dev/null +++ b/library.properties @@ -0,0 +1,10 @@ +name=MQUnifiedsensor +version=1.0.0 +author= Miguel Califa , Yersson Carrillo , Ghiordy Contreras +maintainer= Miguel Califa +sentence= This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, and 135. +paragraph= This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, and 135. +category= Sensor +url=https://github.com/miguel5612/MQSensorsLib +architectures=* +license=MIT diff --git a/src/MQUnifiedsensor.cpp b/src/MQUnifiedsensor.cpp index 69f3dc1..b14dc70 100644 --- a/src/MQUnifiedsensor.cpp +++ b/src/MQUnifiedsensor.cpp @@ -1,167 +1,36 @@ #include "MQUnifiedsensor.h" -MQUnifiedsensor::MQSensor(int pin) { + +void MQUnifiedsensor::MQSensor(int pin, int type) { this->_pin = pin; + this->_type = type; //2,3,4,5,6,7,8,9,131,135,303,309 } -MQUnifiedsensor::setR0(double R0) { +void MQUnifiedsensor::setR0(double R0) { this->_R0 = R0; } -/****************** Info of sensor graphic *******************/ -//MQ-2 - Methane, Butane, LPG, smoke - - - -//MQ-3 - Alcohol, Ethanol, smoke - - - -//MQ-4 - Methane, CNG Gas - -const float R0 = 11.820; -const float m = -0.318; -const float b = 1.133; - -//MQ-5 - Natural gas, LPG - - - -//MQ-6 - LPG, butane gas - - - -//MQ-7 - Carbon Monoxide - - - -//MQ-8 - Hydrogen Gas - - - -//MQ-9 - Carbon Monoxide, flammable gasses - - - -//MQ131 - Ozone - - - -//MQ135 - Air Quality (CO, Ammonia, Benzene, Alcohol, smoke) - - - -//MQ136 - Hydrogen Sulfide gas - - - -//MQ137 - Ammonia - - -/****************** Info of sensor graphic *******************/ - - - -//***************** Operations ************************************/ - - -int readMethane() +String MQUnifiedsensor::readSensor(String nameLectureReqeuired) { + switch (_type) + { + case 1: + break; + + default: + break; + } } -int readButane() + +void MQUnifiedsensor::getSensorCharacteristics(int MQ[38], String nameLectureReqeuired) { - + if(nameLectureReqeuired = nameLecture[0]) + { + _m = MQ[indexSlopeLectures[0]]; + _b = MQ[indexBPointLectures[0]]; + } } -int readLPG() -{ - -} -int readSmoke() -{ - -} -int readAlcohol() -{ - -} -int readEthanol() -{ - -} -int readCNG() -{ - -} -int readLPG() -{ - -} -int readCO() -{ - -} -int readHO() -{ - -} -int readCarbonMonoxide() -{ - -} -int readNH4() -{ - -} -int readbenzene() -{ - -} -int readAlcohol() -{ - -} -int readHidrogen() -{ - -} -int readToluene() -{ - -} -int readAcetone() -{ - -} -int readPropane() -{ - -} -int readCoalGas() -{ - -} - - - - - - - - - - - - - - - - -const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3 -const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter. - -const int retries = 50; -const int retry_interval = 20; double MQUnifiedsensor::calibrate() { float sensor_volt; //Define variable for sensor voltage @@ -189,7 +58,7 @@ double MQUnifiedsensor::getVoltage() { /** * Returns the PPM concentration */ - int MQUnifiedsensor::read() { + int MQUnifiedsensor::readPPM(int m, int b) { double sensor_volt = this->getVoltage(); double RS_gas; //Define variable for sensor resistance double ratio; //Define variable for ratio @@ -201,4 +70,4 @@ double MQUnifiedsensor::getVoltage() { double ppm_log = (log10(ratio) - b) / m; //Get ppm value in linear scale according to the the ratio value double ppm = pow(10, ppm_log); //Convert ppm value to log scale return floor(ppm); -} \ No newline at end of file + } \ No newline at end of file diff --git a/src/MQUnifiedsensor.h b/src/MQUnifiedsensor.h index 874c579..1297ffb 100644 --- a/src/MQUnifiedsensor.h +++ b/src/MQUnifiedsensor.h @@ -1,7 +1,8 @@ #ifndef MQUnifiedsensor_H -#define MQUnifiedsensor_H + #define MQUnifiedsensor_H #include +#include class MQUnifiedsensor { @@ -9,9 +10,24 @@ class MQUnifiedsensor /** * Constructor */ - MQSensor(int pin); - setR0(double R0); - setSensorTyp(int sensorNumber); + void MQSensor(int pin, int type); + void setR0(double R0); + void setSensorTyp(int sensorNumber); + void getSensorCharacteristics(int MQ[38], String nameLectureReqeuired); + String readSensor(String nameLectureReqeuired); + int readPPM(int m, int b); + + /** + * Calibrates the start point of 400 + */ + double calibrate(); + + /** + * Returns the voltage + */ + double getVoltage(); + + /** * Returns the PPM concentration MQ-2 - Methane, Butane, LPG, smoke @@ -48,40 +64,14 @@ class MQUnifiedsensor int MQ303A[38] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2.3543,1.144,-2.4338,0.7558,-2.5597,0.4436}; int MQ309A[38] = {-2.1311,3.0886,0,0,-1.6554,2.985,-4.7623,6.7413,-3.7686,5.6744,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - int readMethane(); - int readButane(); - int readLPG(); - int readSmoke(); - int readAlcohol(); - int readEthanol(); - int readCNG(); - int readLPG(); - int readCO(); - int readHO(); - int readCarbonMonoxide(); - int readNH4(); - int readbenzene(); - int readAlcohol(); - int readHidrogen(); - int readToluene(); - int readAcetone(); - int readPropane(); - int readCoalGas(); - - /** - * Calibrates the start point of 400 - */ - double calibrate(); - - /** - * Returns the voltage - */ - double getVoltage(); - private: - int _pin; - double _R0; + int _pin, _type; + double _R0, _m, _b; + const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3 + const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter. + const int retries = 50; + const int retry_interval = 20; }; #endif //MQUnifiedsensor_H \ No newline at end of file