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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

求一個PM2.5檢測儀的Arduino源程序

[復制鏈接]
跳轉到指定樓層
樓主
    購得夏普GP2Y1010AU0F 傳感器,手頭有我自己寫好引導程序的ATMEGA328P的芯片,有Arduino R3板(可往芯片里寫程序),還有1602液晶屏,想用自己搭建的ATMEGA328P最小系統,制作一個PM2.5檢測儀,,只差可用的源程序了,在網上沒有搜到可用的,請哪位有的朋友,給我傳一個,1602屏要用四線制驅動,多謝了!






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

使用道具 舉報

沙發
ID:1 發表于 2016-4-16 22:08 | 只看該作者
回復

使用道具 舉報

板凳
ID:111876 發表于 2016-4-17 11:15 | 只看該作者
admin 發表于 2016-4-16 22:08
http://www.zg4o1577.cn/bbs/dpj-48466-1.html

謝謝版主!但他那個似乎是51單片機的,而我用的是ATMEGA328P的單片機芯片,需要的是Arduino的源程序!
回復

使用道具 舉報

地板
ID:111876 發表于 2016-4-30 16:07 | 只看該作者
網上找了個源代碼,做了一些改寫,現在已經成功了,這是我學習單片機一個月以來,做成的第一個小東西。有成就感,高興啊!哈哈!



20160430_150156.jpg (186.5 KB, 下載次數: 307)

20160430_150156.jpg

評分

參與人數 1黑幣 +100 收起 理由
admin + 100 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

5#
ID:111876 發表于 2016-4-30 16:38 | 只看該作者
yjx189 發表于 2016-4-30 16:07
網上找了個源代碼,做了一些改寫,現在已經成功了,這是我學習單片機一個月以來,做成的第一個小東西。有成 ...

謝謝版主先生的在此加分,
回復

使用道具 舉報

6#
ID:111876 發表于 2016-4-30 16:48 | 只看該作者
本帖最后由 yjx189 于 2016-4-30 16:50 編輯

    下一步打算用手頭就有的89C2051單片機,加上1602顯示屏,使用壇友送我的SP200S編程器寫程序,做一個能測量電感,電容的單片機LC表!這樣的LC表還是有一定的使用價值的!
回復

使用道具 舉報

