Skip to content

Analog inputs

Connect any analogue sensor to the Analog pins and read in a value. It is important to note however that the rule of keeping the maximum voltage applied to a micor:bit input pin at or half of the input voltage.

For example two AA batteries will give initially 3v, but after a while 2.4v will be produced.

The returned value will change based on the analog voltage reference, that is half of the input voltage.

In blocks:

analog readpinP0

While in python:


from microbit import *
a = pin0.read_analog()
print(a)
display.scroll(str(a))

Plotting an analog PIN

Using blocks, we can plot a bar graph of the values of an analog PIN on the built-in display.

Plotting Pin

In python, we can use the mu-code editor to show a graph for any signal. The example below shows a random signal:

Plotting Python

See Accelerometer for an example.