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

標(biāo)題: 自制基于Arduino移動(dòng)式城市環(huán)境信息采集器 [打印本頁]

作者: 51hei學(xué)習(xí)    時(shí)間: 2016-4-10 00:41
標(biāo)題: 自制基于Arduino移動(dòng)式城市環(huán)境信息采集器

制作靈感來源于一個(gè)叫做 urban feeds 的項(xiàng)目。儀器能夠采集:

采用SD卡存儲(chǔ)數(shù)據(jù),鋰電池供電,外觀如圖:

全部配件包括:



電路部分:



儀器組裝:


DSM501A粉塵傳感器 需垂直安裝
儀器內(nèi)部:



程序代碼:


  1.     //davidce 20111211

  2.     // Include
  3.     #include
  4.     #include
  5.     #include

  6.     // Digital pin
  7.     // SHT1x
  8.     #define ShtDataPin  8  //data
  9.     #define ShtClockPin 9  //clock
  10.     SHT1x sht1x(ShtDataPin, ShtClockPin);
  11.     // system light
  12.     #define systemLightPin 2
  13.     //DSM501A DUST
  14.     #define DSMPin2_5  6
  15.     #define DSMPin1_0  7
  16.     //SD card
  17.     File myFile;
  18.     #define SD_CSPin  10
  19.     char filename[] = "result.txt";
  20.     String order= "";
  21.     //GPS
  22.     #define rxPin 0                    // RX PIN
  23.     #define txPin 1                    // TX TX

  24.     // Analog pin
  25.     const int powerInPin = A0;    // check power state for the bettery charge
  26.     const int infrRayPin = A1;    //infrared ray
  27.     const int o3Pin = A2;          //MQ131
  28.     const int co2Pin = A3;          //MQ811

  29.     // Variable
  30.     boolean inCharge = false;      //bettery charging mark
  31.     const unsigned long warmTime = 60000;     //system warmming 60000 ms
  32.     const unsigned long scanTime = 0;     //get data fre scanTime = scanTime + flashTime
  33.     const unsigned long flashTime = 250;  
  34.     unsigned long previousMillis = 0;        //前一次判斷時(shí)間點(diǎn)
  35.     unsigned long partMillis=0;              //到溢出時(shí)計(jì)算的時(shí)間
  36.     const unsigned long sectev = 30;           // 時(shí)間間隔(秒)
  37.     const unsigned long interval = 30000;           // 時(shí)間間隔(毫秒) = sectev * 1000
  38.     const unsigned long mintev = 30000000; // 時(shí)間間隔(微秒) =interval * 1000
  39.     //BH1750 IIC Mode
  40.     const int BH1750address = 0x23; //setting i2c address
  41.     byte buff[2];
  42.     //GPS
  43.     int byteGPS = -1;
  44.     char linea[300] = "";
  45.     char comandoGPR[7] = "$GPRMC";
  46.     int cont=0;
  47.     int bien=0;
  48.     int conta=0;
  49.     int indices[13];

  50.     void setup() {
  51.       if(!SD.begin(SD_CSPin))
  52.       {
  53.         return;
  54.       }
  55.       // read the value from the power
  56.       int powerValue = analogRead(powerInPin); // variable to store the value coming from the power
  57.       if(powerValue>1000)
  58.       {
  59.         inCharge=true;
  60.         Serial.begin(4800);  //port speed for GPS
  61.       }
  62.       else
  63.       {
  64.         //check if the log file exists and add name of items to the new file
  65.         if (!SD.exists(filename))
  66.         {
  67.           myFile = SD.open(filename, FILE_WRITE);
  68.           if (myFile)
  69.           {
  70.             myFile.print("date_UTC");
  71.             myFile.print(9,BYTE);
  72.             myFile.print("time_UTC");
  73.             myFile.print(9,BYTE);
  74.             myFile.print("lat");
  75.             myFile.print(9,BYTE);
  76.             myFile.print("lon");
  77.             myFile.print(9,BYTE);
  78.             myFile.print("temp_C");
  79.             myFile.print(9,BYTE);
  80.             myFile.print("hum_PER");
  81.             myFile.print(9,BYTE);
  82.             myFile.print("pcs_1");
  83.             myFile.print(9,BYTE);
  84.             myFile.print("pcs_2_5");
  85.             myFile.print(9,BYTE);
  86.             myFile.print("peop_tra");
  87.             myFile.print(9,BYTE);
  88.             myFile.print("O3");
  89.             myFile.print(9,BYTE);
  90.             myFile.print("CO2");
  91.             myFile.print(9,BYTE);
  92.             myFile.println("light_lx");
  93.             myFile.close();
  94.           }
  95.         }
  96.         for (int i=0;i<300;i++)
  97.         {       // Initialize a buffer for received data
  98.           linea[i]=' ';
  99.         }
  100.         pinMode(systemLightPin, OUTPUT);  
  101.         pinMode(DSMPin2_5, INPUT);
  102.         pinMode(DSMPin1_0, INPUT);
  103.         pinMode(rxPin, INPUT);
  104.         pinMode(txPin, OUTPUT);
  105.         Wire.begin();
  106.         Serial.begin(4800);  //port speed for transform
  107.         digitalWrite(systemLightPin, HIGH);   
  108.         delay(warmTime);
  109.       }
  110.     }

  111.     void loop(){
  112.       if(!inCharge)                  // work state
  113.       {
  114.         float temp_c =sht1x.readTemperatureC();
  115.         float humidity = sht1x.readHumidity();

  116.         unsigned long currentMillis;
  117.         boolean goloop=true;
  118.         partMillis=0;
  119.         unsigned long duration1_0=0;
  120.         unsigned long duration2_5=0;
  121.         long temp1_0=0;
  122.         long temp2_5=0;
  123.         unsigned long rayMark=0;        //人流量計(jì)數(shù)
  124.         double rayFreq = 0.0;        //人流量頻率

  125.         while(goloop)      //loop
  126.         {
  127.           currentMillis = micros();
  128.           if(currentMillis<previousmillis)
  129.           {
  130.             partMillis = 4294967295 -  previousMillis +1;
  131.             previousMillis = 0;  
  132.           }
  133.           if(currentMillis - previousMillis - partMillis < mintev)
  134.           {
  135.             //1.0
  136.             if(temp1_0==0)
  137.             {
  138.               temp1_0=-1;
  139.               temp1_0=pulseIn(DSMPin1_0, LOW);
  140.             }
  141.             if(temp1_0>0)
  142.             {
  143.               duration1_0 =duration1_0 + temp1_0;
  144.               temp1_0=0;
  145.             }
  146.             //2.5
  147.             if(temp2_5==0)
  148.             {
  149.               temp2_5=-1;
  150.               temp2_5=pulseIn(DSMPin2_5, LOW);
  151.             }
  152.             if(temp2_5>0)
  153.             {
  154.               duration2_5 =duration2_5 + temp2_5;
  155.               temp2_5=0;
  156.             }
  157.           }
  158.           else
  159.           {
  160.             goloop=false;
  161.             previousMillis=currentMillis;
  162.           }
  163.           //human transform
  164.           int rayState = analogRead(infrRayPin);
  165.           if(rayState>500)
  166.           {
  167.             rayMark = rayMark + 1;
  168.           }
  169.         }
  170.         double per =double(duration1_0)/double(interval);// had multiply 1000
  171.         int pcs1_0 = -1;
  172.         pcs1_0 =  per * 50.0;
  173.         per =double(duration2_5)/double(interval);// had multiply 1000
  174.         int pcs2_5 = -1;
  175.         pcs2_5 =  per * 50.0;
  176.         rayFreq = double(rayMark) /double(sectev);

  177.         // light
  178.         uint16_t lightval=0;
  179.         BH1750_Init(BH1750address);
  180.         delay(200);
  181.         if(2==BH1750_Read(BH1750address))
  182.         {
  183.           lightval=((buff[0]<<8)|buff[1])/1.2;
  184.         }

  185.         //MQ131
  186.         int O3v=analogRead(o3Pin);
  187.         float O3ppb=float(O3v) * 0.0049;    //not realy value
  188.         float O3mg_m3 = O3ppb * 48 / 22.4 / 1000;  //need ajaust
  189.         //MG811
  190.         int CO2v=analogRead(co2Pin);
  191.         float CO2ppb=float(CO2v) * 0.0049;    //not realy value
  192.       
  193.         //GPS
  194.         String datestr = "";    //date UTC (ddmmyy)
  195.         String timestr = "";    //time UTC (hhmmss.sss)
  196.         String latstr = "";    //Latitude (ddmm.mmmm)
  197.         String lonstr = "";    //Longitude (dddmm.mmmm)
  198.         boolean isGPSOK = false;
  199.         bien=0;
  200.         while(bien!=6)
  201.         {
  202.           byteGPS=Serial.read();
  203.           if(byteGPS == -1)
  204.           {
  205.             delay(100);
  206.           }
  207.           else
  208.           {
  209.             linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
  210.             conta++;
  211.             if(byteGPS==13)
  212.             {
  213.               cont=0;
  214.               bien=0;
  215.               for (int i=1;i<7;i++)
  216.               {     // Verifies if the received command starts with $GPRMC
  217.                 if (linea[i]==comandoGPR[i-1])
  218.                 {
  219.                   bien++;
  220.                 }
  221.               }
  222.               if(bien==6)  // If yes, continue and process the data
  223.               {
  224.                 for (int i=0;i<300;i++)
  225.                 {
  226.                   if (linea[i]==',')
  227.                   {    // check for the position of the  "," separator
  228.                     indices[cont]=i;
  229.                     cont++;
  230.                   }
  231.                   if (linea[i]=='*')
  232.                   {    // ... and the "*"
  233.                     indices[12]=i;
  234.                     cont++;
  235.                   }
  236.                 }
  237.                 String dataString;
  238.                 int outindex;
  239.                 outindex=1;
  240.                 for (int j=indices[outindex];j<(indices[outindex+1]-1);j++)
  241.                 {
  242.                   if(linea[j+1]=='A')
  243.                   {
  244.                     isGPSOK = true;
  245.                   }
  246.                 }
  247.                 outindex=8;  //Date UTC (ddmmyy)
  248.                 dataString="";
  249.                 for (int j=indices[outindex];j<(indices[outindex+1]-1);j++)
  250.                 {
  251.                   dataString = dataString + linea[j+1];
  252.                 }
  253.                 datestr=dataString;
  254.                 outindex=0;  //time UTC (hhmmss.sss)
  255.                 dataString="";
  256.                 for (int j=indices[outindex];j<(indices[outindex+1]-1);j++)
  257.                 {
  258.                   dataString = dataString + linea[j+1];
  259.                 }
  260.                 timestr=dataString;
  261.                 outindex=2;  //Latitude (ddmm.mmmm)
  262.                 dataString="";
  263.                 for (int j=indices[outindex];j<(indices[outindex+1]-1);j++)
  264.                 {
  265.                   dataString = dataString + linea[j+1];
  266.                 }
  267.                 latstr=dataString;
  268.                 outindex=4;  //Longitude (dddmm.mmmm)
  269.                 dataString="";
  270.                 for (int j=indices[outindex];j<(indices[outindex+1]-1);j++)
  271.                 {
  272.                   dataString = dataString + linea[j+1];
  273.                 }
  274.                 lonstr=dataString;
  275.               }
  276.               // Reset the buffer
  277.               conta=0;                    
  278.               for (int i=0;i<300;i++)
  279.               {   
  280.                 linea[i]=' ';            
  281.               }
  282.             }
  283.           }
  284.         }

  285.         //output result
  286.         Serial.print(datestr);
  287.         Serial.print(9,BYTE);
  288.         Serial.print(timestr);
  289.         Serial.print(9,BYTE);
  290.         Serial.print(latstr);
  291.         Serial.print(9,BYTE);
  292.         Serial.print(lonstr);
  293.         Serial.print(9,BYTE);
  294.         Serial.print(temp_c);
  295.         Serial.print(9,BYTE);
  296.         Serial.print(humidity);
  297.         Serial.print(9,BYTE);
  298.         Serial.print(pcs1_0);
  299.         Serial.print(9,BYTE);
  300.         Serial.print(pcs2_5);
  301.         Serial.print(9,BYTE);
  302.         Serial.print(rayFreq);
  303.         Serial.print(9,BYTE);
  304.         Serial.print(O3ppb);
  305.         Serial.print(9,BYTE);
  306.         Serial.print(CO2ppb);
  307.         Serial.print(9,BYTE);
  308.         Serial.println(lightval,DEC);

  309.         //writer the result to SD card
  310.         myFile = SD.open(filename, FILE_WRITE);
  311.         if (myFile)
  312.         {
  313.           // to sd file
  314.           myFile.print(datestr);
  315.           myFile.print(9,BYTE);
  316.           myFile.print(timestr);
  317.           myFile.print(9,BYTE);
  318.           myFile.print(latstr);
  319.           myFile.print(9,BYTE);
  320.           myFile.print(lonstr);
  321.           myFile.print(9,BYTE);
  322.           myFile.print(temp_c);
  323.           myFile.print(9,BYTE);
  324.           myFile.print(humidity);
  325.           myFile.print(9,BYTE);
  326.           myFile.print(pcs1_0);
  327.           myFile.print(9,BYTE);
  328.           myFile.print(pcs2_5);
  329.           myFile.print(9,BYTE);
  330.           myFile.print(rayFreq);
  331.           myFile.print(9,BYTE);
  332.           myFile.print(O3ppb);
  333.           myFile.print(9,BYTE);
  334.           myFile.print(CO2ppb);
  335.           myFile.print(9,BYTE);
  336.           myFile.println(lightval,DEC);
  337.           myFile.close();

  338.           //flash the light
  339.           if(isGPSOK)
  340.           {
  341.             digitalWrite(systemLightPin, HIGH);
  342.             delay(flashTime);
  343.             digitalWrite(systemLightPin, LOW);
  344.           }
  345.           else
  346.           {
  347.             digitalWrite(systemLightPin, LOW);
  348.             delay(flashTime);
  349.             digitalWrite(systemLightPin, HIGH);
  350.           }
  351.         }
  352.         delay(scanTime);
  353.       }
  354.       else               //bettery charging and data translation
  355.       {
  356.         while(Serial.available() > 0)
  357.         {
  358.           int incomingByte = Serial.read();
  359.           if(incomingByte==10)    //order end
  360.           {
  361.             if(order == "list")
  362.             {
  363.               myFile = SD.open(filename);
  364.               if (myFile)
  365.               {
  366.                 while (myFile.available())
  367.                 {
  368.                   Serial.write(myFile.read());
  369.                 }
  370.                 myFile.close();
  371.               }
  372.               else
  373.               {
  374.                 Serial.println("open file failure.");
  375.               }
  376.             }
  377.             else if(order.length()>0)
  378.             {
  379.               Serial.println("The available command is:");
  380.               Serial.println("list");
  381.             }
  382.             //reset order
  383.             order="";
  384.           }
  385.           else
  386.           {
  387.             if(incomingByte!=13)
  388.             {
  389.               order = order + char(incomingByte);
  390.             }
  391.           }
  392.         }
  393.       }
  394.     }

  395.     int BH1750_Read(int address)
  396.     {
  397.       int i=0;
  398.       Wire.beginTransmission(address);
  399.       Wire.requestFrom(address, 2);
  400.       while(Wire.available())
  401.       {
  402.         buff[i] = Wire.receive();  // receive one byte
  403.         i++;
  404.       }
  405.       Wire.endTransmission();  
  406.       return i;
  407.     }
  408.     void BH1750_Init(int address)
  409.     {
  410.       Wire.beginTransmission(address);
  411.       Wire.send(0x10);//1lx reolution 120ms
  412.       Wire.endTransmission();
  413.     }