7#
ID:117823 發表于 2016-5-1 16:34 | 只看該作者
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dht11.h>
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6. #include <DS1302.h>

  7. char sensor;
  8. static long timer;
  9. static byte session;
  10. long previousMillis = 0;  
  11. long interval = 1000;

  12. int sensorPin = A3;
  13. int sensorValue = 0;
  14. int sensorPin1 = A7;
  15. int sensorValue1 = 0;
  16. const int buzz=3;
  17. const int  alcoholic=A6;
  18. static int alcoholic_value=200;
  19. char buflcd[16];
  20. dht11 DHT11;
  21. #define DHT11PIN 2
  22. LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  23. namespace {

  24. // Set the appropriate digital I/O pin connections. These are the pin
  25. // assignments for the Arduino as well for as the DS1302 chip. See the DS1302
  26. // datasheet:
  27. const int kCePin   = A2;  // Chip Enable
  28. const int kIoPin   = A1;  // Input/Output
  29. const int kSclkPin = A0;  // Serial Clock

  30. // Create a DS1302 object.
  31. DS1302 rtc(kCePin, kIoPin, kSclkPin);
  32. void ds1302_init()
  33. {
  34.   rtc.writeProtect(false);
  35.   rtc.halt(false);
  36. }

  37. String dayAsString(const Time::Day day) {
  38.   switch (day) {
  39.     case Time::kSunday: return "Sunday";
  40.     case Time::kMonday: return "Monday";
  41.     case Time::kTuesday: return "Tuesday";
  42.     case Time::kWednesday: return "Wednesday";
  43.     case Time::kThursday: return "Thursday";
  44.     case Time::kFriday: return "Friday";
  45.     case Time::kSaturday: return "Saturday";
  46.   }
  47.   return "(unknown day)";
  48. }

  49. void printTime() {
  50.   // Get the current time and date from the chip.
  51.   Time t = rtc.time();
  52.   // Format the time and date and insert into the temporary buffer.
  53.   snprintf(buflcd, sizeof(buflcd), "%2d-%d-%d %d:%d:%d   ",
  54.            t.yr-2000, t.mon, t.date,
  55.            t.hr, t.min, t.sec);

  56.   // Print the formatted string to serial so we can see the time.
  57.   lcd.setCursor(0,1);
  58.   lcd.print(buflcd);
  59. }

  60. void edit_time()
  61. {
  62.   /* 串口數據緩存 */
  63. String comdata = "";
  64. int numdata[7] ={0}, j = 0, mark = 0;
  65.   while (Serial.available() > 0)
  66.     {
  67.         comdata += char(Serial.read());
  68.         delay(2);
  69.         mark = 1;
  70.     }
  71.     /* 以逗號分隔分解comdata的字符串,分解結果變成轉換成數字到numdata[]數組 */
  72.     if(mark == 1)
  73.     {
  74.         Serial.print("You inputed : ");
  75.         Serial.println(comdata);
  76.         for(int i = 0; i < comdata.length() ; i++)
  77.         {
  78.             if(comdata[i] == ',' || comdata[i] == 0x10 || comdata[i] == 0x13)
  79.             {
  80.                 j++;
  81.             }
  82.             else
  83.             {
  84.                 numdata[j] = numdata[j] * 10 + (comdata[i] - '0');
  85.             }
  86.         }
  87.         if(numdata[0]>2000)
  88.         {
  89.         /* 將轉換好的numdata湊成時間格式,寫入DS1302 */
  90.         Time t(numdata[0], numdata[1], numdata[2], numdata[3], numdata[4], numdata[5], Time::kSaturday );
  91.         rtc.time(t);
  92.         }
  93.         else
  94.         {
  95.           if(numdata[0]>100)
  96.           {
  97.            alcoholic_value= numdata[0];
  98.           }
  99.         }
  100.     }
  101. }

  102. }  // namespace
  103. #if defined(ARDUINO) && ARDUINO >= 100
  104. #define printByte(args)  write(args);
  105. #else
  106. #define printByte(args)  print(args,BYTE);
  107. #endif
  108. uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
  109. uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
  110. uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
  111. uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
  112. uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
  113. uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
  114. uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
  115. uint8_t retarrow[8] = {        0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
  116. void lcd_init()
  117. {
  118.   lcd.init();                      // initialize the lcd
  119.   lcd.backlight();
  120.   lcd.createChar(0, bell);
  121.   lcd.createChar(1, note);
  122.   lcd.createChar(2, clock);
  123.   lcd.createChar(3, heart);
  124.   lcd.createChar(4, duck);
  125.   lcd.createChar(5, check);
  126.   lcd.createChar(6, cross);
  127.   lcd.createChar(7, retarrow);
  128. }

  129. void dh11()
  130. {
  131.   int chk = DHT11.read(DHT11PIN);  
  132.   Serial.print("Humidity (%): ");
  133.   Serial.println((int)DHT11.humidity);
  134.   Serial.print("Temperature (oC): ");
  135.   Serial.println((int)DHT11.temperature);
  136.   sensorValue = analogRead(sensorPin);
  137.   Serial.print("Light=" );                       
  138.   Serial.println(sensorValue);
  139.   sensorValue1 = analogRead(sensorPin1);
  140.   Serial.print("alcoholic=" );                       
  141.   Serial.println(sensorValue1);  
  142.   lcd.setCursor(0,0);
  143.   snprintf(buflcd, sizeof(buflcd), "%2dC %2d %3d %3d  ", DHT11.temperature,DHT11.humidity,sensorValue,sensorValue1);
  144.   lcd.print(buflcd);
  145. }
  146. void pin_mode()
  147. {
  148. pinMode(buzz, OUTPUT);
  149. digitalWrite(buzz, LOW);
  150. pinMode(alcoholic, INPUT);
  151. }

  152. void alcoholic_buzz()
  153. {
  154.   sensorValue1 = analogRead(sensorPin1);
  155.   if(sensorValue1>alcoholic_value)
  156.   {
  157.     digitalWrite(buzz, HIGH);
  158.     lcd.setCursor(15, 0);
  159.     lcd.printByte(0);
  160.   }
  161.   else
  162.   {
  163.     digitalWrite(buzz, LOW);
  164.     lcd.setCursor(15, 0);
  165.     lcd.print(" ");
  166.   }
  167. }


  168. void setup()
  169. {
  170.   Serial.begin(115200);
  171.   pin_mode();
  172.   lcd_init();
  173. ds1302_init();
  174. }

  175. void loop()
  176. {
  177.   unsigned long currentMillis = millis();
  178.     if(currentMillis - previousMillis > interval)
  179.    {
  180.    //display temperature and humidity   
  181.     previousMillis = currentMillis;
  182.     dh11();
  183.     alcoholic_buzz();
  184.     printTime();
  185.    }  
  186.   edit_time();
  187. }
復制代碼
回復

使用道具 舉報

8#
ID:111876 發表于 2016-5-2 10:31 | 只看該作者
dadangjia 發表于 2016-5-1 16:34
#include
#include
#include

謝謝,但是I2C的板子很難伺候,我網購了2塊I2C轉接板,用時一周,把網上能搜到,能問到的所有辦法都試過了,結果是1602屏不能正常顯示,,最后又返回來使用四線式連接,才解決的問題!!去他地吧I2C!!
回復

使用道具 舉報

9#
ID:111876 發表于 2016-5-2 10:36 | 只看該作者
樓上的先生,再仔細一看你上傳的程序,是一個采用1302的時鐘源代碼啊!
回復

使用道具 舉報

10#
ID:117823 發表于 2016-6-4 01:38 來自手機 | 只看該作者
可以用,我用了10個pcf8574 iic模塊1602可以正常使用,很簡單的。我采用的是ds1302代碼,庫文件可以在網上找,大多類似。
回復

使用道具 舉報

11#
ID:111876 發表于 2016-6-6 07:13 | 只看該作者
dadangjia 發表于 2016-6-4 01:38
可以用,我用了10個pcf8574 iic模塊1602可以正常使用,很簡單的。我采用的是ds1302代碼,庫文件可以在網上 ...

說的什么啊?
回復

使用道具 舉報

12#
ID:180355 發表于 2017-3-22 15:42 | 只看該作者
yjx189 發表于 2016-4-30 16:07
網上找了個源代碼,做了一些改寫,現在已經成功了,這是我學習單片機一個月以來,做成的第一個小東西。有成 ...

你好,求打包
回復

使用道具 舉報

13#
ID:193375 發表于 2017-4-25 15:49 | 只看該作者
求分享
回復

使用道具 舉報

14#
ID:202802 發表于 2017-5-20 11:15 | 只看該作者
#include <UTFT.h>


UTFT myGLCD(YYROBOT_TFT144,A2,A1,A5,A4,A3);  // Remember to change the model parameter to suit your display module!
//YYROBOT_TFT144  屏幕型號,不用修改
//SDA----A2
//SCL----A1
//CS-----A5
//RST----A4
//RS----A3
//LED---A0  UTFT庫里面設定的,如果需要修改需要修改庫文件

extern uint8_t SmallFont[];//原始文件在庫文件的DefaultFonts.c中
extern uint8_t BigFont[];//原始文件在庫文件的DefaultFonts.c中
extern uint8_t SevenSegNumFont[];//原始文件在庫文件的DefaultFonts.c中
const uint8_t tfont16[] =
{

  0x10,0x04,0x1F,0xFC,0x10,0x84,0x10,0x80,0x10,0x80,0x10,0x80,0x0F,0x00,0x00,0x00,/*"P",0*/
  0x10,0x04,0x1F,0xFC,0x1F,0x00,0x00,0xFC,0x1F,0x00,0x1F,0xFC,0x10,0x04,0x00,0x00,/*"M",1*/
  0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00,/*"2",2*/
  0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*".",3*/
  0x00,0x00,0x1F,0x98,0x10,0x84,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00,/*"5",4*/
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",5*/
  0x08,0x20,0x06,0x20,0x40,0x7E,0x31,0x80,0x04,0x20,0x18,0x40,0x10,0x80,0x13,0xFF,
  0x1C,0x02,0xF3,0x84,0x10,0x60,0x10,0x50,0x14,0x88,0x19,0x04,0x00,0x02,0x00,0x00,/*"濃",6*/
  0x00,0x02,0x00,0x0C,0x3F,0xF1,0x24,0x01,0x24,0x21,0x24,0x32,0x3F,0xAA,0xA4,0xA4,
  0x64,0xA4,0x24,0xA4,0x3F,0xAA,0x24,0x32,0x24,0x01,0x24,0x01,0x20,0x01,0x00,0x00,/*"度",7*/


};

#define PM2_5Serial Serial1 //用于接收PM2.5數據
//本例程使用MEGA2560,有Serial1,若使用UNO,請將這里修改為Serial
//并且把DebugSerial.begin(9600);修改為DebugSerial.begin(2400);
//串口界面通過2400波特率觀看數據
#define DebugSerial Serial //用于把數據通過串口界面返回

byte buffer[7] = {
};
int count = 0;
bool bufferComplete = false;

void setup() {
  PM2_5Serial.begin(2400);
  DebugSerial.begin(9600);

  randomSeed(analogRead(0));

  // Setup the LCD
  myGLCD.InitLCD();//初始化液晶
  myGLCD.InitLCD();//初始化兩次有利于系統穩定
  myGLCD.InitLCD(PORTRAIT);
  myGLCD.setFont(SmallFont);//設置字體為SmallFont格式

  //ChineseFont Test 16*16自定義漢字測試
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);  
  myGLCD.print("ug/m3", RIGHT, 100);  //打印

  Show_CH_Font16(0,10,0);
  Show_CH_Font16(16,10,1);
  Show_CH_Font16(32,10,2);
  Show_CH_Font16(48,10,3);
  Show_CH_Font16(64,10,4);



  //SegNum Test
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(0, 0, 0);

}

