mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Fixed MQ-131 Issue
This commit is contained in:
parent
b9a5e62899
commit
688827ffb4
@ -17,6 +17,8 @@
|
|||||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||||
|
|
||||||
|
Note: high concentration MQ-131 sensor.
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -83,11 +85,12 @@ void setup() {
|
|||||||
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
|
||||||
/***************************** MQ CAlibration ********************************************/
|
/***************************** MQ CAlibration ********************************************/
|
||||||
MQ131.serialDebug(true);
|
MQ131.serialDebug(true);
|
||||||
|
Serial.println("Ignore Ratio = RS/R0, for this example we will use readSensorR0Rs, the ratio calculated will be R0/Rs. Thanks :)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
MQ131.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
MQ131.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
MQ131.readSensorR0Rs(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
MQ131.serialDebug(); // Will print the table on the serial port
|
MQ131.serialDebug(); // Will print the table on the serial port
|
||||||
delay(500); //Sampling frequency
|
delay(500); //Sampling frequency
|
||||||
}
|
}
|
@ -143,6 +143,24 @@ float MQUnifiedsensor::readSensor()
|
|||||||
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||||
return _PPM;
|
return _PPM;
|
||||||
}
|
}
|
||||||
|
float MQUnifiedsensor::readSensorR0Rs()
|
||||||
|
{
|
||||||
|
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
|
_RS_Calc = ((_VOLT_RESOLUTION*_RL)/_sensor_volt)-_RL; //Get value of RS in a gas
|
||||||
|
if(_RS_Calc < 0) _RS_Calc = 0; //No negative values accepted.
|
||||||
|
_ratio = this->_R0/_RS_Calc; // Get ratio RS_air/RS_gas <- INVERTED for MQ-131 issue 28 https://github.com/miguel5612/MQSensorsLib/issues/28
|
||||||
|
if(_ratio <= 0) _ratio = 0; //No negative values accepted or upper datasheet recomendation.
|
||||||
|
if(_regressionMethod == 1) _PPM= _a*pow(_ratio, _b); // <- Source excel analisis https://github.com/miguel5612/MQSensorsLib_Docs/tree/master/Internal_design_documents
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// https://jayconsystems.com/blog/understanding-a-gas-sensor <- Source of linear ecuation
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation.
|
||||||
|
//if(_PPM > 10000) _PPM = 99999999; //No negative values accepted or upper datasheet recomendation.
|
||||||
|
return _PPM;
|
||||||
|
}
|
||||||
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
float MQUnifiedsensor::calibrate(float ratioInCleanAir) {
|
||||||
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
//More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor
|
||||||
/*
|
/*
|
||||||
|
@ -30,6 +30,7 @@ class MQUnifiedsensor
|
|||||||
//user functions
|
//user functions
|
||||||
float calibrate(float ratioInCleanAir);
|
float calibrate(float ratioInCleanAir);
|
||||||
float readSensor();
|
float readSensor();
|
||||||
|
float readSensorR0Rs();
|
||||||
float validateEcuation(float ratioInput = 0);
|
float validateEcuation(float ratioInput = 0);
|
||||||
|
|
||||||
//get function for info
|
//get function for info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user