micro:bit Programming Manual •Free online summary
micro:bit Programming Manual
Título: Manual de Programación micro:bit
Autor: José Francisco Muñoz ( [Link] )
Editor: [Link]
1st Edition: July, 2018
This manual is an online summary of the printed management guide (available soon).
You can download it for free at:
[Link]
It has been published under the Creative Commons license:
Questions? Want to collaborate with the community? Contact us:
e-mail:info@[Link]
teléfono: 945 29 80 50 (de 8:00 a 14:00)
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •2
micro:bit Programming Manual •Free online summary
Table of contents
INTRODUCTION TO THE MICRO:BIT
PROGRAMMING THE MICRO:BIT
LED Panel
Challenge 1. Hello World
Challenge 2. Animating the icons
Challenge 3. Designing Icons
Temperature sensor
Challenge 4. Digital thermometer
Challenge 5. Ice sheet warning
Challenge 6. Optimal temperature of a refrigerator
Light sensor
Challenge 7. Twilight switch
Push buttons
Challenge 8. Which button have you pressed?
Challenge 9. Measure the intensity of ambient light
Challenge 10. Modify the brightness of the LEDs
Accelerometer
Challenge 11. Electronic debt
Challenge 12. Heads or tails.
Compass
Challenge 13. Know the orientation
Challenge 14. North Orientation Sound Alert
Radio
Challenge 15. Wireless sensor
Input and output pins
Challenge 16. Is there continuity?
Challenge 17. Moving a servomotor
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •3
micro:bit Programming Manual • Free online summary
~ Introduction to the micro:BIT ~
1.- What is the micro:BIT?
The micro:BIT is a small programmable board, with an affordable cost for anyone.
pocket. Even though its size is very small, it incorporates a large number of sensors and
actuators, along with using Open Source software, make the micro:BIT a
ideal platform to enter the world of robot programming.
2.- How is the micro:BIT programmed?
There are several platforms that allow coding the micro:BIT, among which MakeCode stands out.
both in its online and offline versions.
The online version is accessible from this link:
[Link]
The offline version can be downloaded from this link:[Link]
makecode-offline-version
In addition, the micro:Bit can be programmed with JavaScript, Python, Scratch (adding a
extension) and yTickle (application for iPad).
3.- Characteristics.
The micro:BIT incorporates:
- 25 LEDs. They can be programmed independently and allow displaying numbers.
letters and images. If the text or number does not fit on the display, it scrolls in a way
automatic.
- Light Sensor. LEDs also have the capability to be used as a light sensor.
environment.
- Buttons. There are 2 buttons, labeled as A and B. The pressing can be detected.
independent of each of them as well as the simultaneous pressing of both.
Connectors. Located at the bottom of the board, it has 25 connections that
allows connecting other sensors and actuators. 5 of the connections (0,1,2 3v. and GND)
are oversized, to facilitate connection using clamps of
crocodile.
Temperature sensor. It allows the micro:BIT to know the ambient temperature.
units are degrees Celsius.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •4
micro:bit Programming Manual •Free online summary
Accelerometer. Activated when the plate moves, allows knowing accelerations and
turns to which the plate is subjected.
Digital compass. It allows you to know the deviation from Magnetic North. Also
it allows the detection of nearby magnetic fields. When it starts being used, it enters into
calibration mode.
- Radio. Allows wireless connection with other micro:BITs.
Bluetooth. Ideal for connecting and exchanging data wirelessly with others.
devices (mobiles, tablets, computers, etc.) that have this type of connection.
- USB. Used to download programs to the card's memory and to supply power.
electrically the micro:BIT.
Battery connector. Allows the supply of electricity using two AAA batteries or one.
battery. The card lacks a switch, so when the power source is connected
the code that is in memory is executed automatically.
4.- MakeCode. First steps.
As seen earlier, MakeCode can be run online, if a connection is available.
Internet is offline.
To access the online version of MakeCode for micro:BIT directly, you must enter
in the browser the following address:[Link]
A) General Description
1. Simulator. Located in the upper left side of the screen, it shows us a
micro:BIT, where the execution of the program can be seen. This section is useful for
debug the code before uploading it to the memory of the micro:BIT.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •5
micro:bit Programming Manual • Free online summary
[Link]. Located in a vertical column, next to the simulator, there
the programming blocks are organized by categories. When you click on
the name of a category opens, to the right, a dropdown where appears
the most used blocks of the section. It is important to notice that just below the
category name, most of the time, the option appears... More, if pressed
the rest of the blocks in the category are displayed. Once the block is selected to
it should be dragged to the programming area.
3. Programming area. Located to the right of the Toolbox, it is the
area where the blocks are dragged to create the program.
[Link]. Located at the top and bottom of the screen,
it offers shortcuts to different functionalities. At the top:
4.1 Pressing on micro:bit takes you to the page[Link] where
find examples of coding in different programming languages.
4.2 The Projects section allows you to choose between:
a) My Things. Here you can create a new project or import a
previously saved file, in addition to showing a list of the
most recent programs, sorted by date.
b) Projects. In this section you will find different tutorials, step
step by step, where to learn to code the micro:BIT using MakeCode.
c) Examples. Several example codes are offered.
4.3 Share. Allows the user to share the created codes. First of all,
requests 'Publish the Project', after which a new window appears, offering a
link and different code options to be able to insert into a web page.
4.4 Allows switching between block view or viewing the code
escrito en JavaScript.
4.5 At the far right of the Toolbar are the sections
of Help, Settings, access to the MakeCode homepage and in orange the
getting started section, which offers a usage tutorial.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •6
micro:bit Programming Manual • Free online summary
The following shortcuts appear in the bottom bar:
4.6 The first icon on the left allows you to hide the simulator, which allows you to have
more available space in the Programming Area.
4.7 Download. Download the code to the micro:BIT. A default name will be used if
none was assigned previously.
4.8 By clicking on the floppy disk icon, it allows you to assign a name and download the
program to the hard drive.
4.9 The arrows allow you to undo and redo coding steps.
In the lower right corner, the “+” icon appears, which increases the zoom of the
programming area and the icon '-' that decreases the zoom.
B) How to create a program with MakeCode
The first thing that is needed is to decide which event triggers the code.
By default, MakeCode places two events in the programming area with which
start the code, these are: at the start and forever.
There are also other events that allow the program to start, located in the
categoríaEntrada, son:al presionar el botón,al presionar pinosi agitadoademás
allow different options.
To create the program, the different blocks must be dragged into the area of
programming.
The operation of the program can be checked in the simulator located at the
left. Also, depending on the introduced blocks, different options will appear.
that allow interaction with the simulator.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 7
micro:bit Programming Manual •Free online summary
C) How to download code to the micro:BIT
After connecting the micro:BIT to the computer, it appears as a new drive.
Once the program is finished and its correct functioning has been verified, it should be pressed
about the download icon, which copies the code to the computer with a name by
defect. Another option is to enter the chosen name in the box located next to the
disk icon and click on it to download. Now just copy the file
with the .hex extension to the unit that appeared after connecting the micro:BIT to the computer.
D) How to run the code.
Copying the code, the program starts to run automatically. If you
wants to use the micro:BIT disconnected from the computer, a battery pack must be connected or
battery to the connector located next to the microUSB connector and it will immediately execute the
downloaded code.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •8
Micro:bit Programming Manual •Free online summary
~ Programming the micro:BIT ~
This section will show some examples of how to program the different
sensors and actuators that make up the micro:BIT.
As explained in the previous chapter, the created codes can be verified.
initially in the simulator on the MakeCode page. Subsequently, the code can be
download to the memory of the micro:BIT and run autonomously.
LED Panel
The card consists of 25 red LEDs, which can be programmed in a way
independent. It allows showing numbers, letters, and images. The system is ready to
automatically move in the event that the characters do not fit
show
Challenge 1. Hello World.
When learning to program, the first program created is called 'Hello World'.
This code prints the text "Hello World!" on a display device.
Objective.
When connecting the micro:BIT, the text '!!!Hello World!!!' should be displayed on the LED panel.
card.
Description of the code.
It is proposed to use the start event, located in the Basic category. This block allows
execute the entered code when the micro:BIT starts
The show block string will be used next, also located in the category
Basic and introduce the text '!!! Hello World !!!'. This block allows to display each character
character, the text entered.
The code will be as follows.
The entered text string will immediately start being displayed on the LED panel.
The text does not fit in its entirety, so it will scroll automatically.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •9
micro:bit Programming Manual •Free online summary
Proposal.
Modify the code to display the programmer's name.
Challenge 2. Animating the icons.
Animation is a technique that creates the sensation of movement in images.
static. It is achieved through a sequence of ordered images, which when being
Displayed consecutively, they create the visual illusion of movement.
Objective.
It is proposed that when connecting the micro:BIT, a beating heart is displayed on the LED panel.
Description of the code.
The event 'forever' will be used, located in the Basic category.
Place the previous block inside the instruction to show icon, use the called heart.
Add the blockpause ms (100) located in the Basic category.
Repeat the two previous blocks, but selecting the 'small heart' icon.
Immediately, a heart that simulates beating is displayed in the simulator.
Proposal.
Create a code that shows an animation of scissors cutting.
Challenge 3. Designing icons.
MakeCode allows you to graphically design the icons to be displayed on the LED display.
this task has a specific block located in the Basic category. The block is
call "show LEDs" and allows the user to design their own icons by marking in shape
independently of the LEDs that you want to illuminate.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 10
micro:bit Programming Manual •Free online summary
Objective.
Design an icon in the shape of an Indalo. It is a rock figure found in a
cave in the province of Almería that represents a human figure with arms
extended and a bow over their hands. It is currently considered a symbol of the province of
Almería.
Description of the code.
The event will be used to start, located in the Basic category.
Place the previous block inside, the instruction 'show LEDs', this is located in the
Basic category. This block allows you to independently mark the LEDs that
they want to light up.
Click on the LEDs you want to light up until you get the desired icon.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •11
micro:bit Programming Manual •Free online summary
The icon with the designed shape should appear in the simulator.
Proposal.
Design a code that displays a logo designed by the programmer.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •12
Micro:bit Programming Manual • Free online summary
Temperature sensor
The temperature sensor integrated into the board detects the ambient temperature in degrees.
Celsius.
Challenge 4. Digital thermometer.
A thermometer is an instrument used to measure temperature; the most common one
consists of a closed glass capillary tube ending in a small reservoir that
contains a certain amount of mercury or alcohol, which expands when the temperature increases
temperature either contracts when decreasing and its volume variations are read on a scale
graduated.
Digital thermometers are those that, using transducer devices,
they use electronic circuits to convert small variations into numbers
tensions obtained, finally showing the temperature on a display.
Objective.
Show on the LED panel the temperature detected by the integrated temperature sensor
in the micro:BIT.
Description of the code.
It is proposed to start the program using the 'forever' event. Add the block,
located in the Basic category, show number. This block displays on the LED screen
the entered number, shifting if it is greater than 1 digit.
Replace the number '0' with the value obtained from the temperature sensor. This block is
locate in the Entry category.
Next, the screen is cleared and a pause of 1000 ms is introduced. Leaving the
program in the following way:
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •13
micro:bit Programming Manual • Free online summary
In the simulator, there will be a vertical bar that allows you to modify the temperature, being the
temperature indicated on the LED panel.
Proposal.
Create a program that, when the A button is pressed, displays the temperature in degrees Celsius and when
Press button B to display the temperature in degrees Fahrenheit.
Challenge 5. Ice plate warning.
Most cars include in the dashboard, next to the screen that indicates the
outside temperature, a snowflake-shaped indicator that warns of the possibility of
that there are ice patches on the road. This indicator usually lights up when the
low temperature of 3 degrees Celsius.
Objective.
Show a snowflake icon on the LED panel of the micro:BIT when the
temperature is below 3 degrees.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •14
micro:bit Programming Manual •Free online summary
Code description.
To start the program, it is proposed to use the event forever. Subsequently, it should be
Add the logical operator if ... then located in the Logic section. This block checks if
It is true that a condition is met, if so, execute the entered instructions.
To check if the temperature is below 3 degrees Celsius, the will be used
operator that returns true whenever 3 is greater than the reported value.
temperature sensor. The block is located in the Logic category.
To display a snowflake-shaped icon, the LED display block will also be used.
It is necessary to add the block to clear the screen so that the LED panel does not stay on.
when the temperature rises by 3º Celsius
Once the code is finished, the ice symbol will appear when the temperature is
less than 3 degrees Celsius.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •15
micro:bit Programming Manual • Free online summary
Proposal.
Add a sound alert when the temperature is below 3 degrees Celsius.
Challenge 6. Optimal refrigerator temperature
The optimal temperature for a refrigerator is 7ºC, while the temperature of a
The freezer should be around -18ºC. Some refrigerators include a notifier.
acoustic that activates when the temperature is not optimal.
Objective.
Display the refrigerator temperature on the micro:BIT LED panel and activate an alarm.
when the temperature is above 7ºC
Description of the code.
In this challenge, a speaker is incorporated as an external actuator. One of the poles will be connected.
to GND and the other to PIN 0.
To start the program, the 'forever' block will be used. Inside, the condition 'if' will be placed.
then.” The condition to verify will be: if the temperature is above 7 degrees.
If the value is true, a warning tone will be played.
The measured temperature is also displayed.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 16
micro:bit Programming Manual • Free online summary
In the simulator, the temperature can be changed to check the correct functioning.
of the program.
Proposal.
Modify the code to monitor the freezer.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 17
micro:bit Programming Manual • Free online summary
Light sensor
The LEDs on the micro:bit board can also act as input by detecting
the ambient light.
Challenge 7. Twilight switch.
When the intensity of light falls below a certain level of illumination
predetermined and adjusted beforehand, the twilight switch turns on the
lighting. On the contrary, if the intensity of the light is greater than the preset level, the
switches turn off the lighting.
Objective.
Create a program that measures the existing light level, for this it will use the light sensor of
the micro:BIT. Subsequently, it will be checked if this value is less than 50; if so, it
All LEDs on the board will light up at their maximum intensity.
Code description.
The event will always be used to start the program. The condition will be introduced if ...
So, if not, to check if it is above or below the taken theoretical value.
as a limit on this occasion 50. If the value is less than 50, the intensity of the
LEDs at maximum using the brightness adjustment block 255. If the value is above 50, it will use the
block erase the screen to turn off all the LEDs this way.
The code would look as follows, its functionality can be checked by varying the
intensity in the card simulator.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 18
micro:bit Programming Manual •Free online summary
Proposal.
One variant of this challenge would be to make the brightness of the LEDs adapt to the intensity of the
media light through the sensor. The greater the intensity received by the sensor, the lower the intensity of
lighting and lower measured intensity, greater brightness of the LEDs.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •19
micro:bit Programming Manual •Free online summary
Buttons
There are two buttons on the front face of the micro:bit (labeled A and B). You can detect
when pressed independently or at the same time and execute an action in each case.
Challenge 8. Which button have you pressed?
Sometimes it may be interesting to use a button to start, pause, or stop a code or
subroutine. Some robots include control panels for this purpose.
Objective.
Crear un programa que muestre en pantalla la letra del pulsador que se ha accionado.
Description of the code.
The block will use the start to show the text "Press a button" at the beginning.
micro:BIT does not display accented characters, so it will leave a gap if the accent is placed.
in the word button.
Subsequently, the event of pressing button A will be used and the blockshow will be introduced.
chain where the default text will be replaced by the letter "A".
This will be repeated when the B button is pressed and the combined press of A+B.
The code would be as follows:
Proposal.
Create a music box. When you press button A, it will play a melody. The block
Necessary to make a melody sound is found in the category Music.
Challenge 9. Measure the intensity of ambient light
Light sensors are used to detect the level of brightness and produce a signal of
representative output of the amount of light detected.
Sometimes it can be interesting to know the light level that exists in different
situations and thus be able to calibrate a device that depends on the value of the intensity
luminous, like a camera.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •20
micro:bit Programming Manual •Free online summary
MakeCode has the light level block in the Input category, which reads the light value.
applied on the LED screen. This value ranges from 0 (dark) to 255
(bright).
Objective.
Pressing the button A will display the numerical value of the light intensity
environment. By clicking on B, the light intensity will be graphically displayed. By clicking A and
B simultaneously, the screen will turn off.
Code description.
It is proposed to create three different programs, each of which will start according to the button or
combination of buttons pressed.
By pressing button A, the numerical value of the light intensity will be displayed. It will be used
the blockshow numberintroducing the blocklight levelas the value to present.
Pressing the B button will light up the necessary LEDs to graphically display the
value of the light level. The blockplot bar graph of ... up to ... located in the
LED section. First, the light level block is introduced and in the second term, it
replace the default value with 255, the maximum value detected by the light sensor.
To finish, the combined pressing of buttons A and B will be used to delete and turn off the
LED screen.
Proposal.
Create a code that allows turning on all the LEDs of the micro:BIT panel when pressing the
turn on with button A and turn them off by pressing button B, but it will not turn on if the light sensor value
is greater than 175.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •21
micro:bit Programming Manual •Free online summary
Challenge 10. Modify the brightness of the LEDs
Most mobile phones come with the ability to modify the
screen brightness, to adapt to ambient light.
Objective.
Design a program that allows modifying the brightness of the LEDs when the button is pressed.
The brightness will increase, if button B is pressed the brightness will decrease. If pressed
A+B the brightness will be at an intermediate value (128).
Description of the code.
To start the program, a variable will be defined that will be called 'brightness'. In the category
You can create a new variable or rename the default one.
An initial value of 128 will be set for the created variable.
It is proposed to use steps by a value of 32 units to show the change in brightness in the
LEDs, but any other value can be used.
Pressing button A will increase the variable 'brightness' by 32 steps. When pressing button B
the value of the variable 'brightness' is decreased by 32 steps. Finally, if both are pressed at the same time
keys A and B set the initial value of the variable "brightness".
Finally, it would be necessary to display an icon on the LED panel that shows the changes in the
brightness of the LEDs. The variable 'brightness' should be used as the value that the adjust block takes.
shine
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •22
micro:bit Programming Manual •Free online summary
Proposal.
It is proposed as a challenge to create code that automatically adjusts the brightness, to a greater
luminosity measured by the light sensor, highest brightness value of the LEDs.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 23
micro:bit Programming Manual • Free online summary
Accelerometer
The accelerometer measures the acceleration of your micro:bit. It activates when your board moves and
It can also detect other actions such as shaking, rotating, and even dropping your micro:bit in free fall.
free!
Challenge 11. Electronic dice.
A die is a cubic object used in gambling games. On the faces of the cube appear
points that represent different numbers.
It is proposed to create an electronic die that, using the LED panel, will show the result of
get a random number between 1 and 6.
Objective.
After shaking the micro:BIT, a random number must be calculated with a value between 1 and 6.
Subsequently, the obtained value will be displayed on the LED panel.
Code description.
As a kickoff event for the program, the agitated block will be used, a number will be displayed.
randomly chosen between 0 and 5, to which 1 will be added. 1 is added because the block chooses
at random, it has a fixed starting value of 0.
After a 1-second pause, the screen clears, waiting for it to return.
shake the micro:BIT.
Proposal.
Design a program that allows playing roulette; it should also indicate whether it is red or
black or if the bank wins.
Challenge 12. Heads or tails.
The heads or tails game is a game of chance that uses a coin. The person who wins is the one who
I guessed which side of the coin (of the two possible) will land heads up. Each of the two
sides have a distinctive name and are mentioned as options to be chosen by
the participants. Therefore, the participants can be two teams or two people and
Thus, each side has a 50% chance of being correct.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •24
micro:bit Programming Manual •Free online summary
This game is frequently used as a mechanism for making decisions or
to raffle, whether among friends or in an informal way, but it is also completely acceptable
under certain circumstances, for example at the start of a professional football match.
Objective.
The micro:BIT will be positioned with the LED panel facing down. When positioned upwards, it
it will show either heads or tails, with the winner being the one who chose the displayed option.
Code description.
First, a variable that can be called 'random' will be created.
It will be used as a start event the block if the screen is up. Next, it is assigned.
to the variable 'azar', a random value between 0 and 1.
Using the logical operator if then if not selected as an option it is the winner. It is assigned.
the happy face if the variable 'random' takes a value of zero and otherwise the cross will win.
The winning option will be displayed using the showblock icon.
After a one-second pause, the screen disappears.
To repeat the process, the micro:BIT must be placed with the panel facing down.
putting the panel back up will repeat the programmed code
.
To see how the program works, it is recommended to upload the code to a micro:BIT.
In the simulator, the process is not so intuitive.
Proposal.
Create a program that allows you to play 'Evens or Odds' against the micro:BIT
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •25
Micro:bit Programming Manual • Free online summary
Compass
The compass detects the Earth's magnetic field, allowing one to know which direction
the micro:bit is oriented. (It needs to be calibrated to ensure an accurate result.)
Challenge 13. Knowing the orientation
The magnetic north is the direction indicated by the magnetic needle of a compass.
that does not match that of the geographic North Pole. One can know the orientation if one
they know the degrees of deviation with respect to Magnetic North.
Objective.
After calibrating the compass, it will tell us the deviation in degrees from Magnetic North of the
micro:BIT.
Description of the code.
Use the event forever, to start the program.
Show the value of the compass direction sensor (º) that provides the angle of deviation
regarding the Magnetic North.
Wait 1 second and clear the screen.
Proposal.
When the compass points to magnetic north, an arrow should appear pointing towards
above. Otherwise, only the numerical value will appear.
Challenge 14. North orientation sound alert.
When you need to orient yourself with a map, the first thing to do is to locate the
map with north orientation. A compass should be used for it.
Objective.
Create a program that alerts with a sound that the micro:BIT is
oriented to the North.
Description of the code.
Usar el eventopara siempre, para iniciar el programa.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 26
micro:bit Programming Manual • Free online summary
Create a variable where the value of the sensor obtained by the direction block will be stored.
of the compass (°).
It introduces the conditional if then else to check in which interval it is located.
the value obtained by the sensor.
If the value is between 315º and 45º, the micro:BIT is oriented to the North, so
an N will be displayed and a note will be played. If the hypothesis is not fulfilled, it will be erased.
screen.
Proposal.
Create a code that locates the Magnetic North more accurately.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •27
micro:bit Programming Manual •Free online summary
Radio
The radio allows you to communicate your micro:bit with other micro:bits. For example, you can connect
all the cards within a classroom to the same broadcaster, use it to send messages between
them and much more!
Challenge 15. Wireless sensor.
En algunas situaciones se puede dar el caso de que no se pueda tener conectado el sensor
with the data receiving unit via cable. When this situation occurs, a
An option is to use wireless sensors.
Using wireless sensors offers numerous advantages. Among them, security stands out.
la centralización de la monitorización y el ahorro de costes por no tener que cablear la
installation.
A wireless sensor consists of the data collection system, a system of
data output and a power supply. The most common is that the transmission of
data either through radio frequency. On the other hand, there is a receiving system of
data connected to the storage and processing system.
Objective.
Design a wireless data collection system. The transmitting micro:BIT will be located in
the inside of a freezer and will emit the temperature. The outdoor unit will display the value of the
temperature.
Description of the code.
Two codes must be created, one for the transmitting micro:BIT and another for the receiving one.
For the cards to be able to communicate with each other, both must be in the same group
of communication. It should also be emitted at maximum power to avoid attenuation.
what the issuing card suffers when it is inside the refrigerator. For this reason, it should be
use the block radio to set transmission power located in the category Radio and use
the maximum value is 7. It is recommended to use the event to start to establish the group
of communication and assign the transmission power.
micro:BIT transmitter:
After setting the emission group to 1 and putting the emission power to the maximum, it
It will send the temperature value via the block radio send number.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •28
micro:bit Programming Manual •Free online summary
micro:BIT receiver:
The sent string is stored in the receiving micro:BIT in a variable that by default is
llama “receivedNumber”. Se usará el bloquemostrar número, para visualizar la temperatura
measure in the fridge. After a second, the LED panel will turn off. Don't forget to set to
start the communication group.
The code of the receiving card would be as follows:
Proposal.
It is proposed to display an animation on the transmitter micro:BIT panel that confirms that the
the program is underway.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •29
micro:bit Programming Manual • Free online summary
Input and output pins
The micro:BIT has 25 connectors located on the bottom edge. Through them, you can...
They will be able to program motors, LEDs, or any other external component or sensor.
Challenge 16. Is there continuity?
Sometimes it is important to know if a cable has continuity along its entire length.
To check continuity, a multimeter is commonly used to measure the resistance of
conductor. A reading of infinite resistance would indicate a break somewhere in the conductor.
interior of the cable.
Objective.
Design a program that allows you to check if a cable is continuous. If it is not
cut, show a happy face.
Description of the code.
The block pin (P0) will be used pressed from the category Entry to check the
continuity. It is proposed to use the event forever and use a conditional that checks
if P0 is pressed. If the condition is met, a happy face is displayed, in case
On the contrary, the panel remains off. The code could look like this:
To check the operation, a cable with banana plugs connected to the
GND, if it connects with the P0 and the wire has continuity, a happy face should appear.
on the LED panel.
Proposal.
Modify the code so that when the cable to be checked has continuity, it makes a sound.
melody 'jump up' and if it does not have continuity, the melody 'jump down' should be played.
Challenge 17. Moving a servo motor
A servomotor (also called a servo) is a device similar to a direct current motor.
continues that has the ability to position itself anywhere within its range of
operation, and to remain stable in that position.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •30
micro:bit Programming Manual •Free online summary
Objective.
Design a program that when pressing button A, the servo positions to 180º, if the
Button B should be located at 0º and by pressing A+B simultaneously it will be positioned at 90º.
Description of the code.
The block that writes to servo pin (P0) to (180) which serves to position the servo is found
located in the Pins category, which appears when clicking on the Advanced section of the menu
principal.
You can choose which pin the servo connects to and at what angle the arm is positioned.
servo. The block will be used by pressing the button, to start the different programs
according to the pressed button.
The program will be as follows:
The simulator shows the image of a servo and will perform as programmed according to the button.
driven.
Proposal.
Create a code that allows the servo to move in 15º steps when pressing the A button and returns.
the arm at 0° when pressing button B.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •31
micro:bit Programming Manual • Free online summary
~ Author's biography ~
José Francisco Muñoz Fernández (Almería, 1968). Senior architect, since he fell into
his hands a computer was fascinated by this digital science. Technology catalyzed his
innate investigative and innovative spirit and led him to integrate it into all facets of his life
educational and labor.
After years of working as an architect, he decides to give more prominence to his other two.
passions, technology, and education, starting to work as a robotics teacher.
This teaching experience allows him to verify the great potential that robotics has in
the classrooms and pushes him to want to help other teachers in the quick implementation and
effective educational robotics in their centers.
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •32
Micro:bit Programming Manual •Free online summary
~ Other books by the author ~
Introduction to Educational Robotics with mBot by Makeblock
Available for purchase at:
[Link]
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) • 33
micro:bit Programming Manual • Free online summary
You may also be interested in
50 Projects with micro:bit
Ernesto Martínez de Carvajal Hedrich • First Edition (2018) • 229 color pages
Available for purchase at:
[Link]
José Francisco Muñoz ([Link]) • [Link] (micro:bit community in Spain) •34