How to find Co2 and O2 level using MQ135 with Arduino

Jitendra Reddy picture Jitendra Reddy · Jun 29, 2015 · Viewed 31.8k times · Source

How to find Co2 and O2 level or any other parameters using MQ135 with Arduino, I just sensed ppm data and displayed it on screen.

int sensorValue;
int pin8 = 8;
void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
  pinMode(pin8, OUTPUT);
}

void loop()
{
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.print(sensorValue, DEC);  // prints the value read
  Serial.println("ppm");
  if (sensorValue > 500) {
    // Activate digital output pin 8 - the LED will light up
    digitalWrite(pin8, HIGH);
  }
  else {
    // Deactivate digital output pin 8 - the LED will not light up
    digitalWrite(pin8, LOW);
  }

  delay(5000);                        // wait 100ms for next reading
}

Answer

GnoStiC picture GnoStiC · Jul 17, 2015

i've found that, if you're using the sensor for the first time, it's a good practice to leave it powered on for about 24 hours before getting a good read. Don't skip this step.

then comes the calibration process. just calibrate it to get about 100-150 from analogRead in a good air condition.

normal air returns ~100-150
alcohol returns ~700
lighter gas returns ~750+

edit:
just noticed this Arduino library for the MQ135 that might be helpful.

edit2:
i decided to update my code as well and found this great source. you can find all the code here.