3

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
}
Jitendra Reddy
  • 31
  • 1
  • 1
  • 5

2 Answers2

5

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.

GnoStiC
  • 552
  • 4
  • 7
1

I have made use of DHT22 to measure actual temperature and humidity to get correct ppm for finding air quality.

#include <DHT.h>

#define DHTTYPE DHT22

#include "MQ135.h"

// MQ135 gas sensor
//
// Datasheet can be found here: https://www.olimex.com/Products/Components/Sensors/SNS-MQ135/resources/SNS-MQ135.pdf
//
// Application
// They are used in air quality control equipments for buildings/offices, are suitable for detecting of NH3, NOx, alcohol, Benzene, smoke, CO2, etc
//
// Original creator of this library: https://github.com/GeorgK/MQ135


DHT dht(2, DHTTYPE);

#define PIN_MQ135 A2
MQ135 mq135_sensor = MQ135(PIN_MQ135);

float temperature = 28.0; // assume current temperature. Recommended to measure with DHT22
float humidity = 25.0; // assume current humidity. Recommended to measure with DHT22

void setup() {
  Serial.begin(9600);
}

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  if (isnan(humidity) || isnan(temperature))
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


  float rzero = mq135_sensor.getRZero();
  float correctedRZero = mq135_sensor.getCorrectedRZero(temperature, humidity);
  float resistance = mq135_sensor.getResistance();
  float ppm = mq135_sensor.getPPM();
  float correctedPPM = mq135_sensor.getCorrectedPPM(temperature, humidity);

  Serial.print("MQ135 RZero: ");
  Serial.print(rzero);
  Serial.print("\t Corrected RZero: ");
  Serial.print(correctedRZero);
  Serial.print("\t Resistance: ");
  Serial.print(resistance);
  Serial.print("\t PPM: ");
  Serial.print(ppm);
  Serial.print("\t Corrected PPM: ");
  Serial.print(correctedPPM);
  Serial.print("ppm @ temp/hum: ");
  Serial.print(temperature);
  Serial.print("/");
  Serial.print(humidity);
  Serial.println("%");
  delay(600);
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197