This webpage has been designed to support our in-person Introduction to Electronics Workshop.
Each group should have:
You will then need to open a new project on Makecode for programming your Micro:Bit.
Task 1: To identify and successfully program your numbered component.
Task 2: Create a programmed circuit using both an input and output device.
For information to help wire, program and identify your component, select the relevant button (same number as your random component) below.
This component is an INPUT device.
To use this in a program, you will need to determine if it is analog(ue) or digital.
How do we do that?
We shall initially treat all inputs as analog(ue) - we will then see all values received. If there are only two values we know the device is digital.
This component is an OUTPUT device.
To use this in a program, you will need to determine if it is analog(ue) or digital.
How do we do that?
We shall need to try both of the below programs to determine the output type of this component,
Please note: It is possible for an output to be both analog(ue) and digital - allowing us to choose how to program it.
Please note: This device has three different inputs to investigate.
Please note: This device has three different outputs to investigate
The test program:
In Makecode, reproduce the below program.
The test program:
In Makecode, reproduce the below program.
You will also need to add a new menu of blocks. To do this, select Extensions from the menu and select the one called Sonar.
The Test Program
In Makecode, reproduce the below program.
You can now download the program to your Micro:Bit.
This component does not require additional power so you do not need to connect the battery bank.
Leave the Micro:Bit connected to the computer and select the Show data Device button beneath the simulator.
This will show a graph of the input values received. Is it analog(ue) or digital?
Can you work out what the component is measuring? There is a component list button at the bottom of this page that may help.
You can now download the program to your Micro:Bit.
This component does not require additional power so you do not need to connect the battery bank.
To stop the program (some outputs can be annoying), unplug from the computer.
You can now download the program to your Micro:Bit.
Unplug the Micro:Bit from your computer.
Connect the provided power bank to the breakout board, connecting it to the Micro:Bit will limit the power available.
To stop the program (some outputs can be annoying), unplug the power bank.
You can now download the program to your Micro:Bit.
Unplug the Micro:Bit from your computer.
Connect the provided power bank to the breakout board, connecting it to the Micro:Bit will limit the power available.
This test program will print the reading on the Micro:Bit's screen everytime you press button A on it. Are the numbers showing this to be an analog(ue) or a digital device?
Can you work out what the component is measuring? There is a component list button at the bottom of this page that may help.
WARNING: Do not operate using additional power as it can make the output damaging/unsafe!
Now that you've identified your input device and what it is measuring we shall connect an output called a Neopixel Strip to your circuit and program the lights to react to the input value.
For this program you will need to add the neopixel extension to Makecode.
Look at the labels on the back of the neopixel strip where the wires connect. They should be labelled as GND, DI, and VCC.
Connect the wire from the GND to any of the black pins on the breakout board.
Connect the VCC wire to any of the red pins on the breakout board.
The wire for DI needs to connect to yellow pin number 8.
Analog(ue) Inputs
Below is an example program for using the neopixel strip with an analog(ue) input device.
If you are using a device with more than one input pin you will need to adapt the program to read each one and give a different response.
This program may need adjustments to match the values to the range detectable and controllable within the environment. For example, if the class is noisy, the sound sensor will need a higher value to activate the output or else we cannot test if it turns off.
Digital Inputs
Below is an example program for using the neopixel strip with an digital input device.
This program includes an error capture - this means if the input is not 0 or 1, the word 'ERROR' will scroll across the Micro:Bit screen. This means that either there is an error in your program and/or the input you're using is analog(ue) not digital.
Download the program to your Micro:Bit.
Unplug from the computer.
Connect a battery pack/power bank to the breakout board (not the Micro:Bit). We need to provide extra voltage to support the use of two components.
Check that the program behaves as expected. If not, check your code and/or make modifications to values and start the testing process again.
WARNING: The neopixel strips can be very bright and cause dazzling. If it is too bright to work with, there is a 'strip set brightness' block in the Neopixel more menu which you can use to reduce it (255 is the maximum value with 0 as off).
For Analog(ue) Inputs
You can add else if statements to your program (just click on the plus symbol within the 'else' section of the if/else block) to have different lighting affects to represent different levels of readings.
If you're feeling particularly confident/brave you could have a look at mapping the value of the input onto the output. This means that the lighting on the neopixel would be indicative of the strength of the input. The higher the input value, the more lights show.
We've put together an example of using mapping with the input of sound using a sensor with a range of 0 (silent) to 255 (very loud) onto a servo which can rotate between 0° and 180°. This recreates a dial effect where a needle connected to the servo would indicate the noise level.
Important: We have a range of 0° to 180° on the servo but the sound level has a range of 0 to 255. There are two ways to approach this:
Do the maths ourselves
(180 ÷ 255) = 0.7058823529411°
Use the 'map' block
For more background and information feel free to review the exercises in Session Five of our Micro:Bit Programming Series.
For Digital Inputs
If your input was a digital device, you have more limitations on options for an output, it's either on or off.
However, that does not mean you cannot have fun exploring ways to create a unique colour effect and/or a randomised output when activated.
One way to do this would be to program each LED of the strip individually and set the colour value of each independently. To do this you will need to use the 'range' blocks available in the Neopixel menu.
Check out the exercises for Session Four of our online Micro:Bit series for more information about programming different parts of a neopixel strip.
If you've finished your circuit and are happy that it works how you want, feel free to start again with a different numbered component.
Now that you've identified your output device and whether it's digital or analog(ue) we shall connect an input called an ultrasonic sensor to your circuit and program your output to react to it.
For this program you will need to add the sonar extension to Makecode.
This new component has four connection points
The input we're receiving from the ultrasonic can be set to centimetres (however, the accuracy is not very good). We can then design a program that either outputs when an object gets too close or have an output that indicates difference.
For Analog(ue) Outputs
Below is an example/starter program for use with an analog(ue) output device.
If you are using a device with more than one output pin you will need to adapt the program to write to each one.
For Digital Outputs
Below is an example/starter program for use with a digital output device.
WARNING! If using the Super Bright LED, this increased power will make it even more blinding. Make sure you have it safely shielded so as not to cause eye damage to anyone in the room.
For Analog(ue) Outputs
You can add else if statements to your program (just click on the plus symbol within the 'else' section of the if/else block) to have different outputs to represent different distances.
If you're feeling particularly confident/brave you could have a look at mapping the value of the input onto the output. This means that the output would be indicative of the closeness of an object.
We've put together an example of using mapping with the input of sound using a sensor with a range of 0 (silent) to 255 (very loud) onto a servo which can rotate between 0° and 180°. This recreates a dial effect where a needle connected to the servo would indicate the noise level.
Important: We have a range of 0° to 180° on the servo but the sound level has a range of 0 to 255. There are two ways to approach this:
Do the maths ourselves
(180 ÷ 255) = 0.7058823529411°
Use the 'map' block
For more background and information feel free to review the exercises in Session Five of our Micro:Bit Programming Series.
For Digital Outputs
There are less options for varying the result of your circuit when using a digital output.
One suggestion would be to test the accuracy of the ultrasonic sensor by changing the value that triggers your output and comparing it to the actual measurement that triggers it in testing.
If you've finished your circuit and are happy that it works how you want, feel free to start again with a different numbered component.