復(fù)制代碼




關(guān)于傳感器標(biāo)定:
每個(gè)傳感器在出廠后的性能是不同的,在實(shí)際的應(yīng)用中需要進(jìn)行標(biāo)定。儀器中需要標(biāo)定的傳感器是MG811二氧化碳、MQ131臭氧和DSM501A灰塵傳感器,其它的傳感器是數(shù)字輸出,在出廠前經(jīng)過標(biāo)定。標(biāo)定方法參考:



數(shù)據(jù)采集與展示:
固定采集:


移動(dòng)采集:


圖中紅色代表高值,藍(lán)色代表低值。


下一步工作:
MQ系列傳感器輔助電路類似,儀器只需更換傳感器探頭和標(biāo)定可實(shí)現(xiàn)其它氣體測(cè)量
由于MQ131和MG811屬于加熱型傳感器耗電量大,2800mAh的鋰電池只能連續(xù)工作3.5小時(shí)左右,同時(shí)二氧化碳和臭氧氣體不適合移動(dòng)觀測(cè),下一步打算將兩種氣體傳感器設(shè)置在固定監(jiān)測(cè)儀器上,在留出的面板位置上安裝1602液晶顯示,儀器同時(shí)實(shí)現(xiàn)便攜式GPS功能。

致謝:
儀器在制作過程中得到論壇和Arduino 與 ADK 熱心網(wǎng)友的大力幫助,他們?cè)绯鐾須w,談天論地,不分主題,有問必答,暢所欲言,謝謝大家!!


