Hello! I need Help with my MQ-135 Sensor, i'm using this code, but the PPM doesn't match with the r
Hello! I need Help with my MQ-135 Sensor, i'm using this code, but the PPM doesn't match with the real PPM
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int mqPin = 14; // Pin where the MQ-135 sensor is connected (A0 -> GPIO15)
int valorSensor = 0; // Variable to store the analog reading
// Calibration parameters (adjust these)
float A = 500; // Start with an initial guess for A
float B = -2.5; // Start with an initial guess for B
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD initialization
void setup() {
Serial.begin(115200);
pinMode(mqPin, INPUT);
Wire.begin();
Wire.setClock(100000);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("CO2 PPM:");
delay(1000);
}
void loop() {
long suma = 0;
int cantidad = 10;
// Average sensor readings
for (int i = 0; i < cantidad; i++) {
suma += analogRead(mqPin);
delay(100);
}
valorSensor = suma / cantidad;
// Debugging: Print raw value
Serial.print("Raw sensor value: ");
Serial.println(valorSensor);
// Calculate PPM from the sensor value using calibration constants A and B
float ppmCO2 = A * pow(valorSensor / 1023.0, B);
// Debugging: Print calculated PPM
Serial.print("Calculated CO2 PPM: ");
Serial.println(ppmCO2);
// Update LCD with PPM value
lcd.setCursor(0, 1);
lcd.print("PPM: ");
lcd.print(ppmCO2);
lcd.print(" ");
delay(500);
}
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int mqPin = 14; // Pin where the MQ-135 sensor is connected (A0 -> GPIO15)
int valorSensor = 0; // Variable to store the analog reading
// Calibration parameters (adjust these)
float A = 500; // Start with an initial guess for A
float B = -2.5; // Start with an initial guess for B
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD initialization
void setup() {
Serial.begin(115200);
pinMode(mqPin, INPUT);
Wire.begin();
Wire.setClock(100000);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("CO2 PPM:");
delay(1000);
}
void loop() {
long suma = 0;
int cantidad = 10;
// Average sensor readings
for (int i = 0; i < cantidad; i++) {
suma += analogRead(mqPin);
delay(100);
}
valorSensor = suma / cantidad;
// Debugging: Print raw value
Serial.print("Raw sensor value: ");
Serial.println(valorSensor);
// Calculate PPM from the sensor value using calibration constants A and B
float ppmCO2 = A * pow(valorSensor / 1023.0, B);
// Debugging: Print calculated PPM
Serial.print("Calculated CO2 PPM: ");
Serial.println(ppmCO2);
// Update LCD with PPM value
lcd.setCursor(0, 1);
lcd.print("PPM: ");
lcd.print(ppmCO2);
lcd.print(" ");
delay(500);
}




