如何使用MQ135和Arduino找到Co2和O2水平

时间:2015-06-29 06:22:33

标签: arduino-uno iot

如何使用带有Arduino的MQ135查找Co2和O2级别或任何其他参数,我只是检测到ppm数据并在屏幕上显示。

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
}

2 个答案:

答案 0 :(得分:3)

我发现,如果您是第一次使用传感器,最好先将其打开电源约24小时,然后再进行良好的阅读。不要跳过这一步。

然后是校准过程。只需在良好的空气条件下校准它就可以从analogRead获得大约100-150。

正常空气返回~100-150
酒精回归~700
较轻的气体返回~750 +

编辑:
刚刚注意到这可能有用的Arduino library for the MQ135

EDIT2:
我决定更新我的代码并找到this great source。你可以找到所有代码here

答案 1 :(得分:0)

我已经使用DHT22来测量实际温度和湿度,以获得正确的ppm来发现空气质量。

#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);
}

如果您或任何人需要进一步的帮助,请与我联系。