風(fēng)塵檢測(cè)傳感器相關(guān)代碼:



  1.     while(goloop)      //loop
  2.     {
  3.     currentMillis = micros();
  4.     if(currentMillis<previousmillis)
  5.     {
  6.     partMillis = 4294967295 -  previousMillis +1;
  7.     previousMillis = 0;  
  8.     }
  9.     if(currentMillis - previousMillis - partMillis < mintev)
  10.     {
  11.     //1.0
  12.     if(temp1_0==0)
  13.     {
  14.     temp1_0=-1;
  15.     temp1_0=pulseIn(DSMPin1_0, LOW);
  16.     }
  17.     if(temp1_0>0)
  18.     {
  19.     duration1_0 =duration1_0 + temp1_0;
  20.     temp1_0=0;
  21.     }
  22.     //2.5
  23.     if(temp2_5==0)
  24.     {
  25.     temp2_5=-1;
  26.     temp2_5=pulseIn(DSMPin2_5, LOW);
  27.     }
  28.     if(temp2_5>0)
  29.     {
  30.     duration2_5 =duration2_5 + temp2_5;
  31.     temp2_5=0;
  32.     }
  33.     }
  34.     else
  35.     {
  36.     goloop=false;
  37.     previousMillis=currentMillis;
  38.     }
  39.     }
  40.     double per =double(duration1_0)/double(interval);// had multiply 1000
  41.     int pcs1_0 = -1;
  42.     pcs1_0 =  per * 50.0;
  43.     per =double(duration2_5)/double(interval);// had multiply 1000
  44.     int pcs2_5 = -1;
  45.     pcs2_5 =  per * 50.0;
