From 700d367d93ef98b64b58067107486b0b4c1aec0b Mon Sep 17 00:00:00 2001 From: miguel5612 Date: Sun, 20 Mar 2022 09:32:31 -0500 Subject: [PATCH] Fix Rs calculation for MQ303A --- examples/MQ-303A/MQ303.ino | 2 +- src/MQUnifiedsensor.cpp | 5 ++++- src/MQUnifiedsensor.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/MQ-303A/MQ303.ino b/examples/MQ-303A/MQ303.ino index d98644b..7440dfb 100644 --- a/examples/MQ-303A/MQ303.ino +++ b/examples/MQ-303A/MQ303.ino @@ -86,7 +86,7 @@ void setup() { void loop() { MQ303.update(); // Update data, the arduino will be read the voltage on the analog pin - MQ303.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup + MQ303.readSensor(true); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup MQ303.serialDebug(); // Will print the table on the serial port delay(500); //Sampling frequency } \ No newline at end of file diff --git a/src/MQUnifiedsensor.cpp b/src/MQUnifiedsensor.cpp index 60e7ee5..64f4c1c 100644 --- a/src/MQUnifiedsensor.cpp +++ b/src/MQUnifiedsensor.cpp @@ -133,9 +133,12 @@ float MQUnifiedsensor::validateEcuation(float ratioInput) //Serial.println("Result: "); Serial.println(_PPM); return _PPM; } -float MQUnifiedsensor::readSensor() +float MQUnifiedsensor::readSensor(bool isMQ303A) { //More explained in: https://jayconsystems.com/blog/understanding-a-gas-sensor + if(isMQ303A) { + _VOLT_RESOLUTION = _VOLT_RESOLUTION - 0.45; //Calculations for RS using mq303a sensor look wrong #42 + } _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 = _RS_Calc / this->_R0; // Get ratio RS_gas/RS_air diff --git a/src/MQUnifiedsensor.h b/src/MQUnifiedsensor.h index 123b46d..865399d 100644 --- a/src/MQUnifiedsensor.h +++ b/src/MQUnifiedsensor.h @@ -31,7 +31,7 @@ class MQUnifiedsensor //user functions float calibrate(float ratioInCleanAir); - float readSensor(); + float readSensor(bool isMQ303A = false); float readSensorR0Rs(); float validateEcuation(float ratioInput = 0);