M Bot Class Work Book
M Bot Class Work Book
COMPUTER LITERACY
mBot programming
Workbook
Name: ________________________
Class: ________________________
Number: ________________________
Table of Contents
LESSON 1 ........................................................................................................................................... 3
LESSON 2 ........................................................................................................................................... 7
LESSON 3 ......................................................................................................................................... 10
LESSON 4 ......................................................................................................................................... 15
LESSON 5 ......................................................................................................................................... 18
LESSON 6 ......................................................................................................................................... 19
LESSON 7 ......................................................................................................................................... 20
LESSON 8 ......................................................................................................................................... 24
LESSON 9 ......................................................................................................................................... 25
LESSON 1
Before doing the following test, make sure you choose the right COM port in the mBlock
program (different computer may show different COM port for the mBot) after connecting
with a USB cable.
If there is no problem, you should see the status indicator turns green.
3
Wiring
4
Testing
Make sure you have connected the mBot by USB cable and have switched on the mBot.
How to turn off the blue light on the module when the infra-red sensors facing downwards?
Can you see the LED lights change colour when you press different key? YES/NO
Test 3 (Buzzer)
Can you hear sound when you press the SPACE bar? YES/NO
5
Test 4 (Ultrasonic sensor)
Can you see the reading change when you move your hand in front of the ultrasonic sensor?
YES/NO
Test 5 (Motors)
Can the remote controller turn on and off the LED on board? YES/NO
6
LESSON 2
The mBot motherboard is equipped with two LEDs. Each LED consists of a red light, a green
light and a blue light.
Try
The intensity of each colour light is represented by a number which ranges from 0 to 255.
Different colours can be generated by adjusting the intensity of each colour light.
7
Task 1
Questions:
How to flash red light first, then green and finally blue?
Task 2
8
Task 3
You will see the light will turn red on and off gradually.
Questions
What is the problem when changing the number from -5 to -2? How to correct the
problem?
9
LESSON 3
We can let the mBot to make sound by using play tone block which is under robot category.
Please don’t mix up with the play note block under sound category.
The play tone command can control the tone and the beat played by the mBot.
10
Task 1
11
Notice that we can’t choose C4# tone from the play tone command. We have to input the
corresponding frequency number. Similarly, we can input the duration (in milliseconds) inside
the beat part.
For example, if we want the mBot emit the F#4 tone with duration 0.75s, we add the following:
12
Task 2
13
OR
14
LESSON 4
Task 1
Step 1: Start a new file and create two backdrops (one backdrop indicates afternoon while
the other indicates the night).
15
Task 2
Step 2: Add a variable light to store the current reading of the light sensor on board. The
script should put inside the default sprite.
16
Step 3: Add the following script into the script area of the backdrop.
Normal Dark
Brightness 0 -100
Sensor value (0-1023) 1023 0
17
LESSON 5
Task 1: Write a program for mBot such that it starts to move 30cm forward after pressing
the button on board.
Does your mBot move 30cm forward after pressing the button on board? If no, what need to
be modified?
Note: You have to choose the COM port every time after you detach the USB cable.
18
LESSON 6
Task 1: Write a program for mBot such that it moves forwards along a square (side = 30cm)
after pressing the button on board. The mBot should stop at the same starting point
and facing the same direction.
Task 3: Write a program for mBot to move forward when the light sensor is covered by your
hand.
19
LESSON 7
Note: If you experience problem when testing your mBot, you may first clear the installed
program by updating the firmware.
To obtain the reading of the ultrasonic sensor, we may use a “say” block. Which of the
following program segment will be used? Why?
Task 1
You will hear the beat sound when there is an object in front.
20
If we want the faster tone indicating that the distance is closer, which of the following program
will be used?
Program 1
Program 2
By using a ruler, compare the reading output with the actual distance measured, is the reading
accurate? If not, how to output an accurate reading?
21
Task 2
Use a ruler and the program below to record the reading output.
? cm
Try 2 10
Try 3 15
Try 4 20
Try 5 25
Try 6 30
22
Example
Choose a suitable scale factor. For example, you may take the average of the scale factors
obtained. In the example, we may choose 1.30 as the scale factor.
Modify the program and compare again the actual distance and the reading.
23
LESSON 8
24
LESSON 9
Task 1: Write a program for mBot such that it starts to move forward the box after pressing
the button on board and stop exactly at 5cm in front of the box.
5 cm
If not, why? Try to build your own program. What will happen if you remove the
box?
Task 2: Write a program for mBot such that it will run automatically in the lane and detect if
there is a roadblock along the way. (p.46-48 in the textbook)
Task 3: Write a program for mBot such that it will run automatically in the lane and reverse
if there is a roadblock along the way. (p.49-51 in the textbook)
25
26