復(fù)制代碼


作者: 碌碌無為    時(shí)間: 2020-5-10 12:50
感謝樓主分享,收藏了。




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 超碰免费在线观看 | 福利久久 | 成人二区 | 青春草在线 | 中文字幕高清免费日韩视频在线 | av影音资源 | 在线免费av观看 | 亚洲电影在线播放 | 九九国产 | 黄片毛片免费观看 | 精品成人av | xx性欧美肥妇精品久久久久久 | 国产精品精品久久久 | 亚洲在线成人 | 午夜寂寞福利视频 | 日韩视频成人 | 亚洲一区亚洲二区 | 久久久精品一区二区三区 | 国产亚洲一区二区三区在线观看 | 在线不卡一区 | 久久久福利 | 中文成人在线 | 日本一道本视频 | 国产一级片精品 | 小川阿佐美pgd-606在线 | 又黑又粗又长的欧美一区 | 天天久 | 99精品网| 国产在线观看一区二区 | 天天干狠狠操 | 国产高清不卡 | av资源中文在线天堂 | 蜜桃av人人夜夜澡人人爽 | 国产欧美日韩一区二区三区在线 | 亚洲国产欧美在线 | 国产精品久久在线观看 | 成人二区三区 | 精品视频一区二区三区在线观看 | av片免费| 久久精品久久精品久久精品 | 一区二区三区视频在线观看 |