Replaced equation y = mx+b to potential equation y=a*x^b

This commit is contained in:
miguel5612 2019-08-13 12:05:39 -05:00
parent 02e5fa2160
commit 7aa387c0b4
2 changed files with 117 additions and 120 deletions

View File

@ -146,37 +146,37 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ2_H2_m;
_a = MQ2_H2_m;
_b = MQ2_H2_b;
}
else if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ2_LPG_m;
_a = MQ2_LPG_m;
_b = MQ2_LPG_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ2_CO_m;
_a = MQ2_CO_m;
_b = MQ2_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ2_Alcohol_m;
_a = MQ2_Alcohol_m;
_b = MQ2_Alcohol_b;
}
else if(_nameLectureRequeired == "Propane")
{
_nameLectureRequeired = "Propane";
_m = MQ2_Propane_m;
_a = MQ2_Propane_m;
_b = MQ2_Propane_b;
}
else if(_nameLectureRequeired == "Benzene")
{
_nameLectureRequeired = "Benzene";
_m = MQ2_Benzene_m;
_a = MQ2_Benzene_m;
_b = MQ2_Benzene_b;
}
}
@ -185,37 +185,37 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ3_LPG_m;
_a = MQ3_LPG_m;
_b = MQ3_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ3_CH4_m;
_a = MQ3_CH4_m;
_b = MQ3_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ3_CO_m;
_a = MQ3_CO_m;
_b = MQ3_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ3_Alcohol_m;
_a = MQ3_Alcohol_m;
_b = MQ3_Alcohol_b;
}
else if(_nameLectureRequeired == "Hexane")
{
_nameLectureRequeired = "Hexane";
_m = MQ3_Hexane_m;
_a = MQ3_Hexane_m;
_b = MQ3_Hexane_b;
}
else if(_nameLectureRequeired == "Benzene")
{
_nameLectureRequeired = "Benzene";
_m = MQ3_Benzene_m;
_a = MQ3_Benzene_m;
_b = MQ3_Benzene_b;
}
}
@ -224,31 +224,31 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ4_LPG_m;
_a = MQ4_LPG_m;
_b = MQ4_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ4_CH4_m;
_a = MQ4_CH4_m;
_b = MQ4_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ4_CO_m;
_a = MQ4_CO_m;
_b = MQ4_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ4_Alcohol_m;
_a = MQ4_Alcohol_m;
_b = MQ4_Alcohol_b;
}
else if(_nameLectureRequeired == "smoke")
{
_nameLectureRequeired = "smoke";
_m = MQ4_smoke_m;
_a = MQ4_smoke_m;
_b = MQ4_smoke_b;
}
}
@ -257,31 +257,31 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ5_H2_m;
_a = MQ5_H2_m;
_b = MQ5_H2_b;
}
else if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ5_LPG_m;
_a = MQ5_LPG_m;
_b = MQ5_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ5_CH4_m;
_a = MQ5_CH4_m;
_b = MQ5_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ5_CO_m;
_a = MQ5_CO_m;
_b = MQ5_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ5_Alcohol_m;
_a = MQ5_Alcohol_m;
_b = MQ5_Alcohol_b;
}
}
@ -290,31 +290,31 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ6_H2_m;
_a = MQ6_H2_m;
_b = MQ6_H2_b;
}
else if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ6_LPG_m;
_a = MQ6_LPG_m;
_b = MQ6_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ6_CH4_m;
_a = MQ6_CH4_m;
_b = MQ6_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ6_CO_m;
_a = MQ6_CO_m;
_b = MQ6_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ6_Alcohol_m;
_a = MQ6_Alcohol_m;
_b = MQ6_Alcohol_b;
}
}
@ -323,31 +323,31 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ7_H2_m;
_a = MQ7_H2_m;
_b = MQ7_H2_b;
}
else if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ7_LPG_m;
_a = MQ7_LPG_m;
_b = MQ7_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ7_CH4_m;
_a = MQ7_CH4_m;
_b = MQ7_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ7_CO_m;
_a = MQ7_CO_m;
_b = MQ7_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ7_Alcohol_m;
_a = MQ7_Alcohol_m;
_b = MQ7_Alcohol_b;
}
}
@ -356,31 +356,31 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ8_H2_m;
_a = MQ8_H2_m;
_b = MQ8_H2_b;
}
else if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ8_LPG_m;
_a = MQ8_LPG_m;
_b = MQ8_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ8_CH4_m;
_a = MQ8_CH4_m;
_b = MQ8_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ8_CO_m;
_a = MQ8_CO_m;
_b = MQ8_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ8_Alcohol_m;
_a = MQ8_Alcohol_m;
_b = MQ8_Alcohol_b;
}
}
@ -389,19 +389,19 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "LPG")
{
_nameLectureRequeired = "LPG";
_m = MQ9_LPG_m;
_a = MQ9_LPG_m;
_b = MQ9_LPG_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ9_CH4_m;
_a = MQ9_CH4_m;
_b = MQ9_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ9_CO_m;
_a = MQ9_CO_m;
_b = MQ9_CO_b;
}
}
@ -410,19 +410,19 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "NOx")
{
_nameLectureRequeired = "NOx";
_m = MQ131_NOx_m;
_a = MQ131_NOx_m;
_b = MQ131_NOx_b;
}
else if(_nameLectureRequeired == "CL2")
{
_nameLectureRequeired = "CL2";
_m = MQ131_CL2_m;
_a = MQ131_CL2_m;
_b = MQ131_CL2_b;
}
else if(_nameLectureRequeired == "O3")
{
_nameLectureRequeired = "O3";
_m = MQ131_O3_m;
_a = MQ131_O3_m;
_b = MQ131_O3_b;
}
}
@ -431,37 +431,37 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ135_CO_m;
_a = MQ135_CO_m;
_b = MQ135_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ135_Alcohol_m;
_a = MQ135_Alcohol_m;
_b = MQ135_Alcohol_b;
}
else if(_nameLectureRequeired == "CO2")
{
_nameLectureRequeired = "CO2";
_m = MQ135_CO2_m;
_a = MQ135_CO2_m;
_b = MQ135_CO2_b;
}
else if(_nameLectureRequeired == "Tolueno")
{
_nameLectureRequeired = "Tolueno";
_m = MQ135_Tolueno_m;
_a = MQ135_Tolueno_m;
_b = MQ135_Tolueno_b;
}
else if(_nameLectureRequeired == "NH4")
{
_nameLectureRequeired = "NH4";
_m = MQ135_NH4_m;
_a = MQ135_NH4_m;
_b = MQ135_NH4_b;
}
else if(_nameLectureRequeired == "Acetona")
{
_nameLectureRequeired = "Acetona";
_m = MQ135_Acetona_m;
_a = MQ135_Acetona_m;
_b = MQ135_Acetona_b;
}
}
@ -470,19 +470,19 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "Iso_butano")
{
_nameLectureRequeired = "Iso_butano";
_m = MQ303_Iso_butano_m;
_a = MQ303_Iso_butano_m;
_b = MQ303_Iso_butano_b;
}
else if(_nameLectureRequeired == "Hydrogeno")
{
_nameLectureRequeired = "Hydrogeno";
_m = MQ303_Hydrogeno_m;
_a = MQ303_Hydrogeno_m;
_b = MQ303_Hydrogeno_b;
}
else if(_nameLectureRequeired == "Ethanol")
{
_nameLectureRequeired = "Ethanol";
_m = MQ303_Ethanol_m;
_a = MQ303_Ethanol_m;
_b = MQ303_Ethanol_b;
}
}
@ -491,25 +491,25 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
if(_nameLectureRequeired == "H2")
{
_nameLectureRequeired = "H2";
_m = MQ309_H2_m;
_a = MQ309_H2_m;
_b = MQ309_H2_b;
}
else if(_nameLectureRequeired == "CH4")
{
_nameLectureRequeired = "CH4";
_m = MQ309_CH4_m;
_a = MQ309_CH4_m;
_b = MQ309_CH4_b;
}
else if(_nameLectureRequeired == "CO")
{
_nameLectureRequeired = "CO";
_m = MQ309_CO_m;
_a = MQ309_CO_m;
_b = MQ309_CO_b;
}
else if(_nameLectureRequeired == "Alcohol")
{
_nameLectureRequeired = "Alcohol";
_m = MQ309_Alcohol_m;
_a = MQ309_Alcohol_m;
_b = MQ309_Alcohol_b;
}
}
@ -522,13 +522,10 @@ float MQUnifiedsensor::readPPM(int m, int b) {
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
_sensor_volt = this->getVoltage();
//_RS_Calc; //Define variable for sensor resistance
_RS_Calc = ((_VOLT_RESOLUTION*_RLValue)/_sensor_volt)-_RLValue; //Get value of RS in a gas
_ratio = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air
float ppm = a*pow(_ratio, b);
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);
}
long MQUnifiedsensor::calibrate(boolean print) {

View File

@ -62,190 +62,190 @@
/**********************Application Related Macros**********************************/
/* Gas, Value of m (Slope) and b (Cut on x axis) points */
//Values consolidated
//Equation PPM = a*((x)^b)
/********************** MQ2 ******************************************************/
#define MQ2_H2_m -2.2459
#define MQ2_H2_a -2.2459
#define MQ2_H2_b 2.9845
#define MQ2_LPG_m -2.2879
#define MQ2_LPG_a -2.2879
#define MQ2_LPG_b 2.7901
#define MQ2_CO_m -2.6208
#define MQ2_CO_a -2.6208
#define MQ2_CO_b 3.6075
#define MQ2_Alcohol_m -3.1157
#define MQ2_Alcohol_a -3.1157
#define MQ2_Alcohol_b 4.5134
#define MQ2_Propane_m -2.7028
#define MQ2_Propane_a -2.7028
#define MQ2_Propane_b 3.5595
#define MQ2_Benzene_m -2.2879
#define MQ2_Benzene_a -2.2879
#define MQ2_Benzene_b 2.7901
/********************** MQ3 ******************************************************/
#define MQ3_LPG_m -3.1851
#define MQ3_LPG_a -3.1851
#define MQ3_LPG_b 4.7048
#define MQ3_CH4_m -17.531
#define MQ3_CH4_a -17.531
#define MQ3_CH4_b 28.785
#define MQ3_CO_m -4.339
#define MQ3_CO_a -4.339
#define MQ3_CO_b 6.4432
#define MQ3_Alcohol_m -1.435
#define MQ3_Alcohol_a -1.435
#define MQ3_Alcohol_b 0.4103
#define MQ3_Benzene_m -2.7009
#define MQ3_Benzene_a -2.7009
#define MQ3_Benzene_b 0.632
#define MQ3_Hexane_m -2.7268
#define MQ3_Hexane_a -2.7268
#define MQ3_Hexane_b 3.6299
/********************** MQ4 ******************************************************/
#define MQ4_LPG_m -2.5818
#define MQ4_LPG_a -2.5818
#define MQ4_LPG_b 3.6303
#define MQ4_CH4_m 0.9873
#define MQ4_CH4_a 0.9873
#define MQ4_CH4_b 2.6386
#define MQ4_CO_m -5.5945
#define MQ4_CO_a -5.5945
#define MQ4_CO_b 5.6693
#define MQ4_Alcohol_m -11.89
#define MQ4_Alcohol_a -11.89
#define MQ4_Alcohol_b 9.0375
#define MQ4_smoke_m -11.189
#define MQ4_smoke_a -11.189
#define MQ4_smoke_b 9.0375
/********************** MQ5 ******************************************************/
#define MQ5_H2_m -4.368
#define MQ5_H2_a -4.368
#define MQ5_H2_b 2.9667
#define MQ5_LPG_m -2.5723
#define MQ5_LPG_a -2.5723
#define MQ5_LPG_b 1.8943
#define MQ5_CH4_m -2.4438
#define MQ5_CH4_a -2.4438
#define MQ5_CH4_b 2.3044
#define MQ5_CO_m -4.8188
#define MQ5_CO_a -4.8188
#define MQ5_CO_b 5.2023
#define MQ5_Alcohol_m -4.419
#define MQ5_Alcohol_a -4.419
#define MQ5_Alcohol_b 4.8044
/********************** MQ6 ******************************************************/
#define MQ6_H2_m -3.6775
#define MQ6_H2_a -3.6775
#define MQ6_H2_b 5.0286
#define MQ6_LPG_m -1.6567
#define MQ6_LPG_a -1.6567
#define MQ6_LPG_b 2.8775
#define MQ6_CH4_m -1
#define MQ6_CH4_a -1
#define MQ6_CH4_b 3.301
#define MQ6_CO_m -12.791
#define MQ6_CO_a -12.791
#define MQ6_CO_b 14.523
#define MQ6_Alcohol_m -5.8057
#define MQ6_Alcohol_a -5.8057
#define MQ6_Alcohol_b 7.5292
/********************** MQ7 ******************************************************/
#define MQ7_H2_m -1.329
#define MQ7_H2_a -1.329
#define MQ7_H2_b 1.8864
#define MQ7_LPG_m -7.8626
#define MQ7_LPG_a -7.8626
#define MQ7_LPG_b 9.1056
#define MQ7_CH4_m -5.4878
#define MQ7_CH4_a -5.4878
#define MQ7_CH4_b 8.8387
#define MQ7_CO_m -1.4065
#define MQ7_CO_a -1.4065
#define MQ7_CO_b 2.0162
#define MQ7_Alcohol_m -6.3219
#define MQ7_Alcohol_a -6.3219
#define MQ7_Alcohol_b 9.924
/********************** MQ8 ******************************************************/
#define MQ8_H2_m -0.7152
#define MQ8_H2_a -0.7152
#define MQ8_H2_b 2.9891
#define MQ8_LPG_m -3.419
#define MQ8_LPG_a -3.419
#define MQ8_LPG_b 7.3513
#define MQ8_CH4_m -7.5609
#define MQ8_CH4_a -7.5609
#define MQ8_CH4_b 15.243
#define MQ8_CO_m -7.0753
#define MQ8_CO_a -7.0753
#define MQ8_CO_b 15.396
#define MQ8_Alcohol_m -1.7459
#define MQ8_Alcohol_a -1.7459
#define MQ8_Alcohol_b 4.7575
/********************** MQ9 ******************************************************/
#define MQ9_LPG_m -2.2535
#define MQ9_LPG_a -2.2535
#define MQ9_LPG_b 2.9855
#define MQ9_CH4_m -1.6012
#define MQ9_CH4_a -1.6012
#define MQ9_CH4_b 3.1476
#define MQ9_CO_m -1.749
#define MQ9_CO_a -1.749
#define MQ9_CO_b 2.827
/********************** MQ131 ******************************************************/
#define MQ131_NOx_m -2.7245
#define MQ131_NOx_a -2.7245
#define MQ131_NOx_b 3.3004
#define MQ131_CL2_m -1.0333
#define MQ131_CL2_a -1.0333
#define MQ131_CL2_b 1.7117
#define MQ131_O3_m -1.2037
#define MQ131_O3_a -1.2037
#define MQ131_O3_b 1.6455
/********************** MQ135 ******************************************************/
#define MQ135_CO_m -2.7268
#define MQ135_CO_a -2.7268
#define MQ135_CO_b 2.301
#define MQ135_Alcohol_m -2.8608
#define MQ135_Alcohol_a -2.8608
#define MQ135_Alcohol_b 1.8627
#define MQ135_CO2_m -3.2819
#define MQ135_CO2_a -3.2819
#define MQ135_CO2_b 1.9903
#define MQ135_Tolueno_m -5.7015
#define MQ135_Tolueno_a -5.7015
#define MQ135_Tolueno_b 1.1612
#define MQ135_NH4_m -2.2119
#define MQ135_NH4_a -2.2119
#define MQ135_NH4_b 2.0473
#define MQ135_Acetona_m -5.9682
#define MQ135_Acetona_a -5.9682
#define MQ135_Acetona_b 1.0175
/********************** MQ303 ******************************************************/
#define MQ303_Iso_butano_m -2.3543
#define MQ303_Iso_butano_a -2.3543
#define MQ303_Iso_butano_b 1.144
#define MQ303_Hydrogeno_m -2.4338
#define MQ303_Hydrogeno_a -2.4338
#define MQ303_Hydrogeno_b 0.7558
#define MQ303_Ethanol_m -2.5597
#define MQ303_Ethanol_a -2.5597
#define MQ303_Ethanol_b 0.4436
/********************** MQ309 ******************************************************/
#define MQ309_H2_m -2.1311
#define MQ309_H2_a -2.1311
#define MQ309_H2_b 3.0886
#define MQ309_CH4_m -1.6554
#define MQ309_CH4_a -1.6554
#define MQ309_CH4_b 2.985
#define MQ309_CO_m -4.7623
#define MQ309_CO_a -4.7623
#define MQ309_CO_b 6.7413
#define MQ309_Alcohol_m -3.7686
#define MQ309_Alcohol_a -3.7686
#define MQ309_Alcohol_b 5.6744
/*
@ -293,7 +293,7 @@ class MQUnifiedsensor
int _VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
int _RLValue = 10; //Value in KiloOhms
float _PPM, _RS_Calc;
float _ratioInCleanAir, _sensor_volt, RS_air, _m, _b, _ratio;
float _ratioInCleanAir, _sensor_volt, RS_air, _a, _b, _ratio;
};