Arduino MQ135气体感应器

阅读: 评论:0

Arduino MQ135气体感应器

Arduino MQ135气体感应器

Arduino MQ135气体感应器

一、接线

    MQ135有4个引脚,分别为VCC、GND、A0、D0,这里只需要使用到VCC、GND、A0.以下图是esp8266接线图。由于测量气体值PPM时,跟空气的温湿度是相关的。所以我们这里加了一个DHT22。DHT22传送门

VCC->3V

GND->G

A0->A0

二、MQ135库

    下载地址:

    下载完成后,拷贝到arduino库目录下

三、代码

#define DHT_TYPE     DHT11
#define DHT_PIN      2  //pin d4

#define ANALOGPIN    A0

DHT dht(DHT_PIN, DHT_TYPE);

MQ135 gasSensor = MQ135(ANALOGPIN);

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

}

void loop() {
    float h = adHumidity();
    // Read temperature as Celsius (the default)
    float t = adTemperature();
    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t))
    {
      Serial.println("Failed to read from DHT sensor!");
      delay(1000);
      return;
    }
    Serial.print("hum=");
    Serial.print(h); // this to display the rzero value continuously, uncomment this to get ppm value
    Serial.println("%");
    Serial.print("temp=");
    Serial.print(t); // this to display the rzero value continuously, uncomment this to get ppm value
    Serial.println("C");
    
    rzero = RZero(); //this to get the rzero value, uncomment this to get ppm value
    Serial.print("RZero=");
    Serial.println(rzero); // this to display the rzero value continuously, uncomment this to get ppm value
     
    ppm = PPM(); // this to get ppm value, uncomment this to get rzero value
    Serial.print("PPM=");
    Serial.println(ppm); // this to display the ppm value continuously, uncomment this to get rzero value
    
    ppmbalanced = CorrectedPPM(t, h); // this to get ppm value, uncomment this to get rzero value
    Serial.print("PPM Corrected=");
    Serial.println(ppmbalanced); // this to display the ppm value continuously, uncomment this to get rzero value

四、总结

从MQ135文档中,我们了解到,MQ135要正常工作,需要预热不少于48小时。中文文档传送门

本文发布于:2024-01-31 01:03:16,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170663419724202.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:51单片机
标签:感应器   气体   Arduino
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23