void loop() {  
  int ppm;
  int count_sum = 0;
  long sum = 0;
  while (count_sum < 10)
  {
    while (PM2_5Serial.available() > 0) {
      char inChar = (char)PM2_5Serial.read();
      buffer[count] = (byte)inChar;

      //    DebugSerial.print("count=");
      //    DebugSerial.println(count);
      //
      //    DebugSerial.print("buffer[count]=");
      //    DebugSerial.println(buffer[count],HEX);


      if (buffer[count] == 0xAA) {
        count = 0;
        //      DebugSerial.println("start");
      }
      else if (buffer[count] == 0xFF && buffer[0] == 0xAA)
      {
        bufferComplete = true;
        //      DebugSerial.println("bufferComplete = true;");
      }

      count++;
      if (count >= 7)
      {
        count = 0;
      }
    }

    //把接收到的數據轉發出來
    if (bufferComplete == true) {
      bufferComplete = false;
      for (int i = 0 ; i < 7 ; i++)
      {
        DebugSerial.print(buffer[i], HEX);
        DebugSerial.print(",");
      }
      DebugSerial.println("");

      //處理數據
      float v_out = 0;
      v_out = (float)((buffer[1] * 256) + buffer[2]) * 5 / 1024;
      DebugSerial.print("v_out = ");
      DebugSerial.println(v_out);
      int ppm = v_out * 1000 * 0.5; //單位為ug/m3
      DebugSerial.print("ppm = ");
      DebugSerial.print(ppm);
      DebugSerial.println("ug/m3");

      if(ppm >= 0)
      {
        count_sum++;
        sum += ppm;
      }
    }
  }

  sum /= 10;
  DebugSerial.println("***********");
  DebugSerial.print("sum = ");
  DebugSerial.print(sum);
  DebugSerial.println("ug/m3");
  DebugSerial.println("***********");

  myGLCD.setFont(SevenSegNumFont);
  myGLCD.printNumI(sum, 0, 40, 4, '0');//顯示數值是i,位置x=0,y=40,長度4,空位置填充字符0


  delay(500);

}


