久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8242|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

arduino驅(qū)動SDS011激光PM2.5顆粒物傳感器

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:113207 發(fā)表于 2016-4-11 01:49 | 只看該作者 |只看大圖 回帖獎勵 |正序瀏覽 |閱讀模式

SDS011是一款使用激光光源的PM2.5顆粒物監(jiān)測傳感器,串口輸出,自帶風(fēng)扇,能檢測直徑最小0.3微米的顆粒物,性能穩(wěn)定。


由于采用串口輸出,使得數(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)


NewSoftSerial12.zip (9.73 KB, 下載次數(shù): 18)


graphicstest.rar (1.79 KB, 下載次數(shù): 13)



部分源碼預(yù)覽:


  1. #define LCD_CS A3   
  2. #define LCD_CD A2   
  3. #define LCD_WR A1   
  4. #define LCD_RD A0   
  5. // you can also just connect RESET to the arduino RESET pin
  6. #define LCD_RESET A4
  7. //Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
  8. // Color definitions
  9. #define        BLACK           0x0000
  10. #define        BLUE            0x001F
  11. #define        RED             0xF800
  12. #define        GREEN           0x07E0
  13. #define CYAN            0x07FF
  14. #define MAGENTA         0xF81F
  15. #define YELLOW          0xFFE0
  16. #define WHITE           0xFFFF

  17. #include "TFTLCD.h"
  18. #include


  19. TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  20. NewSoftSerial nss(11, 12);

  21. uint8_t c;
  22. uint8_t data[10];
  23. uint8_t pIdx = 0;
  24. bool LogData=false;
  25. int pm2_5 = 0;
  26. int pm10 = 0;
  27. int pm2_5_Old = 0;
  28. int pm10_Old = 0;
  29. uint16_t color2_5 = GREEN;
  30. uint16_t color10 = GREEN;

  31. void setup(void) {

  32.   tft.reset();
  33.   tft.initDisplay();
  34.   tft.setRotation(3);
  35.   tft.fillScreen(BLACK);

  36.   tft.setCursor(0, 15);
  37.   tft.setTextColor(BLUE);
  38.   tft.setTextSize(4);
  39.   tft.println("PM2.5:");
  40.   tft.setCursor(0, 130);
  41.   tft.println("PM10:");


  42.   Serial.begin(9600);
  43.   nss.begin(9600);

  44.   //  testtext(RED);
  45.   //  delay(2000);
  46.   //  testlines(CYAN);
  47.   //  delay(500);
  48.   //  testfastlines(RED, BLUE);
  49.   //  delay(500);
  50.   //  testdrawrects(GREEN);
  51.   //  delay(500);
  52.   //  testfillrects(YELLOW, MAGENTA);
  53.   //  delay(500);
  54.   //  tft.fillScreen(BLACK);
  55.   //  testfillcircles(10, MAGENTA);
  56.   //  testdrawcircles(10, WHITE);
  57.   //  delay(500);
  58.   //  testtriangles();
  59.   //  delay(500);
  60.   //  testfilltriangles();
  61.   //  delay(500);
  62.   //  testRoundRect();
  63.   //  delay(500);
  64.   //  testFillRoundRect();
  65. }

  66. void loop(void) {

  67.   while(nss.available())
  68.   {
  69.     c = nss.read();

  70.     if(c==170)
  71.     {
  72.       LogData=true;
  73.     }

  74.     if(LogData)
  75.     {
  76.       data[pIdx]=c;
  77.       pIdx=pIdx+1;
  78.     }

  79.     if(c==171)
  80.     {
  81.       LogData=false;
  82.       pIdx=0;
  83.       uint8_t sumAdd = data[2]+data[3]+data[4]+data[5]+data[6]+data[7];
  84.       if(sumAdd==data[8])
  85.       {
  86.         pm2_5 = (data[3] * 256 + data[2]) / 10;
  87.         pm10 = (data[5] * 256 + data[4]) / 10;

  88.         if(pm2_5>0 && pm2_5<=75)
  89.         {
  90.           color2_5 = GREEN;
  91.         }
  92.         else if(pm2_5>75 && pm2_5<=200)
  93.         {
  94.           color2_5 = YELLOW;
  95.         }
  96.         else if(pm2_5>200)
  97.         {
  98.           color2_5 = RED;
  99.         }

  100.         if(pm10>0 && pm10<=75)
  101.         {
  102.           color10 = GREEN;
  103.         }
  104.         else if(pm10>75 && pm10<=200)
  105.         {
  106.           color10 = YELLOW;
  107.         }
  108.         else if(pm10>200)
  109.         {
  110.          color10 = RED;
  111.         }

  112.         testtext(pm2_5,color2_5,pm10,color10);
  113.         Serial.print(pm2_5,DEC);
  114.         Serial.print(',');
  115.         Serial.println(pm10,DEC);
  116.       }
  117.     }
  118.   }
  119. }

  120. void testtext(uint16_t val2_5,uint16_t color2_5,uint16_t val10,uint16_t color10) {

  121.   tft.setTextSize(9);

  122.   tft.setCursor(0, 55);
  123.   tft.setTextColor(BLACK);
  124.   tft.println(pm2_5_Old);
  125.   tft.setCursor(0, 55);
  126.   tft.setTextColor(color2_5);
  127.   tft.println(val2_5);
  128.   pm2_5_Old=val2_5;

  129.   tft.setCursor(0, 170);
  130.   tft.setTextColor(BLACK);
  131.   tft.println(pm10_Old);
  132.   tft.setCursor(0, 170);
  133.   tft.setTextColor(color10);
  134.   tft.println(val10);
  135.   pm10_Old=val10;

  136. }

  137. //void testFillRoundRect() {
  138. //  tft.fillScreen(BLACK);
  139. //  
  140. //  for (uint16_t x=tft.width(); x > 20 ; x-=6) {
  141. //    tft.fillRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8,  tft.Color565(0, x, 0));
  142. // }
  143. //}

  144. //void testRoundRect() {
  145. //  tft.fillScreen(BLACK);
  146. //  
  147. //  for (uint16_t x=0; x < tft.width(); x+=6) {
  148. //    tft.drawRoundRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, x/8, tft.Color565(x, 0, 0));
  149. // }
  150. //}

  151. //void testtriangles() {
  152. //  tft.fillScreen(BLACK);
  153. //  for (uint16_t i=0; i<tft.width() 2;="" i+="5)" {
  154. //    tft.drawTriangle(tft.width()/2, tft.height()/2-i,
  155. //                     tft.width()/2-i, tft.height()/2+i,
  156. //                     tft.width()/2+i, tft.height()/2+i, tft.Color565(0, 0, i));
  157. //  }
  158. //}

  159. //void testfilltriangles() {
  160. //  tft.fillScreen(BLACK);
  161. //  
  162. //  for (uint16_t i=tft.width()/2; i>10; i-=5) {
  163. //    tft.fillTriangle(tft.width()/2, tft.height()/2-i,
  164. //                     tft.width()/2-i, tft.height()/2+i,
  165. //                     tft.width()/2+i, tft.height()/2+i,
  166. //                     tft.Color565(0, i, i));
  167. //    tft.drawTriangle(tft.width()/2, tft.height()/2-i,
  168. //                     tft.width()/2-i, tft.height()/2+i,
  169. //                     tft.width()/2+i, tft.height()/2+i, tft.Color565(i, i, 0));   
  170. //  }
  171. //}

  172. //void testfillcircles(uint8_t radius, uint16_t color) {
  173. //  for (uint16_t x=radius; x < tft.width(); x+=radius*2) {
  174. //    for (uint16_t y=radius; y < tft.height(); y+=radius*2) {
  175. //      tft.fillCircle(x, y, radius, color);
  176. //    }
  177. //  }  
  178. //}

  179. //void testdrawcircles(uint8_t radius, uint16_t color) {
  180. //  for (uint16_t x=0; x < tft.width()+radius; x+=radius*2) {
  181. //    for (uint16_t y=0; y < tft.height()+radius; y+=radius*2) {
  182. //      tft.drawCircle(x, y, radius, color);
  183. //    }
  184. //  }  
  185. //}


  186. //void testfillrects(uint16_t color1, uint16_t color2) {
  187. // tft.fillScreen(BLACK);
  188. // for (uint16_t x=tft.width()-1; x > 6; x-=6) {
  189. //   //Serial.println(x, DEC);
  190. //   tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
  191. //   tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  192. // }
  193. //}

  194. //void testdrawrects(uint16_t color) {
  195. // tft.fillScreen(BLACK);
  196. // for (uint16_t x=0; x < tft.width(); x+=6) {
  197. //   tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  198. // }
  199. //}

  200. //void testfastlines(uint16_t color1, uint16_t color2) {
  201. //   tft.fillScreen(BLACK);
  202. //   for (uint16_t y=0; y < tft.height(); y+=5) {
  203. //     tft.drawHorizontalLine(0, y, tft.width(), color1);
  204. //   }
  205. //   for (uint16_t x=0; x < tft.width(); x+=5) {
  206. //     tft.drawVerticalLine(x, 0, tft.height(), color2);
  207. //   }
  208. //  
  209. //}

  210. //void testlines(uint16_t color) {
  211. //   tft.fillScreen(BLACK);
  212. //   for (uint16_t x=0; x < tft.width(); x+=6) {
  213. //     tft.drawLine(0, 0, x, tft.height()-1, color);
  214. //   }
  215. //   for (uint16_t y=0; y < tft.height(); y+=6) {
  216. //     tft.drawLine(0, 0, tft.width()-1, y, color);
  217. //   }
  218. //   
  219. //   tft.fillScreen(BLACK);
  220. //   for (uint16_t x=0; x < tft.width(); x+=6) {
  221. //     tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
  222. //   }
  223. //   for (uint16_t y=0; y < tft.height(); y+=6) {
  224. //     tft.drawLine(tft.width()-1, 0, 0, y, color);
  225. //   }
  226. //   
  227. //   tft.fillScreen(BLACK);
  228. //   for (uint16_t x=0; x < tft.width(); x+=6) {
  229. //     tft.drawLine(0, tft.height()-1, x, 0, color);
  230. //   }
  231. //   for (uint16_t y=0; y < tft.height(); y+=6) {
  232. //     tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
  233. //   }
  234. //
  235. //   tft.fillScreen(BLACK);
  236. //   for (uint16_t x=0; x < tft.width(); x+=6) {
  237. //     tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
  238. //   }
  239. //   for (uint16_t y=0; y < tft.height(); y+=6) {
  240. //     tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
  241. //   }
  242. //}

  243. //void testBars() {
  244. //  uint16_t i,j;
  245. //  for(i=0; i < tft.height(); i++)
  246. //  {
  247. //    for(j=0; j < tft.width(); j++)
  248. //    {
  249. //      if(i>279) tft.writeData(WHITE);
  250. //      else if(i>239) tft.writeData(BLUE);
  251. //      else if(i>199) tft.writeData(GREEN);
  252. //      else if(i>159) tft.writeData(CYAN);
  253. //      else if(i>119) tft.writeData(RED);
  254. //      else if(i>79) tft.writeData(MAGENTA);
  255. //      else if(i>39) tft.writeData(YELLOW);
  256. //      else tft.writeData(BLACK);
  257. //    }
  258. //  }
  259. //}
