PM2.5 sensor - G3 PMS3003
Ref: http://www.icshop.com.tw/product_info.php/products_id/20460
我在 ICShopping 買了一個 G3 PMS3003.
他是透過 uart 溝通, 我們可以將 RXD/TXD 與 Ameba 的 D0/D1 對接.
Serial1 (D0/D1) 使用可參考 :
http://njiot.blogspot.tw/2015/08/arduino-ameba-uart-serial.html
比較麻煩的是接線, 他的頭是 Molex 1.25mm 間距.
所以首先我去買了一條 1.25mm 端子線.
接下來因為 1.25mm 比較細, 所以另外又加工把 2.54 的排插焊上去.
斜口鉗剪斷, 並用膠帶貼好,
我買的這條線, 紅色位置和實際 VCC 位置不同, 只好自行在膠帶上做記號.
pin1 VCC - 接 5V
pin2 GND - 接 GND
pin3 SET - 接 3.3V
pin4 RX - 接 D1
pin5 TX - 接 D0
他傳輸的格式 :
https://github.com/neojou/arduino-ameba/blob/master/example/pms3003-test/pms3003-test.ino
long pmcf10=0; | |
long pmcf25=0; | |
long pmcf100=0; | |
long pmat10=0; | |
long pmat25=0; | |
long pmat100=0; | |
char buf[50]; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
Serial1.begin(9600); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int count = 0; | |
unsigned char c; | |
unsigned char high; | |
while (Serial1.available()) { | |
c = Serial1.read(); | |
if((count==0 && c!=0x42) || (count==1 && c!=0x4d)){ | |
Serial.println("check failed"); | |
break; | |
} | |
if(count > 15){ | |
Serial.println("complete"); | |
break; | |
} | |
else if(count == 4 || count == 6 || count == 8 || count == 10 || count == 12 || count == 14) { | |
high = c; | |
} | |
else if(count == 5){ | |
pmcf10 = 256*high + c; | |
Serial.print("CF=1, PM1.0="); | |
Serial.print(pmcf10); | |
Serial.println(" ug/m3"); | |
} | |
else if(count == 7){ | |
pmcf25 = 256*high + c; | |
Serial.print("CF=1, PM2.5="); | |
Serial.print(pmcf25); | |
Serial.println(" ug/m3"); | |
} | |
else if(count == 9){ | |
pmcf100 = 256*high + c; | |
Serial.print("CF=1, PM10="); | |
Serial.print(pmcf100); | |
Serial.println(" ug/m3"); | |
} | |
else if(count == 11){ | |
pmat10 = 256*high + c; | |
Serial.print("atmosphere, PM1.0="); | |
Serial.print(pmat10); | |
Serial.println(" ug/m3"); | |
} | |
else if(count == 13){ | |
pmat25 = 256*high + c; | |
Serial.print("atmosphere, PM2.5="); | |
Serial.print(pmat25); | |
Serial.println(" ug/m3"); | |
} | |
else if(count == 15){ | |
pmat100 = 256*high + c; | |
Serial.print("atmosphere, PM10="); | |
Serial.print(pmat100); | |
Serial.println(" ug/m3"); | |
} | |
count++; | |
} | |
while(Serial1.available()) Serial1.read(); | |
Serial.println(); | |
delay(5000); | |
} | |
測試結果
在我新竹座位量 PM2.5 < 10 ug/m3 , 應該還可以..
在我台北座位, 看來指數高很多... 台北空氣真的不大好...
Thank you very much :)
回覆刪除