大同大學科學開源服務社
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Arduino RFID 實戰 description: 這次社課將讓我們透過 Arduino 技術,模擬和實現一個門禁卡系統。這不僅有助於提升我們的程式設計和電子工程技能,還能讓我們親身體驗如何將現代科技應用於日常生活中,解決實際問題。通過實際操作,我們將學習如何設計和實作一個簡便而有效的門禁系統,從而更好地理解科技如何影響並改善我們的生活。 tags: - 社課 - 共筆 - 113 學年 --- :::success # Arduino RFID 實戰 **時間:** 2024/11/21(星期四)18:00~20:00 **地點:** 挺生大樓 A3-200 教室 **簡報:** [連結](https://www.canva.com/design/DAGWtRqDzLU/Bjl3n7VdBF0slhok3gcF1g/edit?utm_content=DAGWtRqDzLU&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton) **Slido:** [連結]() ::: > 請從這裡開始 # UID讀取程式(程式1) #### 輸出卡片長度及顯示卡號 ```c Serial.print("UID Size: "); // 顯示卡片的UID長度值 Serial.println(idSize); for (byte i = 0; i < idSize; i++) { Serial.print("id["); Serial.print(i); Serial.print("]: "); Serial.println(id[i], HEX); // 以16進位顯示UID值 } Serial.println(); mfrc522.PICC_HaltA(); // 讓卡片進入停止模式 ``` #### sak值判斷卡片種類 ```c Serial.print("PICC type: "); // 顯示卡片類型 // 根據卡片回應的SAK值(mfrc522.uid.sak)判斷卡片類型 Serial.print("SAK 值: 0x"); Serial.println(sakValue, HEX);// 以 16 進位格式顯示 SAK MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak); Serial.println(mfrc522.PICC_GetTypeName(piccType)); ``` #### 前置處理器 ```c #include <SPI.h> #include <MFRC522.h> // 引用程式庫 #define RST_PIN A0 // 讀卡機的重置腳位 #define SS_PIN 10 // 晶片選擇腳位 MFRC522 mfrc522(SS_PIN, RST_PIN); // 建立MFRC522物件 ``` #### 程式初始設定 ```c void setup() { Serial.begin(9600); Serial.println("RFID reader is ready!"); SPI.begin(); mfrc522.PCD_Init(); // 初始化MFRC522讀卡機模組 } ``` #### 主程式 ```c void loop() { // 確認是否有新卡片 if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) { byte *id = mfrc522.uid.uidByte; // 取得卡片的UID byte idSize = mfrc522.uid.size; // 取得UID的長度 byte sakValue = mfrc522.uid.sak; } } ``` #### 位元對齊程式 ```c if (id[i] < 0x10) // 如果值小於 0x10,補零 { Serial.print("0"); } ``` # 門禁卡程式(程式2) ```c #include <SPI.h> // 引入 SPI 庫,用於與 RFID 模組進行通信 #include <Servo.h> // 引入 Servo 庫,用於控制伺服馬達 #include <MFRC522.h> // 引入 MFRC522 庫,用於操作 RFID 模組 // 定義常數 #define SS_PIN 10 // 定義 RFID 模組的片選 (Slave Select) 腳位 #define RST_PIN 9 // 定義 RFID 模組的重置腳位 #define BUZZER_PIN 5 // 定義蜂鳴器的腳位 // 創建對象 Servo servo; // 創建伺服馬達的對象 MFRC522 mfrc522(SS_PIN, RST_PIN); // 創建 RFID 讀卡器的對象 int flag = 0; // 狀態變數,用於記錄伺服馬達當前的位置(控制開關狀態) // 函數原型宣告 void beep(int times, int duration); // 初始化設置 void setup() { Serial.begin(9600); // 初始化序列埠,用於輸出訊息到串列監視器 SPI.begin(); // 初始化 SPI 通信 mfrc522.PCD_Init(); // 初始化 RFID 讀卡器 Serial.println("Approximate your card to the reader"); // 提示訊息 pinMode(BUZZER_PIN, OUTPUT); // 設置蜂鳴器腳位為輸出 digitalWrite(5, HIGH); // 初始化蜂鳴器為關閉狀態 servo.attach(3); // 設置伺服馬達的控制腳位 servo.write(50); // 將伺服馬達設置到初始位置 (50 度) } // 主循環函數 void loop() { // 檢查是否有新卡片 if (!mfrc522.PICC_IsNewCardPresent()) { return; // 如果沒有新卡片,返回並繼續檢查 } // 嘗試讀取卡片序列號 if (!mfrc522.PICC_ReadCardSerial()) { return; // 如果讀取失敗,返回並繼續檢查 } // 讀取 UID Serial.print("UID tag: "); // 輸出 UID 標籤提示 String content = ""; // 用於存儲卡片的 UID for (byte i = 0; i < mfrc522.uid.size; i++) { if (mfrc522.uid.uidByte[i] < 0x10) { Serial.print("0"); // 如果是單位數,補 0 } Serial.print(mfrc522.uid.uidByte[i], HEX); // 以十六進制輸出 UID content += (mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // 合併成字串 } Serial.println(); Serial.print("Complete UID: "); // 提示完整的 UID Serial.println(content); content.toUpperCase(); // 將 UID 轉為大寫以便比較 // 如果 UID 匹配特定值 if (content == "35129B1B") { if (flag % 2 == 0) // 如果 flag 是偶數 { servo.write(10); // 伺服馬達轉到 10 度 flag++; // 更新 flag 狀態 Serial.print("Flag: "); Serial.println(flag); Serial.print("Door Close "); // 蜂鳴器響 3 次,每次持續 100 毫秒 beep(3, 100); delay(1000); // 延遲 1 秒,等待伺服馬達完成動作 } else // 如果 flag 是奇數 { servo.write(90); // 伺服馬達轉回 50 度 flag++; // 更新 flag 狀態 Serial.print("Flag: "); Serial.println(flag); Serial.print("Door Open "); // 蜂鳴器響 2 次,每次持續 150 毫秒 beep(2, 150); delay(1000); // 延遲 1 秒,等待伺服馬達完成動作 } } else // 如果 UID 不匹配 { delay(100); // 延遲 100 毫秒 beep(4, 75); // 蜂鳴器響 4 次,每次持續 75 毫秒 servo.write(30); // 無效卡片時伺服馬達轉到 30 度 Serial.print("Wrong card "); } mfrc522.PCD_Init(); } // 蜂鳴器控制函數 void beep(int times, int duration) { for (int i = 0; i < times; i++) { digitalWrite(BUZZER_PIN, LOW); // 開啟蜂鳴器 delay(duration); // 蜂鳴器響的持續時間 digitalWrite(BUZZER_PIN, HIGH); // 關閉蜂鳴器 delay(duration); // 蜂鳴器停止的間隔時間 } } ``` <br> <br> --- ## Arduino 安裝 [Arduino 安裝連結](https://www.arduino.cc/en/software)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully