SDS011是一款使用激光光源的PM2.5顆粒物監(jiān)測傳感器,串口輸出,自帶風(fēng)扇,能檢測直徑最小0.3微米的顆粒物,性能穩(wěn)定。
132552bcccvzwou1ncwccv.png (220.9 KB, 下載次數(shù): 163)
下載附件
2016-4-11 01:50 上傳
132551loratz7mz3777571.jpg (148.92 KB, 下載次數(shù): 183)
下載附件
2016-4-11 01:50 上傳
132551dku1kekzuwd3uuct.jpg (152.93 KB, 下載次數(shù): 194)
下載附件
2016-4-11 01:50 上傳
由于采用串口輸出,使得數(shù)據(jù)獲取更加方便,同時也提供PWM輸出方式,也能滿足更高的精度要求。程序使用軟串口采集數(shù)據(jù),同時輸出至硬件串口,在實時顯示數(shù)據(jù)的同時也能將數(shù)據(jù)發(fā)送至上位機或通過添加網(wǎng)絡(luò)模塊發(fā)送至物聯(lián)網(wǎng)絡(luò)。傳感器監(jiān)測結(jié)果較為可靠,比較接近環(huán)境監(jiān)測站發(fā)布的數(shù)據(jù)。 制作資料下載:
SDS011激光PM2.5傳感器簡介.pdf
(184.7 KB, 下載次數(shù): 20)
2016-4-11 01:46 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
NewSoftSerial12.zip
(9.73 KB, 下載次數(shù): 18)
2016-4-11 01:46 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
graphicstest.rar
(1.79 KB, 下載次數(shù): 13)
2016-4-11 01:46 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
部分源碼預(yù)覽:
- #define LCD_CS A3
- #define LCD_CD A2
- #define LCD_WR A1
- #define LCD_RD A0
- // you can also just connect RESET to the arduino RESET pin
- #define LCD_RESET A4
- //Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
- // Color definitions
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- #include "TFTLCD.h"
- #include
- TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- NewSoftSerial nss(11, 12);
- uint8_t c;
- uint8_t data[10];
- uint8_t pIdx = 0;
- bool LogData=false;
- int pm2_5 = 0;
- int pm10 = 0;
- int pm2_5_Old = 0;
- int pm10_Old = 0;
- uint16_t color2_5 = GREEN;
- uint16_t color10 = GREEN;
- void setup(void) {
- tft.reset();
- tft.initDisplay();
- tft.setRotation(3);
- tft.fillScreen(BLACK);
- tft.setCursor(0, 15);
- tft.setTextColor(BLUE);
- tft.setTextSize(4);
- tft.println("PM2.5:");
- tft.setCursor(0, 130);
- tft.println("PM10:");
- Serial.begin(9600);
- nss.begin(9600);
- // testtext(RED);
- // delay(2000);
- // testlines(CYAN);
- // delay(500);
- // testfastlines(RED, BLUE);
- // delay(500);
- // testdrawrects(GREEN);
- // delay(500);
- // testfillrects(YELLOW, MAGENTA);
- // delay(500);
- // tft.fillScreen(BLACK);
- // testfillcircles(10, MAGENTA);
- // testdrawcircles(10, WHITE);
- // delay(500);
- // testtriangles();
- // delay(500);
- // testfilltriangles();
- // delay(500);
- // testRoundRect();
- // delay(500);
- // testFillRoundRect();
- }
- void loop(void) {
- while(nss.available())
- {
- c = nss.read();
- if(c==170)
- {
- LogData=true;
- }
- if(LogData)
- {
- data[pIdx]=c;
- pIdx=pIdx+1;
- }
- if(c==171)
- {
- LogData=false;
- pIdx=0;
- uint8_t sumAdd = data[2]+data[3]+data[4]+data[5]+data[6]+data[7];
- if(sumAdd==data[8])
- {
- pm2_5 = (data[3] * 256 + data[2]) / 10;
- pm10 = (data[5] * 256 + data[4]) / 10;
- if(pm2_5>0 && pm2_5<=75)
- {
- color2_5 = GREEN;
- }
- else if(pm2_5>75 && pm2_5<=200)
- {
- color2_5 = YELLOW;
- }
- else if(pm2_5>200)
- {
- color2_5 = RED;
- }
- if(pm10>0 && pm10<=75)
- {
- color10 = GREEN;
- }
- else if(pm10>75 && pm10<=200)
- {
- color10 = YELLOW;
- }
- else if(pm10>200)
- {
- color10 = RED;
- }
- testtext(pm2_5,color2_5,pm10,color10);
- Serial.print(pm2_5,DEC);
- Serial.print(',');
- Serial.println(pm10,DEC);
- }
- }
- }
- }
- void testtext(uint16_t val2_5,uint16_t color2_5,uint16_t val10,uint16_t color10) {
- tft.setTextSize(9);
- tft.setCursor(0, 55);
- tft.setTextColor(BLACK);
- tft.println(pm2_5_Old);
- tft.setCursor(0, 55);
- tft.setTextColor(color2_5);
- tft.println(val2_5);
- pm2_5_Old=val2_5;
- tft.setCursor(0, 170);
- tft.setTextColor(BLACK);
- tft.println(pm10_Old);
- tft.setCursor(0, 170);
- tft.setTextColor(color10);
- tft.println(val10);
- pm10_Old=val10;
- }
- //void testFillRoundRect() {
- // tft.fillScreen(BLACK);
- //
- // for (uint16_t x=tft.width(); x > 20 ; x-=6) {
- // tft.fillRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(0, x, 0));
- // }
- //}
- //void testRoundRect() {
- // tft.fillScreen(BLACK);
- //
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(x, 0, 0));
- // }
- //}
- //void testtriangles() {
- // tft.fillScreen(BLACK);
- // for (uint16_t i=0; i<tft.width() 2;="" i+="5)" {
- // tft.drawTriangle(tft.width()/2, tft.height()/2-i,
- // tft.width()/2-i, tft.height()/2+i,
- // tft.width()/2+i, tft.height()/2+i, tft.Color565(0, 0, i));
- // }
- //}
- //void testfilltriangles() {
- // tft.fillScreen(BLACK);
- //
- // for (uint16_t i=tft.width()/2; i>10; i-=5) {
- // tft.fillTriangle(tft.width()/2, tft.height()/2-i,
- // tft.width()/2-i, tft.height()/2+i,
- // tft.width()/2+i, tft.height()/2+i,
- // tft.Color565(0, i, i));
- // tft.drawTriangle(tft.width()/2, tft.height()/2-i,
- // tft.width()/2-i, tft.height()/2+i,
- // tft.width()/2+i, tft.height()/2+i, tft.Color565(i, i, 0));
- // }
- //}
- //void testfillcircles(uint8_t radius, uint16_t color) {
- // for (uint16_t x=radius; x < tft.width(); x+=radius*2) {
- // for (uint16_t y=radius; y < tft.height(); y+=radius*2) {
- // tft.fillCircle(x, y, radius, color);
- // }
- // }
- //}
- //void testdrawcircles(uint8_t radius, uint16_t color) {
- // for (uint16_t x=0; x < tft.width()+radius; x+=radius*2) {
- // for (uint16_t y=0; y < tft.height()+radius; y+=radius*2) {
- // tft.drawCircle(x, y, radius, color);
- // }
- // }
- //}
- //void testfillrects(uint16_t color1, uint16_t color2) {
- // tft.fillScreen(BLACK);
- // for (uint16_t x=tft.width()-1; x > 6; x-=6) {
- // //Serial.println(x, DEC);
- // tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
- // tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
- // }
- //}
- //void testdrawrects(uint16_t color) {
- // tft.fillScreen(BLACK);
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
- // }
- //}
- //void testfastlines(uint16_t color1, uint16_t color2) {
- // tft.fillScreen(BLACK);
- // for (uint16_t y=0; y < tft.height(); y+=5) {
- // tft.drawHorizontalLine(0, y, tft.width(), color1);
- // }
- // for (uint16_t x=0; x < tft.width(); x+=5) {
- // tft.drawVerticalLine(x, 0, tft.height(), color2);
- // }
- //
- //}
- //void testlines(uint16_t color) {
- // tft.fillScreen(BLACK);
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawLine(0, 0, x, tft.height()-1, color);
- // }
- // for (uint16_t y=0; y < tft.height(); y+=6) {
- // tft.drawLine(0, 0, tft.width()-1, y, color);
- // }
- //
- // tft.fillScreen(BLACK);
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
- // }
- // for (uint16_t y=0; y < tft.height(); y+=6) {
- // tft.drawLine(tft.width()-1, 0, 0, y, color);
- // }
- //
- // tft.fillScreen(BLACK);
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawLine(0, tft.height()-1, x, 0, color);
- // }
- // for (uint16_t y=0; y < tft.height(); y+=6) {
- // tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
- // }
- //
- // tft.fillScreen(BLACK);
- // for (uint16_t x=0; x < tft.width(); x+=6) {
- // tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
- // }
- // for (uint16_t y=0; y < tft.height(); y+=6) {
- // tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
- // }
- //}
- //void testBars() {
- // uint16_t i,j;
- // for(i=0; i < tft.height(); i++)
- // {
- // for(j=0; j < tft.width(); j++)
- // {
- // if(i>279) tft.writeData(WHITE);
- // else if(i>239) tft.writeData(BLUE);
- // else if(i>199) tft.writeData(GREEN);
- // else if(i>159) tft.writeData(CYAN);
- // else if(i>119) tft.writeData(RED);
- // else if(i>79) tft.writeData(MAGENTA);
- // else if(i>39) tft.writeData(YELLOW);
- // else tft.writeData(BLACK);
- // }
- // }
- //}
復(fù)制代碼
|