會想做這個主題的原因是受到一本書-日常生活的能源革命第二章第二節<匯集公民力量的空汙戰鬥器>的啟發,在書中提到的空氣盒子(Airbox)是能感測PM2.5、CO2、溫度和相對溼度,並且能讓空氣盒子連上網路、上傳至平台和用戶分享,建立一個空氣品質的地圖。
有感測PM2.5、溫度和相對溼度的功能
AM2302數位溫濕度感測器是一款含有已校準數位信號輸出的溫濕度複合 感測器。它應用專用的數位模組採集技術和溫濕度傳感技術,確保產品具有極 高的可靠性與卓越的長期穩定性。感測器包括一個電容式感濕元件和一個NTC 測溫元件,並與一個高性能8位單片機相連接。因此該產品具有品質卓越、超 快回應、抗干擾能力強、性價比極高等優點。每個AM2302感測器都在極為精確 的濕度校驗室中進行校準。校準係數以程式的形式儲存在OTP記憶體中,感測器 內部在檢測信號的處理過程中要調用這些校準係數。單線制序列介面,使系統 集成變得簡易快捷。超小的體積、極低的功耗,信號傳輸距離可達20米以上, 使其成為各類應用甚至最為苛刻的應用場合的最佳選則。產品為 4 針單排引 腳封裝。連接方便,特殊封裝形式可根據使用者需求而提供 。
GP2Y1014AU0F 是一款光學空氣品質感測器,設計用來感測空氣中的塵埃粒子,其內部對角安裝紅外線發光二極體和光電晶體,使其能夠探測空氣中塵埃反射光,即使非常細小的如煙草煙霧顆粒也能夠被檢測到,通常應用在空氣淨化系統中。該感測器具有非常低的電流消耗(最大20mA,典型值11mA),可使用高達7VDC。
可測量0.8微米以上的微小粒子,感知煙草產生的煙氣和花粉,房屋粉塵等.體積小,重量輕,便於安裝
DAT 改接到D3
//DHT22
#include <DHT.h>; //import Libraries
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Varibles
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
//DHT22
//GP2Y1010AU0F
int measurePin = 0; //Connect dust sensor to Arduino A0 pin
int ledPower = 2; //Connect 3 led driver pins of dust sensor to Arduino D2
int samplingTime = 280; //time require to sample signal coming out of the sensor
int deltaTime = 40;
int sleepTime = 9680;
//variable
float voMeasured = 0; //data is sensed by A0
float calcVoltage = 0;
float dustDensity = 0;
//GP2Y1010AU0F
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT); //output pin is on D2(set up the function of pin D2)
//DHT22
dht.begin();
}
void loop(){
//GP2Y1010AU0F
//The total measurement process takes around 10ms but the sampling period is 0.28ms.
//make the ledpin low that turns on the led and we use the delayMicroseconds() function to generate a 0.28mS delay
//that is recommended by the datasheet. Then we take our sample and add another delay of 40uS,
//this will ensure the pulse width remains at .32ms or 320us and we sleep for the rest of the 9680uS.
//we calculate the voltage value from the ADC(analog to digital converter) value.
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime);//delay samplingTime microsecond
voMeasured = analogRead(measurePin); // read the dust value(A0 pin) to calculate the voltage value from the ADC(analog to digital converter) value.
delayMicroseconds(deltaTime);//delay deltaTime microsecond
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime);
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0); //turn the data sensed by A0 by the function
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
// Chris Nafis (c) 2012
dustDensity = 0.172* calcVoltage - 0.0999;
//GP2Y1010AU0F
//DHT22
hum = dht.readHumidity();
temp= dht.readTemperature();
//DHT22
Serial.print(" Voltage: ");
Serial.print(calcVoltage);
Serial.print(" Dust Density: ");
Serial.print(dustDensity * 1000); // 這裡將數值呈現改成較常用的單位( ug/m3 )
Serial.println(" ug/m3 ");
Serial.print(" Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(3000);//delay
}