From 1b351f9495d0150a4d821d0703eedad37f12897b Mon Sep 17 00:00:00 2001 From: miguel5612 Date: Thu, 26 Mar 2020 11:17:46 -0500 Subject: [PATCH] Fixed overflow --- examples/MQ-3/MQ-3.ino | 19 +++++++++++++------ src/MQUnifiedsensor.cpp | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/MQ-3/MQ-3.ino b/examples/MQ-3/MQ-3.ino index e94f6bc..992715d 100644 --- a/examples/MQ-3/MQ-3.ino +++ b/examples/MQ-3/MQ-3.ino @@ -38,17 +38,22 @@ void setup() { Remarks: This function create the sensor object. ************************************************************************************/ MQ3.setRegressionMethod("Exponential"); + MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values + + /* + //Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: + MQ3.setRL(10); + */ + MQ3.init(); MQ3.serialDebug(true); //pinMode(calibration_button, INPUT); } void loop() { - MQ3.update(); // Update data, the arduino will be read the voltaje in the analog pin - /* - //Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: - MQ3.setRL(10); - */ + MQ3.update(); // Update data, the arduino will be read the voltage on the analog pin + MQ3.readSensor(); // Sensor will read PPM concentration using the a and b values setted before or on setup + MQ3.serialDebug(); // Will print the table on the serial port /* //Rutina de calibracion - Uncomment if you need (setup too and header) if(calibration_button) @@ -57,6 +62,7 @@ void loop() { MQ3.setR0(R0); } */ + /***************************** MQReadSensor **************************************** Input: Gas - Serial print flag Output: Value in PPM @@ -66,6 +72,7 @@ void loop() { //Lecture will be saved in lecture variable //float lecture = MQ3.readSensor("", true); // Return Alcohol concentration // Options, uncomment where you need + /* MQ3.setA(2*10^31); MQ3.setB(19.01); // Configurate the ecuation values CH4 = MQ3.readSensor(); // Return CH4 concentration @@ -83,6 +90,7 @@ void loop() { MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values Benzine = MQ3.readSensor(); // Return Benzene concentration + */ /* Serial.println("***************************"); @@ -97,5 +105,4 @@ void loop() { Serial.print("Benzine: ");Serial.print(Benzine,2);Serial.println(" mg/L"); Serial.println("***************************"); */ - MQ3.serialDebug(); } \ No newline at end of file diff --git a/src/MQUnifiedsensor.cpp b/src/MQUnifiedsensor.cpp index 6c83704..f074fd3 100644 --- a/src/MQUnifiedsensor.cpp +++ b/src/MQUnifiedsensor.cpp @@ -41,6 +41,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup) { if(onSetup) { + Serial.println(); Serial.println("************************************************************************************************************************************************"); Serial.println("MQ sensor reading library for arduino"); @@ -93,7 +94,7 @@ float MQUnifiedsensor::readSensor() if(_regressionMethod == "Exponential") _PPM= _a*pow(_ratio, _b); if(_regressionMethod == "Linear") _PPM= _a*_ratio + _b; if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation. - if(_PPM > 10000) _PPM = 9999; //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() {