
空氣品質檢測裝置
功能介紹
本項目主要是實作基本的空氣品質檢測功能:
- PM2.5指數
- 空氣品質指數
- 空氣濕度
- 空氣溫度
準備材料
- Arduino UNO *1
- LCD 5110 *1
- DHT11溫濕度傳感器 *1
- MQ135空氣品質檢測子產品
- PM2.5粉塵檢測傳感器 (GP2Y1010AU0F) *1
- 150歐電阻 *1
- 220uF電解電容 *1
- 面包闆 *1
- 跳線若幹
就不給出購買連結了,這些材料在某寶上随便一搜就有~
子產品接線
-
LCD 5110與Arduino
LCD 5110 | Arduino | |
---|---|---|
RST | -> | 11 |
CE | 12 | |
DC | 10 | |
DIN | 9 | |
CLK | 8 | |
VCC | 5V | |
BL | GND | |
-
PM2.5粉塵檢測傳感器與Arduino
GP2Y1010AU0F | ||
---|---|---|
1 | 150歐電阻 | |
220uF電解電容 | ||
2 | ||
3 | ||
4 | ||
5 | A0 | |
6 |
-
MQ135空氣品質檢測子產品與Arduino
MQ135 | ||
---|---|---|
AOUT | A1 | |
-
DHT11溫濕度傳感器與Arduino
DHT11 | ||
---|---|---|
OUT |
第三方庫
#include <dht.h>
#include <LCD5110_Basic.h>
#include "MQ135.h"
下載下傳位址:
-
https://arduino-info.wikispaces.com/file/view/DHT-lib.zip/545470280/DHT-lib.zipdht.h
-
http://www.rinkydinkelectronics.com/download.php?f=LCD5110_Basic.zipLCD5110_Basic.h
-
https://codeload.github.com/GeorgK/MQ135/zip/masterMQ135.h
如果不知道如何手動加載庫檔案,或者不知道怎麼使用庫,請參考我之前寫的基礎教程:
源程式
#include <dht.h>
#include <LCD5110_Basic.h>
#include "MQ135.h"
//空氣品質
MQ135 gasSensor = MQ135(1);
//LCD5110
LCD5110 myGLCD(8,9,10,11,12);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
//溫濕度
dht DHT;
#define DHT11_PIN 5
//PM2.5
int dustPin=0;
float dustVal=0;
int ledPower=2;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
float a=0;
String s0 = " ";
String s1 = " ";
String s2 = " ";
String s3 = " ";
void setup()
{
Serial.begin(115200);
pinMode(ledPower,OUTPUT);
pinMode(dustPin, INPUT);
myGLCD.InitLCD(); //Intializing LCD
myGLCD.setContrast(55);
}
void pm25(){
digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
if (dustVal>36.455)
a = (float(dustVal/1024)-0.0356)*120000*0.035;
s0 = String("PM2.5: "+String(a));
myGLCD.setFont(SmallFont);
myGLCD.print(s0,0,8);
}
void ht(){
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
case DHTLIB_ERROR_CONNECT:
Serial.print("Connect error,\t");
break;
case DHTLIB_ERROR_ACK_L:
Serial.print("Ack Low error,\t");
break;
case DHTLIB_ERROR_ACK_H:
Serial.print("Ack High error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
myGLCD.setFont(SmallFont);
s1 = String("H : " + String(int(DHT.humidity)) + " %");
myGLCD.print(s1,0,24);
myGLCD.setFont(SmallFont);
s2 = String("T : " + String(int(DHT.temperature))+" C");
myGLCD.print(s2,0,32);
}
void ppm(){
float ppm = gasSensor.getPPM();
s3 = String("Air: " + String(ppm)+"ppm");
myGLCD.print(s3,0,16);
}
void loop(){
myGLCD.setFont(SmallFont);
myGLCD.print("Hello World",CENTER,0);
pm25();
ht();
ppm();
delay(2000);
myGLCD.clrScr();
}
源程式下載下傳位址
:
https://github.com/wwwxmu/ArduinoAirQuality附:測試得到的資料和空氣品質對照:
3000 + = 很差
1050-3000 = 差
300-1050 = 一般
150-300 = 好
75-150 = 很好
0-75 = 非常好
附:室内空氣品質對照表
室内空氣品質對照表