Analog Digital
Understanding the ins and outs
Introduction
In order to take full advantage of the Micro:bit you need to connect external input and output devices. But before you can do that you need to understand how your Micro:bit talks with the world using pins. There are two different ways to use these pins: analog and digital. Understanding this opens up a world of possibilities, with over 200 external devices you can use.
To help you understand the ins and outs of digital and analog we have a simple demonstration.
Have fun!
volts inputs outputs
A demonstration using Micro:bit
Simplest sensors
Both analog and digital
The simplest example of a digital sensor is an on/off switch.
The simplest example of an analog sensor is a volume knob (or rotary potentiometer.
Our test rig: digital
Measuring the voltage
This shows a voltage meter plugged into our Micro:bit.
We have plugged in our on/off digital switch.
The external batteries are needed because the Micro:bit runs on 3 volts and the voltage meter needs at least 4 volts.
Our test rig: analog
Measuring the voltage
This shows a voltage meter plugged into our Micro:bit.
We have plugged in our continuous analog device -- the volume knob (or rotary potentiometer).
Our code - on/off via analog read
Converting voltage to numbers
This code reads the input voltage from the switch on pin 0 and then plays it back on pin 1.
The voltage is converted into a number from 0 to 1023 and then displayed on the Micro:bit.
The result - on/off via analog read
Converting voltage to numbers
The switch is ether on or off.
You can see the voltage on the voltmeter on the right. The equivalent number (zero or 1023) is displayed on the Micro:bit.
What's happening
Under the hood
The blue line is the on/off input, varying either zero or three volts. The red line is the signal after conversion via analog read (either 0 or 1023. The output is either zero volts or a full 3 volts.
Our code - continuous via analog read
Converting voltage to numbers
This code reads the input voltage from the switch on pin 0 and then plays it back on pin 1.
The voltage is converted into a number from 0 to 1023 and then displayed on the Micro:bit.
The result - continuous via analog read
Converting voltage to numbers
The volume knob (rotary potentiometer) goes continuously from zero to 3 volts.
You can see the voltage on the voltmeter on the right. The equivalent number (zero to 1023) is displayed on the Micro:bit.
What's happening
Under the hood
The smooth analog input is converted into whole numbers, which makes the output approximately the same, but a little jagged.
Our code - on/off via digital read
Converting voltage to numbers
This code reads the input voltage from the switch on pin 0 and then plays it back on pin 1.
The voltage is converted into a number, either zero or one, and then displayed on the Micro:bit.
The result - on/off via digital read
Converting voltage to numbers
The switch is ether on or off.
You can see the voltage on the voltmeter on the right. The equivalent number (zero or one) is displayed on the Micro:bit.
What's happening
Under the hood
The blue line is the on/off digital input, coming in either zero or three volts. The red line is the signal after conversion via digital read (either 1 or 0). The output is either zero volts or a full 3 volts.
Our code - continuous via digital read
Converting voltage to numbers
This code reads the input voltage from the switch on pin 0 and then plays it back on pin 1.
The voltage is converted into a number, either zero or one, and then displayed on the Micro:bit.
The result - continuous via digital read
Converting voltage to numbers
This code reads the input voltage from the switch on pin 0 and then plays it back on pin 1.
The voltage is converted into a number, either zero or one, and then displayed on the Micro:bit.
You can see the output voltage (either zero or 3 volts) on the voltmeter on the right.
The continuous input (goes smoothly up or down) is converted to an all or nothing output (zero or one; zero volts or 3 volts).
What's happening
Under the hood
The blue line is the analog input, varying smoothly from zero to three volts. The red line is the signal after conversion via digital read (either 1 or 0). The output is either zero volts or a full 3 volts.
Challenge?
Spot the difference
Looking at the photo at the right...
What is different from what we just observed on the Micro:bit?
This graph is for a microprocessor called Arduino, which is similar to the Micro:bit.
Are you ready?
You should have a basic idea of how to use the BBC Micro:bit. Now you should be ready to start learning how to use your Micro:bit with external sensors. You can start the next step of your journey at http://microbitiot.strikingly.com
Profile
Bob Elliott
Robotics enthusiast
Bob is a maths/science/robotics teacher with degrees in biology and computing. He has been a member of the Robotics Tamania committee for several years, helping to run the Tasmanian state finals of Robocup Jr. He runs several local robotics club and with his collaborators, runs Arduino/Micro:bit robotics and IoT workshops.
Contact Us!
To get help building, programming or hosting a workshop: