Makecode Tutorial
Makecode Tutorial
1
Table of contents
1.What's in the package? ............................................................3
2
1.What's in the package?
1 Expansion Board 1
2 Acrylic Board 1
3 Ultrasonic Sensor 1
4 Universal Wheel 1
5 Wheels 2
3
10 M3 Nickle-plated Nuts 2
11 Slotted Screwdriver 1
12 Cross Screwdriver 1
13 IR Remote Control 1
4
2.Getting started with micro:bit
2.1 Introduction
Hardware
Software
5
2.2 Meet The Micro:bit
6
The following content is borrowed from Kitronik University micro:bit
resources and guides.
The table below lists all of the features for both boards for much easier
comparison, new or improved features are highlighted in green.
7
The new micro:bit speaker works the same as it does when you currently
connect a speaker to the micro:bit and the sound output will be on both
the speaker and the edge connector. The new microphone blocks in the
MakeCode editor will allow you to write code that reacts to sound.
Much of the onboard tech has also been enhanced. The processor and
memory has been upgraded which has also allowed upgrades to other
on-board technologies.
8
The table below lists key technical specifications for both boards for much
easier comparison, new or improved features are highlighted in green.
9
Coding and MakeCode Compatibility:
Users will not need to select which version of the device they have
before using MakeCode or the Python Editor.
Every program that could run on a micro:bit version 1 can be re-built to
run on micro:bit V2.
The editors will support both versions simultaneously for features
common to both boards.
To convert an old HEX file into a universal HEX file, drag it into the editor
it was created in and then export it back to your computer where it can
be dragged and dropped onto the micro:bit. If you attempt to use an
old .Hex file without updating it, the micro:bit will display a compatibility
error.
In this step you will take a tour of the MakeCode editor, and create your
first program for the micro:bit.
10
Create a new project
Now you are presented with the MakeCode editor, this is the screen you
will use to program your micro:bit.
Below is a quick reminder of the different parts of the editor, to help you
better understand the interface.
11
Sign in --- Sign in to save your progress and access your work anytime,
1
anywhere.
Blocks/JavaScript/Python --- Choose your own adventure by
programming in blocks (default) or in JavaScript. Not shown in the image,
2
Microsoft also eventually added an additional option to use convert the
code to MicroPython.
Share --- Allows you to share your project code in a number of different
3
ways with your friends!
Program Space --- This is where the magic happens and where you build
4
your program...where you "make code."
Zoom/Undo-Redo --- Sometimes you need to undo things, or zoom out
5
and look around; these are the buttons for that.
Name & Save --- Name your program and save it (download it) to your
6 computer as a .hex file. You can drag this file to your micro:bit using your
computer's file explorer.
Download --- Transfer the code directly to your micro:bit using webUSB.
7 Or similar to Save, download your program as a .hex file and drag it into
your micro:bit.
Block Library --- The toolbox is where you get the blocks that make up
8
your program. It is split into categories that are colour coded.
Simulator --- You don't need hardware! MakeCode has a real-time
9 simulator! As you change your program, you can see what it will do on
this virtual micro:bit!
12
Creating your heartbeat program
In the code area, there are two fixed blocks “on start” and “forever”.
The code in the “on start” block will be executed only once after
power-on or reset, while the code in “forever” block will be executed
circularly.
You can also right-click on start and click Delete block to remove it.
13
Click the Basic menu in the Toolbox. Grab a show icon block.
Place the show icon inside the forever block in the program space.
The blocks will fit together like puzzle pieces.
The simulator will immediately run your program, you will see the heart
pattern displayed on the LEDs.
14
Click on the heart icon at the end of the show icon block. You will see a
drop down, with all the available pre-made icons.
Click Basic again and drag the show icon block to place it underneath the
show icon block you just created.
Or you can right click the show icon and click Duplicate, the same show
icon block will appear in the program space.
Choose a smaller heart from drop down.
15
You should notice that when you make a change to your code, the
simulator restarts.
The simulator will display a beating heart.
In the next step you will learn how to download your program onto your
physical micro:bit.
It covers:
Transferring a program from MakeCode or the micro:bit Python Editor
from a computer
from an Apple device (iPad or iPhone)
from an Android device
Transferring a program that has been downloaded as a file
16
2.31 Method 1: Flashing the Micro:bit with WebUSB
WebUSB
The first time you pair your micro:bit with your computer you’ll need to go
through a few easy steps to get setup. Here’s how to get paired with
WebUSB:
17
Click Next
Click Pair and select the micro:bit device and click Connect.
Note: If your micro:bit isn’t showing up, try unplugging it and plugging it
back in. You can also try a different USB port or USB cable if they are
available.
You will see another box telling you the pairing was successful. Your
micro:bit is connected!
18
Once your micro:bit is paired, MakeCode will use WebUSB to transfer
the code directly and you won’t have to drag and drop .hex files from a
folder. Just click the Download button in the editor and your project code
will just transfer to the micro:bit.
The yellow light on the back of the micro:it will flash really fast to let you
know the program is transferring, then your program will start
automatically.
This method does not save a version of your code to your local
machine, if you wish to keep a copy of the program you have written, click
the save icon (looks like a floppy disk and is located next to your project
name in the MakeCode Editor) to save a copy of the hex file to your local
machine.
19
This will download your program file to your standard download
location, probably the Downloads folder on your computer, or whatever
location you have set in your download preference. You can copy or move
it somewhere safe if you need to keep it to reload into the editor.
Using Safari/Firefox/Other
Note: If you are using any browser other than Chrome or Edge. It may not
support WebUSB so you can't pair your micro:bit with your computer.
Every time you click on the 'Download' button, your program won’t
transfer directly to your micro:bit, your code will be downloaded as
a .hexfile. Just like click the save icon to save a copy of the hex file to your
computer.You can drag this file to your micro:bit using your computer's file
explorer.
Next step, we will learn how to transfer a program that has been
downloaded as a hex file.
20
2.32 Method 2: Transfer a program that has been downloaded as
a hex file
Find the downloaded program hex file (e.g. in your local downloads
folder) and drag and drop this on to the micro:bit drive.
21
The yellow light on the back of the micro:it will flash really fast to let
you know the program is transferring. Once the transfer is completed then
your program will start automatically.
After you transfer your .hex file, the micro:bit drive will disconnect
and reconnect as the micro:bit resets. If you look at the contents of the
micro:bit drive, you will not see the .hex file listed, this is normal, but
will be gone. T
Note: In the lessons we offered, the micro:bit can only receive hex files
and won't store anything else!
22
2.4 Import Files from Your Computer with the Makecode.
Steps:
2. There are two ways to import or update a saved hex file in the
Makecode editor.
Drag the HEX file from your computer into the home page or edit
window.
Note: The micro:bit can only run one program at a time - every time you drag-and-drop a hex file onto
the device over USB it will erase the current program and replace it with the new one.
23
Click “Import” button on the right side of HOME page.
24
2.5 Micro:bit Project
2.50 Prepare:
Make sure you have downloaded the files we provided that are required
to run the robot car.
Link to download:
https://fs.keyestudio.com/KS4036F
Or
https://drive.google.com/drive/folders/15Q2MOlBwgK1TR33pF1ov43Ush
MNH-_jy?usp=sharing
Download the tutorial package and save it in the folder you want, and
unzip it to use.
25
2.51 LED Matrix
There are 25 LEDs on the front face that you can use to show pictures,
numbers, and words.
The upper left corner is (0,0) point, the lower right corner is (4,4) point,
the horizontal direction (from left to right) is the x-axis direction,
increasing in sequence [0-4], and the vertical direction (from top to
bottom) is y-axis direction, increasing in sequence [0-4].
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-LED-Matrix-1.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
-Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-LED-Matrix-1
26
Result:LEDs at coordinates (1,0) and coordinates (3,4) of the micro:bit will
flash alternately.
"Hello!"
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-LED-Matrix-2.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-LED-Matrix-2
27
2.52 Programmable Buttons, A & B
Buttons are a very common input device. All micro:bit have two buttons
you can program, and a reset button. The programmable buttons, A & B
can trigger pieces of code in your programs.
We will make buttons A,B of the micro:bit work with the LED
matrix.
→Press button A, the LED matrix displays A
→Press button B, the LED matrix displays B
→Press button AB at the same time, the LED matrix displays AB
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Buttons-1.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Buttons-1
28
Now let's send another code to micro:bit to realize the following
function:
→When you press button A, the LED matrix is lit with more LEDs
upwards, and when you press button B, LEDs of the mircrobit turn off
downward.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Buttons-2.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Buttons-2
29
2.53 Temperature Sensor
The micro:bit does not actually have a temperature sensor. It uses the
temperature sensor built into the NFR51822 chip for temperature
detection. Therefore, the detected temperature is closer to the
temperature of the chip and may have a certain error with the ambient
temperature.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Temperature-Sensor-1.hex file, drag it in
the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Temperature-Sensor-1
The "Show Data Device" button will appear below the simulator
If you press the Show data button, the editor will switch from the
30
Blocks or JavaScript view to display a charting window and a text console.
The Data view window will display the temperature value read by the
temperature sensor in the micro:bit's processor chip.
Return: The Go back button switches the view back to previous code
window (either Blocks or JavaScript).
Source: Tells you where the data is coming from. If the code writing the
data is running in the simulator, then the source is Simulator. If your code
is running on the micro:bit and connected by USB, the source is Device.
Pause: The pause button will stop the display of new values and stop
scrolling. When you resume, the chart starts again with the current value
written.
Resume: The resume button will start displaying new values after
the Pause button was pressed.
31
Download: The download button collects the data your code has written and
downloads it to your computer as a file called something
like data-11-2018-23-00-0700.csv. The numbers in the filename are the date
and time when the file is created. The file may automatically open in an editor
or spreadsheet if one of those programs is associated with csv files.
32
2.54 Magnetometer
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Magnetometer-1.hex file, drag it in
the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Magnetometer-1
33
Keep tilting the micro:bit in all directions until all LEDs are lit, and a
smiley face appears indicating calibration is complete!
Test Result: Each time you press button A, position value read by
the compass will be displayed on the LED matrix. Change the orientation
of the micro:bit and you will notice that the position value changes
accordingly.
34
Here, we will download a new code to make the arrow on the LED
matrix of the micro:bit always point to the north.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Magnetometer-2.hex file, drag it in
the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Magnetometer-2
35
Test Result: Place the micro:bit's LED matrix horizontally facing up
and change its orientation horizontally, you will find that no matter how
you change its orientation, the arrow displayed by its LED matrix points in
the same direction. If you have a compass app on your phone, turn the
compass app on, hold your micro:bit horizontally in the same direction as
your phone and you will see that the arrow of the micro:bit is pointing at
North9(0 degree).
36
2.55 Accelerometer
If you imagine the micro:bit sitting flat on a desk, the x dimension is left to
right; the y dimension front to back and the z dimension into and out of
the desk. We can use an accelerometer to detect the orientation of the
micro:bit, since gravity will always be acting in the same downwards
direction.
When the micro:bit is lying flat on a surface with the screen pointing up,
-x is 0,
-y is 0,
-z is -1023,
-and strength is 1023.
37
In this step we will use the Data View Window to display the values
of the x, y, and z axes detected by accelerometer.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Accelerometer-1.hex file, drag it in
the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Accelerometer-1
Click the "Show Data Device" under the simulator
You will see the values of the X, Y, and Z axes detected by the
accelerometer in the Data View Window.
38
Now let us upload new code so that when the accelerometer detects
the posture of the micro:bit change, the micro:bit will display the
corresponding number on the LED matrix.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Accelerometer-2.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Accelerometer-2
Test result:
Find the light level (how bright or dark it is) where you are. The light level
0 means darkness and 255 means bright light. The micro:bit measures the
light around it by using some of the LEDs on the LED screen.
The first time you use it, this function will say 0. After that, it will say the
real light level. This is because the light sensor (the part that can find the
light level) has to be turned on first.
In this step we will use the Data View Window to display the values
of the light intensity detected by light level sensor.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Light-Level-Sensor.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Light-Level-Sensor
Click the "Show Data Device" under the simulator
You will see the values of light intensity in the Data View Window.
40
2.57 Speaker (V2 only)
The micro:bit can make sounds, play tunes and the new micro:bit has a
built-in speaker to make it even easier to make expressive and useful
projects.
Any micro:bit sound project will work with the speaker, but with the new
micro:bit you can also express yourself with some new sounds: make your
micro:bit giggle, greet you or let you know when it's sleepy or sad.
You can also mute the speaker and sound will still come out of the pins so
you can still enjoy micro:bit music on headphones connected to GND and
pin 0. In MakeCode, use the music block 'set on-board speaker off'.
Result: the speaker of the micro:bit makes interesting sounds and the
LED dot matrix displays the music logo pattern.
41
2.58 Logo Touch (V2 only)
The gold logo is a touch sensor that works a bit like a touch screen on a
mobile phone, measuring tiny changes in electricity. This is also called a
capacitive touch sensor, because it uses measurements of electrical
capacitance to work.
Light up your micro:bit with a heart - but only while you touch it!
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Logo-Touch. hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Logo-Touch
Result: Show a ‘❤’ icon on the LEDs while the logo is pressed. When
you release your finger from the "Logo" mark, number will appear.
42
2.59 Microphone (V2 only)
The new micro:bit with sound has a built-in microphone sensor. It can
react to loud and quiet sounds, and also measure how loud your
environment is.
The microphone is on the back of the new micro:bit, and on the front
you'll find a new microphone LED next to the hole that lets the sound in. It
lights up to show you when your micro:bit is measuring sound levels.
We will make the LED matrix of micro:bit display a large heart when
the microphone detects sound, and a small heart when the surroundings
are quiet.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Microphone-1.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Microphone-1
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded micro:bit-Microphone-2.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code micro:bit-Microphone-2
Result: After the code is downloaded, You'll notice that the louder the
sound around the micro:bit, the more LEDs will light up, from bottom to top.
44
3. Introduction to the Mini Robot Car
In addition, it leaves lot of universal jacks of building block holes for easy
connection to other peripheral devices, you can use your experience and
imagination to create more interesting inventions.
3.1 Hardware
Note: the two colored headlights, two photosensitive sensors, the IR receiver and
two motors are already integrated in the car baseplate.
45
3.2 Parameters
46
3.4 Adding Extension for the Robot Project
Extensions are functional code modules that are installed from outside the
MakeCode editor and plug new blocks into the Toolbox. If you have used
Arduino before, you probably know about a thing called a library; which is
a collection of code that extends the functionality of the core
programming language. MakeCode extensions work the same way.
Drag the hex files we provided into the Makecode editor or use the
"Import" button to open the hex files we provided. You can see two
additional extensions in the Toolbox list, which are already included in our
code.
That is to say, if you use the hex file we provided, you do not need to add
these extensions to the Makecode editor.
Note:
1. If you want to drag and drop blocks to Create a New Project to control
this robot car, you will need to add the extension we provide to use new
blocks to complete the code.
2. For every new MakeCode project that you make, you will have to load
extensions over again.
47
How to add an extension
This will open a window giving you a place to search for extensions. Also, a
selection of recommended extensions is shown for you to choose from.
Copy and paste the following link into the search box and press the
"Enter" to search.
https://github.com/keyestudio2019/MiniCar
48
After the extension is added, you should see the Mini Car, and IrRemote
extension category appear in the Toolbox. The extension will contain the
new blocks, ready for you to use in the project’s code.
49
2.Find the Explorer button below the simulator
50
3.5 Assemble the Robot Car
Before assembly, please tear off the protective film on the acrylic boards.
Couple the protruding end of the wheel with the motor shaft
51
2.Install acrylic board and battery case
52
53
54
55
56
3.Install the universal wheel
57
4.Install the ultrasonic module and the micro:bit
58
Micro:bit’s LED matrix faces forward
59
3.6 Robot Project
1. To avoid poor contact between micro:bit and robot, please make sure
that the Microbit is correctly inserted into the Microbit interface of the car
body. The connector need to cover the edge of the Microbit round hole.
The LED matrix of the micro:bit facing forward.
2. Put AAA batteries into the battery case and connect the case to the
VCC connector of the car base.
3. Turn off the slide switch that controls the power from the batteries.
60
3.61 RGB Headlights
Let’s light up the two RGB headlights of the robot car and make it
flash every second in the order of red, green, blue, cyan, oxblood red,
yellow and white.
Steps:
Connect the micro:bit on the robot car to your computer with a USB
cable.
Find the downloaded RGB-Headlights.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code RGB-Headlights
61
Result: After downloading the code, the RGB headlights of the robot car
will switch every second in the order of red, green, blue, cyan, oxblood red,
yellow and white. If you disconnect the microbit's USB power supply, you can
turn on the power slide switch of the robot car and power it from the
batteries.
Schematic Diagram
STC8G1K08 through the IIC, then the slave outputs PWM to control RGB LED
lights. This greatly saves the IO ports of the microbit board, for the IIC enables
62
3.62 Control the Motors
The robot car is equipped with two DC geared motors, which are
developed on the ordinary DC motors. It enjoys a matching gear reduction
box, which provides a lower speed but a larger torque. Furthermore,
different reduction ratios of the box can provide different speeds and
torques.
The reduction motor is the integration of gearmotor and motor, which is
applied widely in steel and machine industry.
Circuit Diagram
63
Let's download a new code to make the robot car go forward for 1s,
backward for 1s, turn left for 1s, turn right for 1s and stop for 1s.
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn off the POWER Slide switch on the robot car base to prevent it
from moving and falling off the table after the code download is complete.
Find the downloaded Control-the-Motors.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code Control-the-Motors
64
3.63 Photoresistor
65
When the light intensity increases, the resistance decreases, and the
voltage of the analog port rises, that is, the analog value of the
microcontroller goes up. Otherwise, when the light intensity decreases,
the resistance increases, and the voltage of the analog port declines, that
is, the analog value of the microcontroller becomes smaller. Therefore, we
can use the photoresistor to read the corresponding analog value and
sense the light intensity in the environment.
It is commonly applied to light measurement, control and conversion, light
control circuit as well.
Now let's use Data View Window of the Makecode to display the light
value detected by the photoresistor
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded Photoresistor.hex file, drag it in the Makecode
to view and analyze, and use WebUSB to flash it to the micro:bit from
inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code Photoresistor
Result: After the code is downloaded, click the "Show data Device"
button and the Data View Window will display the value detected by the
left and right photosensitive sensors.
66
3.64 Light Following Robot Car
In this Step, we are going to guide you to make an Microbit Light Following
Robot Car.
67
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn off the POWER Slide switch on the car base to prevent the robot
from moving and falling from the table after the code is downloaded
successfully.
Find the downloaded Light-Following-Robot-Car.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code Light-Following-Robot-Car
68
3.65 The Line Tracking Sensor
The car base board of Keyestudio micro:bit Mini Robot Car V2.0 contains
two line tracking sensor module, and it also integrates two
potentiometers on the top to allow you to adjust the sensitivity of the line
tracking sensor.
The line tracking sensor is an infrared sensor that uses the TCRT5000
infrared tube. The TCRT5000 Infrared sensor mainly includes an IR Tx
(transmitter) & and IR Rx (receiver), the IR Tx generates an infrared signal
continuously then reflects through an obstacle and is detected through
the IR receiver.
69
In this step, we will display the digital value detected by the line
traking sensor in the Data View Window.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded The-Line-Tracking-Sensor.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code The-Line-Tracking-Sensor
Result: You can use a black and white object or hold your finger close
to the sensor. Click the "Show data Device" button and the simulator will
display the digital value detected by each sensor.
70
3.66 Line Tracking Robot Car
Steps:
Result:
After the code is downloaded, place the robot on the paper and align
the line tracking sensor with the black line.
Turn on the power switch on the car base, the robot car will move
following the black line.
71
Note:
Avoid performing this experiment in strong sunlight. Sunlight contains a
large amount of invisible light, such as infrared rays and ultraviolet rays,
which will affect the work of the line tracking sensor.
72
3.67 Ultrasonic Sensor
Let’s look at the picture of the ultrasonic sensor module. There are two
things like eyes, one is the signal transmitter (TRIG) and the other is the
signal receiver (ECHO).
working principle:
(1) We first pull TRIG (T) low, and then give at least 10us of high-level
signal to trigger;
(2) After triggering, the module will automatically transmit 8 40KHZ
square waves and automatically detect whether there is a signal return;
(3) If a signal returns, a high level is output through ECHO (E). The duration
of the high level is the time from transmission to reception of the
ultrasonic wave. Then the test distance = the duration of high level *
340m/s * 0.5.
73
Specifications:
Now, let's use the ultrasonic sensor to measure the distance of an object
in front of the robot.
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn on the POWER Slide switch on the car base
Find the downloaded Ultrasonic-Sensor.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code Ultrasonic-Sensor
Result: Click the "Show data Device" button under the simulator. The
distance of the object in front measured by the ultrasonic sensor will be
displayed in the Data View Window.
74
3.68 Obstacle Avoidance Robot Car
working principle:
75
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn off the POWER Slide switch to prevent the robot from moving
and falling from the table after the code is downloaded successfully.
Find the downloaded Obstacle-Avoidance-Robot-Car.hex file, drag it
in the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code Obstacle-Avoidance-Robot-Car
Result: Place the robot on the ground and turn on the power switch
on the car base, the robot car will will move forward and avoid obstacles.
76
3.69 Obstacle Following Robot Car
Working principle:
77
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn off the POWER Slide switch on the car base to prevent the robot
from moving and falling from the table after the code is downloaded
successfully.
Find the downloaded Obstacle-Following-Robot-Car.hex file, drag it in
the Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code Obstacle-Following-Robot-Car
Result: Place the robot on the ground and turn on the power switch
on the car base, place your phone or palm in front of the ultrasound and
the robot will follow it.
78
3.70 IR Remote Control
Infrared remote controls are used to control various home appliances such
as televisions, stereos, video recorders, and satellite receivers. The
infrared remote control is composed of an infrared remote control, an
infrared receiver module, and a microcontroller that can decode.
When a button on the remote control is pressed, the remote control sends
out an infrared carrier signal. When the infrared receiver receives the
signal, the program decodes the carrier signal and determines which
button is pressed based on the difference in data code. The
microcontroller decodes the received 0 and 1 signals to determine which
key is pressed on the remote control.
The infrared receiving module is integrated into the car base and is
controlled by the P16 of micro:bit.
79
In this step, we will use View Data Window to display the key values
sent from the infrared remote control.
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded IR-Remote-Control.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code IR-Remote-Control
Result:
1.Click the "Show data Device" button under the simulator.
2.Pull out the plastic insulation film from the infrared remote control.
80
3.71 IR Remote Control Robot Car
Working principle:
81
Steps:
Connect your micro:bit to your computer with a USB cable.
Turn on the POWER Slide switch on the car base.
Find the downloaded IR-Remote-Control-Robot.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
Or you can right-click on it and choose "Send to→micro:bit."
File Type Path File Name
hex file .../Makecode/Makecode Code IR-Remote-Control-Robot-Car
82
3.72 Install Bluetooth APP and Read Bluetooth Data
Steps:
Connect your micro:bit to your computer with a USB cable.
Find the downloaded Read-Bluetooth-Data.hex file, drag it in the
Makecode to view and analyze, and use WebUSB to flash it to the
micro:bit from inside editor.
File Type Path File Name
hex file .../Makecode/Makecode Code Read-Bluetooth-Data
Next we will need to download the Bluetooth App for our phone and
connect it to the micro:bit.
83
Download APP and connect the bluetooth:
2.Search keyes mini car in the Apple Store and click download.
84
4.Click Settings, scroll through the list and find mini car. Click it and allow mini
car APP to access Bluetooth.
6.Click the CONNECT button in the upper left corner of the APP
homepage.
85
7. After clicking the CONNECT button, a Bluetooth list will pop up, scroll
through the list and find BBC Micro:bit, click on the Connect.
7. If after clicking the CONNECT button, the pop-up page is blank and
shows that Bluetooth not turned on, please exit the APP and restart it and
try again.
You also need to make sure you have completed the following steps.
1).Code has been downloaded to the micro:bit
2).The battery power is sufficient and the power switch on the car base
has been turned on.
4).Turn on the Bluetooth and location services on phone.
5).Allow the mini car APP to access Bluetooth.
86
For Android system device
The APP file is provided in our tutorial package, you can also transfer it to your
phone and install it.
2. Click INSTALL
A security warning pop-up will appear. We guarantee that the APP is safe,
please use it with confidence.
-Select l understand that this app hasn't been tested and may pose a risk
87
4.Click Settings of the mobile phone, and turn on the Bluetooth.
Click Privacy, and turn on the location services.
1. Find the keyes bit car Bluetooth app, click on the permission options of the app,
and enable Location and nearby device permissions.(Note: Some mobile phones do
not have nearby device permissions function.)
88
7.Click to open keyes bit car APP.
8.Click the CONNECT button in the upper left corner of the APP
homepage.
9.After clicking the CONNECT button, a Bluetooth list will pop up, scroll
through the list and find BBC Micro:bit, click on the Connect. After "is
connected" is displayed, click on the blank space outside the pop-up box
to return to the APP main interface.
89
After downloading the code to the Microbit and connecting
Bluetooth to the phone.
Click the "Show Data Device" under the simulator on Makecode
Editor.
Click the button on the Bluetooth APP, the Data View Window will display
its corresponding letter value, and "S" will be displayed when releasing a
button.
90
3.73 Multi-purpose Smart Car
In the previous chapter, we learned how to install and use Bluetooth APP.
In this step, we will use Bluetooth APP to control the mini robot car.
Steps:
Result:
Place the robot on the ground and turn on the power switch on the
car base, connect the Bluetooth APP to the micro:bit, then you can use
the Bluetooth APP to control the robot.
91
The following are the functions corresponding to the buttons on the
Bluetooth APP interface.
92
1. Ultrasonic obstacle
avoidance
2. Ultrasonic following
3. Line tracking
4. Light following
It is used to control
the music.
93