ostaquet / Arduino-MQ131-driver

Arduino driver for gas sensor MQ131 (Ozone / O3)
MIT License
64 stars 19 forks source link

live data #47

Closed gilshallem closed 2 years ago

gilshallem commented 2 years ago

Hi, noob question: If I call "MQ131.startHeater();" then can i check the values every x millis without stopping the heater, and in this way get live data?

Example: (I overrided the library to give me access to the private methods)

void setup() {
  lcd.begin(16, 2);
  Serial.begin(115200);

  MQ131.begin(2,A0, LOW_CONCENTRATION, 1000000);  
  lcd.setCursor(0,0);
  lcd.print("Calibrationing");

  MQ131.calibrate();

  lcd.setCursor(0,0);
  lcd.print("Heating...                     ");
  MQ131.startHeater();
}

void loop() {
  if (MQ131.isTimeToRead()) {
     MQ131.lastValueRs = MQ131.readRs();
     lcd.setCursor(0,0);
     lcd.print(String(MQ131.getO3(PPM),4) + " PPM                    ");
     lcd.setCursor(0,1);
     lcd.print(String(MQ131.getO3(MG_M3),4) + " mg/m3                    ");
  }
  delay(100);

}
ostaquet commented 2 years ago

I don't get the point of reading the values continuously as the sensor is a semiconductor gas sensor which detect gases by a chemical reaction that takes place when the gas comes in direct contact with the sensor. The concentration is calculated through a ratio between the the R0 (clean air) and RL (sample).

There are two points here:

  1. The calibration has nothing to do in the same code that the sampling (has the ratio between R0 and RL will always by 1).
  2. When the calibration is performed (R0 + timing), it is important to respected the same parameters in order to have reliable sampling.

Therefore, showing the values during the heating is not interesting; except for specific experiments or observations.

The library was designed to provide a ready-to-use driver for the sensor. If you want to do some experiment, I suggest cloning the library and modifying the code or design your own code to achieve your needs. You can also just copy/paste some pieces of code to reach your goal.