 Test InstrumentationEnter 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 Project14 Home Monthly Themes Monthly Theme Poll  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. 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. 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. 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: 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():
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. 