基于MQ-135的空气检测器
本人小白第一次发帖子,最近想做一个空气净化器,用到了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(检测一氧化碳的)都是通接线,通代码的!
新人发帖,还望大神多多指点。 自顶!!!!!!!!!!!!!!!!!!!!!! 你应该测量那个A0 本帖最后由 数字 于 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-2 14:25 static/image/common/back.gif
你应该测量那个A0
也对哈,当时只寻思检测一下子...
页:
[1]