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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1524|回復: 0
打印 上一主題 下一主題
收起左側

arduino空氣質量檢測

[復制鏈接]
跳轉到指定樓層
樓主
ID:431677 發表于 2020-2-16 15:49 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本系統主要是通過arduino控制激光粉塵傳感器來檢測空氣中的PM2.5及其他氣體含量,并在lcd1602上顯示出來。具體詳細代碼在壓縮包。
  1. #include <Arduino.h>
  2. #include <LiquidCrystal.h>
  3. LiquidCrystal lcd( 7, 6, 5, 4, 3, 2);
  4. #define LENG 31   //0x42 + 31 bytes equal to 32 bytes
  5. unsigned char buf[LENG];

  6. int PM01Value=0;          //define PM1.0 value of the air detector module
  7. int PM2_5Value=0;         //define PM2.5 value of the air detector module
  8. int PM10Value=0;         //define PM10 value of the air detector module


  9. void setup()
  10. {
  11.   Serial.begin(9600);   //使用串口0
  12.   Serial.setTimeout(1500);    //設置超時時間為1500毫秒(大于傳感器傳送數據周期1秒)
  13.   
  14. // lcd.print("PM1.0: ");
  15. // lcd.print(PM01Value);
  16.   //lcd.println("  ug/m3");            
  17.      
  18.       
  19.       
  20. // lcd.print("PM1 0: ");  
  21.   //lcd.print(PM10Value);
  22.   //lcd.println("  ug/m3");   
  23.   //lcd.println();
  24. }

  25. void loop()
  26. {
  27.   if(Serial.find(0x42)){    //檢測到0x42時,開始讀取
  28.     Serial.readBytes(buf,LENG);

  29.     if(buf[0] == 0x4d)
  30.     {
  31.       if(checkValue(buf,LENG))
  32.       {
  33.         PM01Value=transmitPM01(buf); //count PM1.0 value of the air detector module
  34.         PM2_5Value=transmitPM2_5(buf);//count PM2.5 value of the air detector module
  35.         PM10Value=transmitPM10(buf); //count PM10 value of the air detector module
  36.       }           
  37.     }
  38.   }

  39.   static unsigned long OledTimer=millis();  
  40.     if (millis() - OledTimer >=1000)
  41.     {
  42.       OledTimer=millis();
  43.       
  44.       Serial.print("PM1.0: ");  
  45.       Serial.print(PM01Value);
  46.       Serial.println("  ug/m3");            
  47.      
  48.       Serial.print("PM2.5: ");  
  49.       Serial.print(PM2_5Value);
  50.       Serial.println("  ug/m3");     
  51.       
  52.       Serial.print("PM1 0: ");  
  53.       Serial.print(PM10Value);
  54.       Serial.println("  ug/m3");   
  55.       Serial.println();
  56.     }
  57.     lcd.begin(16, 2);
  58.     lcd.setCursor(0,0);
  59.     lcd.print("PM2.5:   ");  
  60.     lcd.print(PM2_5Value);
  61.     lcd.println("ug/m3 ");
  62.     lcd.setCursor(0,1);
  63.     lcd.print("PM10:   ");  
  64.     lcd.print(PM10Value);
  65.     lcd.println("ug/m3  ");   
  66.     lcd.println();
  67. }
  68. char checkValue(unsigned char *thebuf, char leng)
  69. {  
  70.   char receiveflag=0;
  71.   int receiveSum=0;

  72.   for(int i=0; i<(leng-2); i++){
  73.   receiveSum=receiveSum+thebuf[i];
  74.   }
  75.   receiveSum=receiveSum + 0x42;
  76.   
  77.   if(receiveSum == ((thebuf[leng-2]<<8)+thebuf[leng-1]))  //check the serial data
  78.   {
  79.     receiveSum = 0;
  80.     receiveflag = 1;
  81.   }
  82.   return receiveflag;
  83. }

  84. int transmitPM01(unsigned char *thebuf)
  85. {
  86.   int PM01Val;
  87.   PM01Val=((thebuf[3]<<8) + thebuf[4]); //count PM1.0 value of the air detector module
  88.   return PM01Val;
  89. }

  90. //transmit PM Value to PC
  91. int transmitPM2_5(unsigned char *thebuf)
  92. {
  93.   int PM2_5Val;
  94.   PM2_5Val=((thebuf[5]<<8) + thebuf[6]);//count PM2.5 value of the air detector module
  95.   return PM2_5Val;
  96.   }

  97. //transmit PM Value to PC
  98. int transmitPM10(unsigned char *thebuf)
  99. {
  100.   int PM10Val;
  101.   PM10Val=((thebuf[7]<<8) + thebuf[8]); //count PM10 value of the air detector module  
  102.   return PM10Val;
  103. }
復制代碼


空氣質量檢測PM2.5.zip

61.12 KB, 下載次數: 13, 下載積分: 黑幣 -5

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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产午夜精品一区二区三区嫩草 | 一级少妇女片 | 999久久久国产精品 欧美成人h版在线观看 | 国产免费一区二区三区最新6 | 亚洲中国字幕 | 亚洲一区二区视频 | 国产成人99久久亚洲综合精品 | 久草在线青青草 | www在线视频| 国产在线一区二区 | 热久久免费视频 | 精品久久久久久久 | 国产二区av | 91成人在线 | 青青草精品视频 | 精品国产乱码久久久久久88av | 91综合网 | 亚洲日日 | 国产精品美女久久久久aⅴ国产馆 | 日韩在线一区二区三区 | 国产99热精品 | jizz在线免费观看 | 99精品久久久 | 一级a性色生活片久久毛片 一级特黄a大片 | 鲁大师一区影视 | 午夜天堂精品久久久久 | 97色在线观看免费视频 | 激情毛片 | 粉嫩一区二区三区性色av | 国产一区二区三区久久 | 欧美综合一区二区 | 亚洲精品一区二区另类图片 | 亚洲+变态+欧美+另类+精品 | 成人在线视频网址 | 国产欧美在线视频 | 91久久爽久久爽爽久久片 | 天堂久久av | 91深夜福利视频 | 中文字幕亚洲区一区二 | 国产乱码精品一区二区三区中文 | 亚洲不卡av在线 |