Fixed overflow

This commit is contained in:
miguel5612 2020-03-26 11:17:46 -05:00
parent abac48da38
commit 1b351f9495
2 changed files with 15 additions and 7 deletions

View File

@ -38,17 +38,22 @@ void setup() {
Remarks: This function create the sensor object. Remarks: This function create the sensor object.
************************************************************************************/ ************************************************************************************/
MQ3.setRegressionMethod("Exponential"); 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.init();
MQ3.serialDebug(true); MQ3.serialDebug(true);
//pinMode(calibration_button, INPUT); //pinMode(calibration_button, INPUT);
} }
void loop() { void loop() {
MQ3.update(); // Update data, the arduino will be read the voltaje in the analog pin 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
//Si el valor de RL es diferente a 10K por favor asigna tu valor de RL con el siguiente metodo: MQ3.serialDebug(); // Will print the table on the serial port
MQ3.setRL(10);
*/
/* /*
//Rutina de calibracion - Uncomment if you need (setup too and header) //Rutina de calibracion - Uncomment if you need (setup too and header)
if(calibration_button) if(calibration_button)
@ -57,6 +62,7 @@ void loop() {
MQ3.setR0(R0); MQ3.setR0(R0);
} }
*/ */
/***************************** MQReadSensor **************************************** /***************************** MQReadSensor ****************************************
Input: Gas - Serial print flag Input: Gas - Serial print flag
Output: Value in PPM Output: Value in PPM
@ -66,6 +72,7 @@ void loop() {
//Lecture will be saved in lecture variable //Lecture will be saved in lecture variable
//float lecture = MQ3.readSensor("", true); // Return Alcohol concentration //float lecture = MQ3.readSensor("", true); // Return Alcohol concentration
// Options, uncomment where you need // Options, uncomment where you need
/*
MQ3.setA(2*10^31); MQ3.setB(19.01); // Configurate the ecuation values MQ3.setA(2*10^31); MQ3.setB(19.01); // Configurate the ecuation values
CH4 = MQ3.readSensor(); // Return CH4 concentration CH4 = MQ3.readSensor(); // Return CH4 concentration
@ -83,6 +90,7 @@ void loop() {
MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values MQ3.setA(4.8387); MQ3.setB(-2.68); // Configurate the ecuation values
Benzine = MQ3.readSensor(); // Return Benzene concentration Benzine = MQ3.readSensor(); // Return Benzene concentration
*/
/* /*
Serial.println("***************************"); Serial.println("***************************");
@ -97,5 +105,4 @@ void loop() {
Serial.print("Benzine: ");Serial.print(Benzine,2);Serial.println(" mg/L"); Serial.print("Benzine: ");Serial.print(Benzine,2);Serial.println(" mg/L");
Serial.println("***************************"); Serial.println("***************************");
*/ */
MQ3.serialDebug();
} }

View File

@ -41,6 +41,7 @@ void MQUnifiedsensor::serialDebug(bool onSetup)
{ {
if(onSetup) if(onSetup)
{ {
Serial.println();
Serial.println("************************************************************************************************************************************************"); Serial.println("************************************************************************************************************************************************");
Serial.println("MQ sensor reading library for arduino"); 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 == "Exponential") _PPM= _a*pow(_ratio, _b);
if(_regressionMethod == "Linear") _PPM= _a*_ratio + _b; if(_regressionMethod == "Linear") _PPM= _a*_ratio + _b;
if(_PPM < 0) _PPM = 0; //No negative values accepted or upper datasheet recomendation. 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; return _PPM;
} }
float MQUnifiedsensor::calibrate() { float MQUnifiedsensor::calibrate() {