IoT教具研發
      • 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
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: LAB01 - ADC電壓量測實驗 slideOptions: transition: slide transitionSpeed: 'fast' theme: league --- <!-- .slide: data-background="https://i.imgur.com/cgViIs1.jpg" data-background-color="#111111" data-background-opacity="0.2" --> ###### tags:`js-iot` `lab` 返回[電子電路實驗與JavaScript物聯網應用](/s/8Q89ww-EQlOg8zy7XSTlCw) ## LAB 01 <br> <span style="color:#F9BF45;">ADC電壓量測實驗</span> ###### [點我開啟簡報模式](/@BEExANT-ta/S1pZrairK#) ###### <kbd>ESC</kbd> 鍵進入總覽模式 ###### <kbd>&#8592;</kbd> <kbd>&#8593;</kbd> <kbd>&#8595;</kbd> <kbd>&#8594;</kbd> 切換頁面 --- ## 目標 - 實驗一 - 分壓計算與量測 - 實驗二 - LED電壓量測 ---- ### :dart: 實驗一 - 分壓計算與量測 **將兩個相同大小的電阻串聯分壓,計算出應該得到的電壓值,再使用ADC輸入量測電壓,並替換不同大小電阻,觀察數據並理解爲何量測與計算值不同。** ---- ### :dart: 實驗二 - LED電壓量測 **使用ADC輸入腳位量測電壓,在網頁取得ADC輸入資料,換算出電壓,調整可變電阻並觀察LED亮度與電壓變化,記錄電壓與LED亮度關係。** --- ## 使用材料 - **JavaScript開發板** - **220、1K、10K、100KΩ 電阻** - **100KΩ 可變電阻** (參考[電阻色碼表](/s/ZjKg95nBRVCVy3V6aPNYgQ)) - **紅、藍、綠 LED** - **杜邦線** --- ## 線路圖 :::warning :zap: 圖上麵包板正負極與實際不同,需注意正負極 ::: ---- #### 實驗一,分壓量測(100K電阻 * 2) <center> <img src="https://i.imgur.com/nVHbaVz.png" width="68%"></img> </center> ---- #### 實驗二,LED電壓量測(1K電阻 * 1) <center> <img src="https://i.imgur.com/BWHhYTo.png" width="70%"></img> </center> --- ## 設計原理 - ADC轉換電壓公式(Vc: 轉換電壓, ADC: 量測ADC值, Vr: 輸入電壓, n bits ADC, 一般爲 10 bits)。 \begin{gather*}V_c = ADC \times V_r \times (2^n - 1)\end{gather*} ---- - 使用ADC量測電壓時,==主控板signal偵測電阻值(位於J1)需大於量測電阻值==(偵測>量測,越大越準確)。如下圖 ==100K(R1) > 22K + 10K(R2)==,並聯後的電阻值僅剩==24.24K==(依公式計算),使用ADC量測出約0.7V,與實際1.66V相差過大。 <center> <img src="https://i.imgur.com/aXNIjsL.png"></img> </center> ---- - 並聯和串聯電阻計算公式 \begin{gather*}R_T = {\cfrac{1}{(\cfrac{1}{R_1}+\cfrac{1}{R_2}+\cfrac{1}{R_3}+etc...)} }\end{gather*} :::info :globe_with_meridians: 參考資源 - [ADC 轉換公式](http://wiki.csie.ncku.edu.tw/embedded/ADC#adc-%E8%BD%89%E6%8F%9B%E5%85%AC%E5%BC%8F) - [並聯和串聯電阻計算器 ](https://www.digikey.tw/zh/resources/conversion-calculators/conversion-calculator-parallel-and-series-resistor) ::: ---- - 利用可變電阻改變電壓,透過ADC量測取得電壓(LED壓降0.7V),記錄==不同電壓下對不同LED的亮度變化==。 :::warning :zap: LED最佳工作電流為35mA以下,超過容易損耗,而實際三用電表量測會有些許誤差,需經過校正才更精確(ADC量測最大爲3.3V)。 ::: ---- - 電壓與LED間的關係圖(來源:[Testing unknown LEDs](http://lednique.com/test-equipment/testing-unknown-leds/)) <center><img src="https://i.imgur.com/YW89oKj.png"></img> </center> --- ## 範例程式 新增程式檔並命名 ==LAB01 - ADC電壓量測實驗==,將以下程式碼複製貼上程式編輯區執行。 ```javascript= let V = 3.3; let offset = 0; let adc = DATA.adc[0]; let v = 0; v = (adc - offset) / 1024 * V; v = Math.round(v * 100) /100; console.log("電源輸入: " + V); console.log("量測電壓: " + v); delay(100); ``` --- ## 程式解說 逐行講解程式意義。 ---- ```javascript= let V = 3.3; ``` - 定義區域變數 V 為 3.3,表示輸入電壓值。 ---- ```javascript= let offset = 0; ``` - 定義區域變數 offset 為 0,為ADC校正歸零的偏差值。 ---- ```javascript= let adc = DATA.adc[0]; ``` - 定義區域變數 adc 為DATA.adc[0],意思是DATA物件中adc陣列的第一個值,代表==第一個腳位的ADC資料==。 ---- ```javascript= let v = 0; ``` - 定義區域變數 v 為0,作為儲存輸出電壓值的變數 。 ---- ```javascript= v = (adc - offset) / 1024 * V; ``` - 將ADC值校正後換算成電壓,把值設給 v。 ---- ```javascript= v = Math.round(v * 100) /100; ``` - 將 v 值取到小數後二位。 ---- ```javascript= console.log("電源輸入: " + V); console.log("量測電壓: " + v); ``` - 在訊息輸出區顯示輸入電源(V)與量測電壓(v)。 ---- ```javascript= delay(100); ``` - 等待100毫秒後繼續執行。 --- ## 參數修改 為方便實作,以下會將範例程式中可修改的參數標示出來,進行實作時只需修改對應參數,並觀察結果即可。 :::warning :zap: 詳細內建JS參數參考 - [內建Js參數及功能總覽](/s/51F8nDF3Ss6M2DmGoRJQbA) ::: ---- :::success **offset = ==0==;** ::: - 依據ADC輸入的初始值設定,將其校正歸零。 ---- :::success **adc = DATA.adc[==x==];** ::: - x可代入 0 ~ 15,表示取得第1 ~ 16個腳位的ADC資料,依據使用的腳位填入對應的數字。 --- ## 範例影片 {%youtube EAYI-9glMKE %} ---- {%youtube Wgp_tpqvVic %} <a class="btn btn-warning" style="width:100%;color:#333333;" href="/s/4CgYHd9BREiq0TwqEWpRKw" role="button"> JavaScript基礎語法與變數運用 **&#8680;** </a> <a class="btn btn-primary" style="width:100%;" href="/s/r8SqOJDqQlGaYIUxYinQHw" role="button"> **&#8678;** 開發板網頁功能總覽 </a>

    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