void Show_CH_Font16(int x,int y,int FontPos)
{
  char temp,t,t1,k;
  int y0=y;
  int HZnum;

  for(t=0;t<32;t++)//每個16*16的漢字點陣 有32個字節
  {   
    temp=tfont16[t+32*FontPos];                    
    for(t1=0;t1<8;t1++)
    {
      if(temp&0x80)
      {
        myGLCD.setColor(255, 255, 255);//FontColor
        myGLCD.drawPixel(x,y);
      }
      else
      {
        myGLCD.setColor(0, 0, 0);//BackColor
        myGLCD.drawPixel(x,y);
      }

      temp<<=1;
      y++;
      if((y-y0)==16)
      {
        y=y0;
        x++;
        break;
      }

    }   
  }   


}
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品久久久久久久 | 午夜精品一区二区三区在线视 | 欧美精品在线免费 | 成人免费观看男女羞羞视频 | 午夜私人影院在线观看 | 最新国产精品精品视频 | 国产精品久久久久久久一区二区 | 一级毛片高清 | 日本黄色一级片视频 | 天天操夜夜艹 | 91亚洲免费 | 中文在线播放 | 色综合一区| 午夜电影网 | 91精品国产乱码久久久 | 一区二区亚洲 | 精品视频一区二区三区四区 | 午夜视频一区 | 久草青青草 | 国产美女黄色片 | 国产精品视频999 | 成人精品毛片 | 欧美成人影院 | 一区二区不卡高清 | 97精品国产一区二区三区 | 亚洲视频在线观看一区二区三区 | 在线第一页 | 日本不卡免费新一二三区 | av在线一区二区三区 | 欧美全黄| 国产女人与拘做受视频 | 新91| 日韩视频一级 | 91资源在线播放 | 成人中文字幕在线 | 亚洲天堂一区 | 欧美在线一区二区三区 | 在线视频a| 精品成人佐山爱一区二区 | 国产欧美日韩在线一区 | 日日av|