Added Linear ecuation on test algorithm

This commit is contained in:
miguel5612 2020-03-28 12:58:25 -05:00
parent ab77a7a4d7
commit 70fbaa9115
3 changed files with 11 additions and 4 deletions

View File

@ -99,6 +99,13 @@ void loop()
expectedValue[0] = 1000; expectedValue[1] = 3000; expectedValue[2] = 5000; expectedValue[3] = 7000;
testSensor("MQ-309", 1000000, -4.01);
// Testing linear equation for MQ-4
mySensor.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)
ratio[0] = 2.5; ratio[1] = 1.5; ratio[2] = 0.9; ratio[3] = 0.65;
expectedValue[0] = 200; expectedValue[1] = 1000; expectedValue[2] = 5000; expectedValue[3] = 10000;
testSensor("MQ-4", -0.318, 1.133);
while(1);
}

View File

@ -37,7 +37,7 @@ void setup() {
Serial.begin(9600); //Init serial port
//Set math model to calculate the PPM concentration and the value of constants
MQ4.setRegressionMethod(0); //_PPM = a*ratio + b
MQ4.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)

View File

@ -112,9 +112,9 @@ float MQUnifiedsensor::validateEcuation(float ratioInput)
if(_regressionMethod == 1) _PPM= _a*pow(ratioInput, _b);
else
{
// https://jayconsystems.com/blog/understanding-a-gas-sensor
double ppm_log = (log10(_ratio)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
// https://jayconsystems.com/blog/understanding-a-gas-sensor
double ppm_log = (log10(ratioInput)-_b)/_a; //Get ppm value in linear scale according to the the ratio value
_PPM = pow(10, ppm_log); //Convert ppm value to log scale
}
//Serial.println("Regression Method: "); Serial.println(_regressionMethod);
//Serial.println("Result: "); Serial.println(_PPM);