miguel5612 / MQSensorsLib

We present a unified library for MQ sensors, this library allows to read MQ signals easily from Arduino, Genuino, ESP8266, ESP-32 boards whose references are MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ136, MQ303A, MQ309A.
MIT License
173 stars 64 forks source link

MQ-3 sensor and CH4 gas reading 'ovf' failure #75

Open AndroidCrypto opened 3 months ago

AndroidCrypto commented 3 months ago

Describe the bug I'm trying to read the CH4 gas concentration with a MQ-3 sensor using these values for 'setA' and 'setB':

MQ3.setA(2*10^31);
MQ3.setB(19.01);
float ch4 = MQ3.readSensor();

Unfortunately, the library gives an 'ovf' as output. All other gas readings are working.

Additional context I tested the library on with Arduino Uno R4 Wi-Fi microcontroller and 5V for VCC. The sensor is connected to A0 on the Arduino.

miguel5612 commented 2 months ago

Thank you for reporting this issue. It seems that the overflow might be caused by the extremely large value used for setA (2*10^31), which is likely exceeding the limits of the variable type. To resolve this, we suggest adjusting the variable types or using alternative mathematical operations that handle large numbers more efficiently.

If you're able to make these changes and test them, it would be fantastic if you could contribute a merge request with the modifications. This would be a great enhancement to the library, and we appreciate your help in improving it!