復(fù)制代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:223039 發(fā)表于 2017-9-12 16:58 | 只看該作者
牛逼,大神,最近正在弄這個凈化器,要用到激光PM2.5傳感器,我下載程序到12864上顯示,但數(shù)據(jù)不顯示,可能是什么原因?程序是淘寶網(wǎng)家給的,但他是用數(shù)碼管顯示出來的,
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 黄久久久 | 亚洲国产aⅴ精品 | 国产亚洲一区精品 | 免费视频一区二区 | 久久精品一区二区三区四区 | 午夜天堂精品久久久久 | 久久久久久免费精品一区二区三区 | 精品视频一区在线 | 免费成人高清 | 日本精品一区二区三区视频 | 亚洲国产视频一区 | 特一级毛片 | 大伊人久久 | 免费观看色 | 成人av免费 | 亚洲国产精品一区二区第一页 | 国产一区欧美 | 午夜精品久久久久久久久久久久 | 一区二区三区视频在线观看 | 天天看天天爽 | 一区二区三区四区电影视频在线观看 | 欧美a区 | 亚洲一区二区三区免费观看 | 久久久久综合 | 久久久久无码国产精品一区 | 视频一区二区三区中文字幕 | 国产精品一区二区久久 | 亚洲一卡二卡 | 亚洲精品18| aaaa一级毛片 | 亚洲精品日本 | 国产精品久久久久久模特 | 欧美精品久久久久久久久老牛影院 | 男人天堂国产 | 国产高清精品一区二区三区 | 久久成人免费视频 | 在线色网站 | 性高朝久久久久久久3小时 av一区二区三区四区 | 久久精品视频一区二区 | 国产精品久久久久久影视 | 国产精品久久久久久久久久尿 |