极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11390|回复: 4

基于MQ-135的空气检测器

[复制链接]
发表于 2015-2-1 13:37:10 | 显示全部楼层 |阅读模式
            本人小白第一次发帖子,最近想做一个空气净化器,用到了MQ135的检测模块,可在网上搜了搜,几乎全是51的,看了一下程序挺简单的,所以用arduino来测试下~大神勿喷{:soso_e106:}
                                                
这是传说中的模块,某宝10元内,功能还算可以,也挺简单。下面就是连线:
                                                VCC--5v
                                                GND--GND
                                                A0   --A0
                                              DOUT--0
                                                
下面就是代码啦!
#define uchar unsigned char
#define LED 0
#define DOUT A0
void delay()
{
  uchar m, n, s;
  for (m = 20; m > 0; m--)
    for (n = 20; n > 0; n--)

      for (s = 248; s > 0; s--);
}

void setup()
{ pinMode(DOUT, OUTPUT);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}


void loop()
{
  while (1) //无限循环
  {
    digitalWrite(LED, 1);
    if (DOUT == 0)
    {
      delay();
      if (DOUT == 0)
      {
        digitalWrite(LED, 0);
        Serial.println();
      }
    }
  }
}
下载之后会发现MQ135的背后有一个红灯一个黄灯,通电后发现都亮,过几秒黄灯熄灭,之后随便抽一支烟(本人不吸烟,向别人要了一根,抽了一口过堂烟~~)向模块上吐,会发现黄灯有亮了起来~~~

总体来说还是很有意思,并且这些包括像MQ-9(检测一氧化碳的)都是通接线,通代码的!
新人发帖,还望大神多多指点。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2015-2-1 13:38:47 | 显示全部楼层
自顶!!!!!!!!!!!!!!!!!!!!!!
回复 支持 反对

使用道具 举报

发表于 2015-2-2 14:25:13 | 显示全部楼层
你应该测量那个A0
回复 支持 反对

使用道具 举报

发表于 2015-2-2 14:26:12 | 显示全部楼层
本帖最后由 数字 于 2015-2-2 14:27 编辑

这是我上传乐联网用的一段代码.


#include <LiquidCrystal.h>
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
   Serial.begin(9600);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("MQ135");
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);         
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);         

  Serial.print("M:");
  Serial.println(sensorValue);
  lcd.clear();
  lcd.print("MQ135");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(sensorValue);
  delay(1000);
  
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-4 19:32:32 | 显示全部楼层
数字 发表于 2015-2-2 14:25
你应该测量那个A0

也对哈,当时只寻思检测一下子...
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 17:24 , Processed in 0.052002 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表