element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test Instrumentation
  • Challenges & Projects
  • Project14
  • Test Instrumentation
  • More
  • Cancel
Test Instrumentation
Blog Simple resistance measurement with the micro bit and voltage divider
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test Instrumentation to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: kk99
  • Date Created: 3 Nov 2018 1:52 AM Date Created
  • Views 4961 views
  • Likes 7 likes
  • Comments 7 comments
  • intermediate micro:bit projects
  • micro:bit project
  • microbit projects
  • microbit
  • intermediate_microbit_projects
  • test instrumentation
  • diytestinstruch
Related
Recommended

Simple resistance measurement with the micro bit and voltage divider

kk99
kk99
3 Nov 2018
image

Test Instrumentation

Enter Your Electronics & Design Project for a chance to win a Grand Prize for Originality, a Tool Set, and a $100 Shopping Cart!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

image

image

Few days ago I have received package from element14 with micro bit. I would like to say thank you to element14 for chance to test this small device. I have decided to create a simple example of usage micro bit to measurement of resistance.

image

I have used for this purpose a voltage divider with reference resistance set to 1 k Ohm (1% 50ppm). Output voltage of this divider is connected to the analogue pin number 2.

image

Equation for output voltage is in following form:

Vpin2 = (Rx * Vcc) / (Rx + Rref)

To solve for Rx:

Rx = (Rref * Vpin2) / (Vcc - Vpin2)

 

The code was created in python. For this purpose I used a page python.microbit.org, which allow to generate output .hex file which I used to program my microbit.

image

Code is really simple. If user presses button A, we are reading value of voltage from PIN 2. If this value is correct then calculation of resistance is performed and user sees on display the resistance value. If user presses button B the display will be cleared. Below there is diagram for this algorithm:

image

Below there is source of code:

# Add your Python code here. E.g.
from microbit import *

referenceResistorOhm = 1e3;

while True:
    if button_a.is_pressed():
        Vout = pin2.read_analog();
        if Vout < 1023:
            resistance = (referenceResistorOhm * Vout) / (1023 - Vout)
            if resistance > 1e6:
                display.scroll(str(resistance / 1e6)+"MOhm", wait=False, loop=True)
            elif resistance > 1e3:
                display.scroll(str(resistance / 1e3)+"kOhm", wait=False, loop=True)
            else:
                display.scroll(str(resistance)+"Ohm", wait=False, loop=True)
        else:
            display.scroll("OL", wait=False, loop=True)
    elif button_b.is_pressed():
        display.clear()
    sleep(100)
   

 

I have performed quick test with following values of resistance: 10 Ohm, 100 Ohm, 1 kOhm, 4.7 kOhm, 51 kOhm, 300 kOhm, 470 kOhm, 680 kOhm and 1M Ohm. Results of measurement you would see in below movie.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • jw0752
    jw0752 over 6 years ago +3
    Simple is elegant. I like what you have done with the microbit. John
  • kulky64
    kulky64 over 6 years ago +3
    Your equation for Rx in text is not correct. But in Python code it is calculated correctly.
  • genebren
    genebren over 6 years ago +2
    Nicely done! Fun little project. Gene
  • tonygo
    tonygo over 6 years ago

    Very nice little project. Can I suggest that you try the Mu editor. It is much better than the online editor and you can print results back to the REPL. You can download it here

     

    https://codewith.mu/

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 6 years ago

    Nice simple project to get to know the MicroBit.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kk99
    kk99 over 6 years ago in reply to kulky64

    Thank you. I have corrected this. It was late when I was writing this article ;).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kulky64
    kulky64 over 6 years ago

    Your equation for Rx in text is not correct. But in Python code it is calculated correctly.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jw0752
    jw0752 over 6 years ago

    Simple is elegant. I like what you have done with the microbit.

    John

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube