Tuesday, August 25, 2020

Testing the micro:bit's Analog Inputs

The BBC GPIO connection rings (labelled 0, 1 and 2) of a micro:bit can all be used as analog inputs.

You might think, that as long as you are careful to to exceed the 3V input voltage limit, then you can measure any low voltage whatever the source. Perhaps a photoresistor in a voltage divider arrangement with a fixed resistor. 

While this is basically true, if the source of the voltage to be measured has a high output impedance, at some point the voltage measured by the micro:bit will diverge from reality as the impedance of the voltage source being measured increases.

In reality, you can't measure something without altering it. The best we can do is to make the measurement errors small, so that they can be ignored.

This blog post determines the extent of this measurement error with the micro:bit's analog inputs.

Equipment Used

Here's a handy test program that reports the voltage at P0 when button A is pressed, that I used in this experiment.

Use a multimeter to measure the voltage between the 3V and GND ring connectors on the micro:bit and put this value in for Vanalog. I was powering the micro:bit from USB, so Vanalog was about 3.2V.

You will also need:

  • A digital multimeter on DC volts range
  • Resistors 100Ω, 1kΩ, 10kΩ, 100kΩ, 1MΩ, 10MΩ
  • A low-impedance voltage source such as bench power supply (set to 2V) or just an AA battery
  • An alligator lead


Here's the setup for the experiment.

The ground of the micro:bit is connected to the ground of the power supply and the positive lead from the power supply is clipped to one end of the test resistor. The alligator lead is used to connect the other end of the resistor the micro:bit P0 ring. The multimeter measures the voltage at the micro:bit's P0 ring (V1). V2 is the voltage reported on the micro:bit by the test program.


Here are the results for a series of resistor values.

R (Ω)V1 (V)V2 (V)

Even the multimeter starts to give errors when connected to the voltage source via a 10MΩ resistor. The DMM used is specified as having an input impedance of 10MΩ but actually these results imply it's quite a bit better than that.

If we plot V1 and V2 against R, this is what we get:

As you can see, the micro:bit does pretty well up until a value of R of 10kΩ after which it goes down hill pretty rapidly.


If you want to use your micro:bit to measure a voltage, try and keep the output impedance of the voltage source lower than 10kΩ. 

No comments: