MQ131 Module – PPM Calculation Support

Hi there,

I have the MQ-131 sensor module, which can be found at the following link:

I wrote a code with the help of ChatGPT, but I suspect that the calculations are incorrect and I am getting inaccurate readings because I do not know the RL resistance on the module.

For more precise measurements (12-bit), I am using an ESP32. Since the module operates at 5V and the ESP32 analog pin can only read a maximum of 3.3V, I am using a 5V to 3.3V logic level converter.

How can I perform the calculations correctly? Do you have any knowledge about this module? I would appreciate your support.

The code generated by ChatGPT:

// MQ131 Sensor Settings
const float RL = 10.0;     // Load resistance (in kilo-ohms) - Check the RL value on the module
float R0 = 30.0;           // Clean air reference resistance (in kilo-ohms) - Requires calibration

// Calibration curve coefficients (taken from the MQ131 Datasheet)
const float m = -2.3;      // Slope of the curve (for high concentration region)
const float b = 0.5;       // Y-axis intercept of the curve

// Analog sensor pin
const int sensorPin = 34;  // GPIO34 will be used (input only)

void setup() {
  Serial.begin(9600);      // Start serial communication
}

void loop() {
  int sensorValue = analogRead(sensorPin);  // Read the analog value (12-bit resolution)
  float Vout = sensorValue * (3.3 / 4095.0);  // Convert the read value to voltage
  float Rs = ((3.3 - Vout) / Vout) * RL;      // Calculate Rs
  
  float ratio = Rs / R0;                      // Calculate the Rs / R0 ratio
  float log_ppm = (log10(ratio) * m) + b;     // Logarithmic PPM calculation
  float ppm = pow(10, log_ppm);               // Convert concentration to ppm
  
  // Print the results to the serial monitor
  Serial.print("Analog Value: ");
  Serial.println(sensorValue);
  Serial.print("Ozone Concentration (ppm): ");
  Serial.println(ppm);

  delay(1000);  // Wait for 1 second
}

That's not the way to do it. Logic level converters convert digital signals. To convert a 5V analogue input to 3.3V analogue input, a resistor divider could be used.

Have a look at this library. Perhaps get the example working on an Uno or classic Nano to start with. Then when you have that working work out how to port it to ESP32.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.