Bluetooth diagram mBot Bluetooth module (Obverse)
mBot Bluetooth module (Front)
Install the Bluetooth module
Please position the pin well and the module is easily installed. If the position is not placed right, you
will not be able to install it.
Chapter 11 Bluetooth Communications Application 201
Status of Bluetooth module light
1. Blue light flashing: means it’s waiting for a connection.
2. Blue light is on: Bluetooth is connected.
Connects to a computer
A USB cable is used to establish the connection between the mBot’s mainboard and the computer.
Shown in the diagram below.
Note The position of the serial port will vary with each computer.
202 Scratch (mBlock) Program Design — Using mBot Robot
11-2
mBlock Communications Component
When we use the communication component to obtain the value received by the Bluetooth, you
must use the argument of function to receive it. This is because the type of mBlock variables that can be
made is a Double, whereas String is used to receive the value of the Bluetooth. Therefore you must set
up a function to obtain this value. This will be explained at the later part of the program.
Communications Component
Please start the mBlock software. mBot’s Bluetooth communications component is at the bottom of
the program’s communication component area.
Only four elements in the communications components will be used, together with the control and
computing components.
Block Components Description
Check to see if any data is being transmitted.
When data is being transmitted, use this component to receive the data
content. Normally, this component is assigned to a variable.
Used to determine whether the received Bluetooth data is equal to a
character.
Such as A, B, C. After receiving A, the wheel goes forward.
Used to transfer the String data content to the mobile phone.
Mobile phone will then use the App to use it.
Chapter 11 Bluetooth Communications Application 203
11-3
Pairing mBot Bluetooth and Phone
After understanding the basic introduction of the mBlock communications component, if we want
to use an Android mobile phone to transmit data with an MBot, both devices must be paired with each
other to enable communications via Bluetooth.
Mobile phone is paired with mBot Bluetooth Select Makeblock
Select Bluetooth
Bluetooth pairing Bluetooth pairing successful
Description
When the phone is paired with or connected to a Bluetooth device, the PC cannot be connected
to the mBot.
204 Scratch (mBlock) Program Design — Using mBot Robot
11-4
Mutual Transmission between mBot and Phone
If the mobile phone and Bluetooth is paired successfully in the previous unit, we can now use the
mobile phone and mBot to send characters to each other.
Implementation
Please use the App to enter a character such as “A”, mBot will send it back to the mobile phone after
receiving it.
Mobile phone screen Screen of mobile phone connected to mBot
App program on disc ch11 \ ch11_Ex1.apk
App Screen
Description
After pressing the “button to connect mBot”, please select the Bluetooth device as shown
above. Enter one character in the input field, and press the button, “Send character to mBot”.
mBot will then return the character to the mobile phone.
Note The IP address of a Bluetooth module on each mBot will be different.
Chapter 11 Bluetooth Communications Application 205
mBlock program code Ch11-ex1 mobile phone and mBot exchanging characters
file
01
02
03
04
05
Description
Line 01: Loop, so that the program will implement the loop in the program continuously.
Line 02: Detect whether there is any Bluetooth data transmission.
Line 03: Call the self-established BT Receive ( ) function, and the Bluetooth characters will be
received into the function.
Line 04: Transmit the received characters back to the mobile phone.
Line 05: Line 02 ~ 03 will be implemented every 1 second.
Program upload
When you want to communicate with an mBot Bluetooth using your mobile phone, it is not like the
mBot main program component area, where you just have to click on it and the mBot will implement
it. Instead you have to press the “upload to Anduino” button and use the updating method.
206 Scratch (mBlock) Program Design — Using mBot Robot
The procedure is as follows: Step 2
Step 1
Description
1. In the “mBot program”, right-click and select Upload Arduino program.
2. Press the “Upload to Arduino” button again.
After burning is completed, you must release the mBot port or the mobile phone Bluetooth is
unable to connect to the mBot. As shown in the diagram below, Select Connect -> Serial Port COM4
released with a click of the mouse. (Or re-start the mBot).
For the mobile phone and mBot Bluetooth to connect, please remember that the pairing has to be
first successful before you can use the mobile phone App to connect. If you have never used the mobile
phone Bluetooth before, you will have to first try several times. mBot Bluetooth wireless transmission
program code is simple; it can only receive and send out. Just by pulling out the Block component, it
will automatically generate the corresponding C Language program code. But the drawback with mBot
communications component is that it is unable to convert the accepted characters into numerals. This
makes it difficult to make changes to settings containing numerals.
Chapter 11 Bluetooth Communications Application 207
11-5
Lighting mBot LED Light With Phone
We will now take the program in 11-4 and evolve it into one that is functional. A fixed character is
sent to the mBot by pressing a button. After the mBot receives the character, it then determines what it
must do. Here we use the simplest LED to implement.
Mobile phone Screen
App program on disc ch11 \ ch11_Ex2.apk
Instructions
1. Press the “Red” button, and the mBot's LED will light up in red.
2. Press the “Green” button, the mBot’s LED will light up in green. Same goes for the “Blue” button.
3. Press the “OFF” button, and all of the mBot LEDs will be turned off.
208 Scratch (mBlock) Program Design — Using mBot Robot
mBlock code Ch11-ex2 Mobile phone lights up the mBot LED
Code
01
02
03
04
05
06
07
08
Description 209
Line 01: LoopsLoop, so that the program will implement the Loop in the program continuously.
Line 02: Detects whether there is any Bluetooth data transmission.
Line 03: Call the self-established BT Receive () function to bring the received Bluetooth character
into the function.
Line 04: A subroutine created by itself with a string variable of string1. String1 is to receive the
incoming Bluetooth characters.
Line 05: Bluetooth received the “A” character, LED light up red.
Line 06: Bluetooth received the 'B' character, LED lights green.
Line 07: Bluetooth to receive the 'C' character, LED light blue.
Line 08: Bluetooth to receive the 'D' character, LED all off.
Note Before using the mobile phone to control the mBot, you must upload the mBlock program to the
mBot’s mainboard.
Chapter 11 Bluetooth Communications Application
11-6
Receiving mBot Ultrasonic Distance with Phone
The most common ultrasonic presence in our lives is when we reverse our cars. When we reverse
our cars, the radar at the back of the car will detect the distance between it and an obstacle. Once the
car is only a few centimeters away from the obstacle, it will start to beep. Now our mobile phones
can further realize the implementation of the loT by receiving the value sent by the mBot’s ultrasonic
sensor.
Mobile phone Screen
App program on disc ch11 \ ch11_Ex3.apk
Instructions
1. Please connect to mBot Bluetooth.
2. Press the “Start Ultrasound” button. mBot will start ultrasonic detection and returns to the phone.
3. Press the “Off Ultrasound” button. mBot will turn off the ultrasonic detection.
4. The buzzer will sound when the mBot detects an obstacle less than 15 cm from it.
210 Scratch (mBlock) Program Design — Using mBot Robot
mBlock code Ch11-ex3 mobile phone to receive mBot ultrasonic distance
Code
01
02
03
04
05
06
07
Description
Line 01: Set an “ultrasonic switch variable”. The program starts implementation when the
variable is set to 0.
Line 02: The ultrasonic switch variable is set at 1.
Line 03: Transmits the ultrasonic distance to the mobile phone.
Line 04: If the ultrasonic distance is less than 15 cm, the buzzer will sound.
Line 05: Pause for 0.2 second.
Line 06: If the ultrasonic switch variable is set at 0, empty characters will be transmitted to the
phone.
Line 07: Pause for 0.2 second.
Chapter 11 Bluetooth Communications Application 211
mBlock program code
Code Ch11-ex3 mobile phone to receive mBot ultrasonic distance
01
02
Description
Line 01: The received Bluetooth character is “A”, and the value of the “ultrasonic variable" is set
to 1. Indicates that the ultrasonic is activated.
Line 02: The received Bluetooth character is “B” and the value of “ultrasonic variable” is set to
'0'. Indicates that the ultrasound is turned off.
Note Before using your mobile phone to control the mBot, you must first upload the above mBlock program
to the mBot controller. That is done after the mBot is restarted after having the program first burnt into
its mainboard.
212 Scratch (mBlock) Program Design — Using mBot Robot
Chapter
11 Review questions
Short Answer Questions
1. Please use the file ch11_Ex1.apk from Mobile Phone Implementation Program
found in 11-4 of this chapter. When mBot receives the character A, mBot will at,
every second, display a red, green and blue light in sequence. When the character
B is received, the color will change every 0.5 seconds, and when the character C
is received, they will take turns to light up continuously. Lastly, when the character
D is received, all the LEDs will be turned off.
2. Please use the file ch11_Ex3.apk from Mobile Phone Implementation Program
found in 11-6 of this chapter, and modify the ch11-ex3 in order for the mobile
phone to receive mBot ultrasonic distance in .Sb2 program. When you press the
“Start Ultrasound” button, mBot will issue a long sound, and the “Off Ultrasound”
button, is pressed, mBot will issue 2 short sounds. When the ultrasound detects a
distance of less than 15 cm, the LED will flash blue light.
Chapter 11 Bluetooth Communications Application 213
214 Scratch (mBlock) Program Design — Using mBot Robot
Chapter 12 CHAPTER OBJECTIVES
Controlling mBot • To let the reader understand how
with Phone App to use mobile phone App to control
the various changes to the mBot
LED.
• To let the reader understand how to
use the mobile phone App to control
the various changes to the buzzer.
• To let the reader understand how to
use mobile App to control the robot’s
actions (forward, backward, left,
right).
CHAPTER OUTLINE
12-1 Light Sensor Use
12-2 Controlling mBot LED with Phone
App
12-3 Controlling mBot Buzzer with
Phone App
12-4 Using Phone App to Remote-
Control Robot Movement
(Forward, Backward, Left, Right)
12-1
Light Sensor Use
We can use the light sensor to detect if the light at the environment of the reading desk is even.
Light affects the children’s vision, so it can also be used to detect the classroom or store’s balance of
light, depending on how the readers use the light sensor.
Using it is very simple. We just have to transmit the value by the light sensor to the mobile phone.
So we just have to move the mobile phone to see the brightness of the place. If you are a flashlight
player, you can use it to compare the light intensity of each of them. You can also compare the light
intensity of the different brands of LED lamp bought.
Draw a flow chart
Robot starts
Waiting for
Bluetooth connection
Receives light Sends light sensor value
sensor data to mobile phone
(Transmitted every 0.3 seconds)
App
The App, on the disc of ch12 \ ch12_LightSensor.apk, uses App Inventor 2 to develop.
First, the mobile phone must be paired with the mBot Bluetooth. The screen is shown below:
Step 1 Search for Bluetooth device Step 2 Request to pair with mBot Bluetooth
216 Note When the mBot is connected to the mobile phone Bluetooth, the mBot can no longer be connected to
the computer using USB.
Scratch (mBlock) Program Design — Using mBot Robot
After installing the apk file, please start the program and connects to the mBot. The screen is as
shown below:
Step 1 App is starting Step 2 Select mBot Bluetooth
After pressing the “Connect mBot” button, please select the Bluetooth device as shown above.
The screen showing the App detecting the light sensor value is as shown below:
Step 1 App is starting Step 2 Select mBot Bluetooth
Description
The mBot sends the value of brightness to the mobile phone every 0.3 seconds. You can modify
it if you wish to slow it down.
Chapter 12 Controlling mBot with Phone App 217
mBlock program Ch12-1 mobile phone receives light sensor value
code
01
02
03
Description
Line 01: Loops Loop, so that the program will implement the Loop in the program continuously.
Line 02: Obtain the light sensor value and round the value up to obtain an integer value. Have
the value sent to the phone.
Line 03: Transmitted every 0.3 seconds.
The switching of the street lamps in the evening most often uses light sensors. Cars as well when
they automatically turn their headlights on when they detect that the sky is darkening. You can also
buy a LED light module and install it in an mBot; that will be very interesting. Perhaps you will also
think of using a flashlight to shine on it; if there is light, the mBot will move, and if there isn’t any, it
stops moving. Please use your imagination and think of the endless possibilities!
218 Scratch (mBlock) Program Design — Using mBot Robot
12-2
Controlling mBot LED with Phone App
This unit uses the mobile phone App to design values of color that can be arbitrarily changed, so as
to match the mBot LED color display. As the mBlock Bluetooth is not able to receive numerical data,
so colors are used to send out the frequency to determine the value of the color (0~255). The colors
displayed on the mobile phone will not be exactly like the LED but will be very similar.
You can learn how to change the mBot numerical data of the program in this unit; just like how you
would write the program when changing the rotational speed of the wheel. The program however will
be more complicated as the LED has three color values to change. This program can also be added as
a general observation of the Bluetooth transmitting data as the LED will flash when that is happening.
Please pay special attention to not stare at the LED for too long when the mobile phone is transmitting
color values to mBot, as that will hurt the eyes.
Draw a flow chart
Robot starts
Waiting for
Bluetooth connection
Bluetooth Receives Records the change in color Change the LED color
Value = R (Red)
Receive the number
Bluetooth Receive of Bluetooth transmissions
Value = G (Green)
(The number is
Bluetooth Receive 0 ~ 255 color value)
Value = B (Blue)
Bluetooth Receive
Value = E (Ends)
Chapter 12 Controlling mBot with Phone App 219
App
The App on the disc ch12 \ ch12 LED.apk uses App Inventor 2 to develop.
Mobile phone pairing with an mBot Bluetooth: Please refer to the previous unit.
Start App and connect the mBot, the screen is shown below:
Step 1 Touch the screen Step 2 LED will change accordingly
Touch the screen
Move the bar
Description
Touching the middle of the mobile phone screen will randomly select a color value. You can use
the bars below to change to monochrome. Once the color values are changed, the mBot’s LED
will start flashing until the Bluetooth finishes transmitting the data.
mBlock program
Make variables and build functions.
code Ch12-2 Mobile phone App controls various changes of the mBot LED .sb2
220 Scratch (mBlock) Program Design — Using mBot Robot
mBlock program — main program
code Ch12-2 Mobile phone App controls various changes of the mBot LED .sb2
01
02
Description
Line 01: All variables are set to 0 after the program is loaded. The LED display is also not
illuminated.
Line 02: Read the received value of the Bluetooth.
mBlock program — Receive Bluetooth subroutine
code Ch12-2 Mobile phone App controls various changes of the mBot LED .sb2
01
02
03
04
05
Chapter 12 Controlling mBot with Phone App 221
Description
Line 01: The received value is character R, which means that the LED will emit red light.
The color value is set to -1 to indicate the number of the next Bluetooth
transmission is to change the value of the red light emitted by the LED.
Setting the value of the variable “Color to be changed” to 1 means that the value of the
red in the LED will change in the “Change LED Color ( )” subroutine.
Line 02: The received value is character G, which means that the LED will emit green light.
The color value is set to -1 to indicate the number of the next Bluetooth
transmission is to change the value of the green light emitted by the LED.
Setting the value of the variable “Color to be changed” to 2 means that the value of the
green in the LED will change in the “Change LED Color ( )” subroutine.
Line03: The received value is character B, which indicates that the LED will emit blue light.
The color value is set to -1, to indicate the number of the next Bluetooth
transmission is to change the value of the blue light emitted by the LED.
Setting the value of the variable “Color to be changed” to 3 means that the value of the
blue in the LED will change in the “Change LED Color ( )” subroutine.
Line 04: The received value is E, representing the number of completed Bluetooth transmissions.
Such as when the character R is received, after which the Bluetooth received 100
times, which is 100 times what the mobile phone sent to the mBot. After the 100 times,
the character 'E' is received, which means the LED will emit red and the lit value is 100.
Line05: Call the “Change LED color ( )” subroutine.
222 Scratch (mBlock) Program Design — Using mBot Robot
mBlock program — The subroutine that changes the color of the LED
code Ch12-2 Mobile phone App controls various changes of the mBot LED .sb2
01
02
03
04
Description
Line 01: The variable “color to change” = 1. Which means to change the red, there is an
increment of 1 for every Bluetooth data received. The variable “color value” is assigned
to the “red” variable.
Line 02: Change the green value.
Line 03: Change the blue value.
Line 04: reset the values of LED red, green, blue light.
Chapter 12 Controlling mBot with Phone App 223
12-3
Controlling mBot Buzzer with Phone App
This unit uses the mobile phone App to design a small piano keyboard to complement the mBot
buzzer. To simplify the program, the black button on the App will not be used. There are eight scales
and it is sufficient to play quite a lot of music. The buzzer uses frequency to sound high and low sounds.
This frequency is of international standards, as shown in the following table:
Scale frequency table
This is only the treble frequency. If you feel that the mBlock built-in representative of the tone does
not meet your requirements, you can set your own.
Tone of mBlock
Scale C4 D4 E4 F4 G4 A4 B4
Mid tone frequency 262 294 330 349 392 440 494
Scale C5 D5 E5 F5 G5 A5 B5
High tone frequency 523 587 659 698 784 880 988
Piano notes Do Re Mi Fa So Ra Si
mBlock buzzer component
Description
The sound from the above two lines of program code sounds the same. The first line is C5 and
the next line is 523; the two lines of the program with block codes have the same tone, thus the
value of 523 can be the input.
224 Scratch (mBlock) Program Design — Using mBot Robot
Draw a flow chart
Robot starts
Waiting for Play the buzzer
Bluetooth connection A = C5 tone
B = D5 tone
Bluetooth receives C = E5 tone
the value D = F5 tone
A~H E = G5 tone
F = A5 tone
App G = B5 tone
H = C6 tone
App program is on the disk ch12 \
ch12 sound.apk, App use App Inventor 2 Touch the piano to press
to develop. Phone pairing with an mBot
Bluetooth: Refer to the previous unit.
Start App and connect to the mBot. The
screen is as shown below.
Description
After connecting to the Bluetooth, the mBot will sound a matching tone when you touch the
white keyboard, Do, Re, etc. The black keys have no effect.
Notation of a children’s song
Little star 1155665 4433221 5544332 5544332 1155665 4433221
Jingle Bells 333 333 35123 4444433 322325 333 333 35123 4444433 55421
Description
The notation 1 on the mobile phone screen represents Do, 2 represents Re ~ 6represents Ra, 7
represents Si and space represents the pause.
Chapter 12 Controlling mBot with Phone App 225
mBlock program
The subroutine that changes the color of the LED.
file Ch12-3 mobile phone App controls the various changes of the mBot buzzer .sb2
01
02
Description
Line 01: Loops Loop, so that the program will implement the Loop in the program continuously.
Line 02: Read the received value of Bluetooth and then put the characters into
The BT Receive ( ) function.
mBlock program
Subroutine of the sound of the buzzer (not printed, see program on the disc file).
file Ch12-3 mobile phone App controls the various changes of the mBot buzzer .sb2
01
02
03
Description
Line 01: Bluetooth receives the character A and plays the tone C5. The beat is
the broadcast in seconds, 1/4 is 0.25 seconds.
Line 02: Bluetooth receives the character B and plays the tone D5.
Line 03: Bluetooth receives the character C and plays the tone E5.
226 Scratch (mBlock) Program Design — Using mBot Robot
12-4
Using Phone App to Remote-Control Robot Movement
Using the mobile phone to control the mBot to run forward, backward, left, and right. Design
simple directional keys for the App screen to control the wheels of the mBot run forward and
backward. mBot is positioned on three wheels, thus the left wheel speed when making a left turn is
-255, while the right wheel speed is 255. It is the opposite when making a right turn. In fact, mBlock
rotates when turning left or right.
mBlock controlling the wheels
We use turning right below to illustrate, the rest is the same.
Code blocks components Illustration
To rotate to the right. Both left and right wheels will
move; the left wheel will rotate forward while the right
wheel will rotate backward.
As above.
Motor’s port 1 is the left wheel. Port 2 is the right
wheel.
Single wheel turning right.
Only the left wheel rotates forward, the right wheel
does not rotate.
Draw a flow chart
Robot starts
Waiting for
Bluetooth connection
Bluetooth Receives Runs forward
Value = A Runs backward
Bluetooth Receives Turns left
Value = B Turns right
Bluetooth Receives Stops
Value = C
Chapter 12 Controlling mBot with Phone App
Bluetooth Receives
Value = D
Bluetooth Receives
Value = G
227
App Touch the buttons on the top
App program is on the disc ch12 \ ch12
move.apk. App uses App Inventor 2 to develop.
Mobile phone pairing with an mBot
Bluetooth: Please refer to previous unit.
Open the app and connect to the mBot. The
screen is as shown below:
Description
1. The mBot runs forward when the “forward” button is pressed.
2. Press “Backward” to run backward.
3. Press the “Left” button to rotate to the left, and the “Right” button to rotate to the right.
4. Press “Stop” to stop moving.
5. The mBot will only move if you press and hold the button. The mBot will stop when you
release your finger from the button.
mBlock program — main program
file Ch12-4 machine App remote controls the robot’s actions ( forward, backward, left,
right ) .sb2
01
02
Description
Line01: Loops Loop, so that the program will implement the Loop in the program continuously.
Line02: Read the received value of the Bluetooth and then put the characters into the BT
Receive ( ) function.
228 Scratch (mBlock) Program Design — Using mBot Robot
mBlock program — Subroutine to move the mBot
file Ch12-4 machine App remote controls the robot’s actions (forward, backward, left,
right) .sb2
01
02
03
04
05
Description
Line 01: When the Bluetooth received value is the character A, it implements running forward.
Line 02: When the Bluetooth received value is the character B, it implements running backward.
Line 03: When the Bluetooth received value is the character C, it implements turning left.
Line 04: When the Bluetooth received value is the character D, it implements turning right.
Line 05: Bluetooth received value is the character G, both wheels stop.
Chapter 12 Controlling mBot with Phone App 229
Chapter
12 Review questions
Short Answer Questions
1. Please use the mobile phone implementation program ch12_sound.apk file in
12-3 of this chapter, and modify the program, 12-3 mobile phone App controls the
various changes of the mBot buzzer .Sb2. Please change the tone to C3 ~ B3,
and for every sound played, the LED lights up for 0.2 seconds.
2. Please use the mobile phone implementation program ch12_move.apk file in 12-4
of this chapter, and modify the program ch12-4 machine App remote controls the
robot’s actions (forward, backward, left, right) .sb2. Please modify the speed of
going forward to increase slowly; from 60 at the start, and increasing by 0.02 every
time it receives a Bluetooth character A. This goes on until the increased speed is
greater than 250 and then the LED will light up in red. The LED will turn off when
you release the forward button. The speed will again increase slowly from 60 the
next time you press the forward button.
230 Scratch (mBlock) Program Design — Using mBot Robot
Chapter 13 CHAPTER OBJECTIVES
Innovative • To let the reader understand the
Applications When basic introduction the product Lego
Combining mBot of the bar, bolt and connector.
with Lego • Let the reader understand how the
mBot combined with Lego, and
the use of "seven-segment display
module" and "face panel" to design
a variety of application examples.
CHAPTER OUTLINE
13-1 ntroduction to Lego
13-2 Lego Crossbar
13-3 Lego Pin
13-4 Lego Connector
13-5 Combining mBot with Lego
13-6 Using [Seven Segment Display
Module] to Display Detected
Value
13-7 Using [Face Panel] to Display
Detected Value
13-8 Using [Face Panel] to Display
[Paint Picture]
13-9 Using [Face Panel] to Display
[Marquee]
13-10 Using [Face Panel] to Display
[Bomb Explosion Countdown 10
Seconds]
13-11 Infrared Controlling mBot (Face
Panel Displays Direction)
13-1
Introduction to Lego
Lego a toy company founded in 1932 AD, is located in the Denmark and has its headquarters in
Billund. In the early years, it mainly produces toy building bricks called LEGO. Today, Lego is not only
a child's toys, but has also become a favorite of many adults. The main reason is because the company is
constantly innovating and changing with the trends. It has also launched a series of themed products.
Three common types of LEGO building bricks
1. Lego creative building bricks.
2. Lego power machinery.
3. Lego robots.
13-1.1 LEGO Creative Building Bricks
Features
To let the children follow the situation of the “story”, and using their imagination, assemble their own
design using the LEGO building bricks.
Purpose
1. To cultivate the child's creativity.
2. To train the fingers to be flexible through practice.
3. To let the children share their work with everyone and cultivate the child's ability to express.
Lego teaching aids
Classic ideas creative building bricks Creative building bricks
232 Scratch (mBlock) Program Design — Using mBot Robot
Works by the author “Car” modeling creation
“Invincible Iron King Kong” modeling creation
13-1.2 Lego power machines
Features
To let the children use the LEGO group of power machinery, with hands-on experience to verify the
"lever", "gear", “pulley”, “connecting rod”, “axle” etc and other physics and mechanical principles.
Purpose
1. To have a deeper understanding of the physical sciences from the observations and measuring of
different phenomenon.
2. By “doing through learning, and learning through doing”.
3. Cultivating the ability of problem solving through observing life and the machines.
Teaching aids
Children’s Simple Power machinery group Power machinery group
Chapter 13 Innovative Applications When Combining mBot with Lego 233
Solar energy (or renewable energy) Pressure group
Power machinery group (Extension Kit) IR remote control
IR receiver
PF Motor (M)
PF Motor (L) PF Motor (XL) Steering
Motor
Note PF represents Power Functions.
234 Scratch (mBlock) Program Design — Using mBot Robot
Works by the author “Original” F1 race car
“Transformed” into
a power machine F1 race car
“Transformed” into “Original” super sports car
a power machine super sports car
13-1.3 Lego robots
Definition
EV3 Lego robot (LEGO MINDSTORMS) is a programmable toy robot manufactured by the Lego group.
Purpose
1. To be hands-on in “assembling” so as to train the students’ abilities to “observe” and “transform
space”.
2. To write a “program” themselves so as to train the students’ abilities to “focus” and “think logically”.
3. To practice on an actual “test” by themselves so as to train the students' abilities to “verify” and
“solve problem”.
Chapter 13 Innovative Applications When Combining mBot with Lego 235
Lego teaching aids
They are currently divided into RCX (first generation), NXT (second generation) and EV3 (third
generation).
RCX (1st generation) 1998 NXT (2nd Generation) 2006 EV3 (3rd generation) 2013
Note 1. Very few players are currently using the first generation RCX. It has become a class for antique
collection.
2. The second generation NXT is currently discontinued, but most of the education centers are still
using it.
3. The third-generation EV3 is currently the mainstream robots in the market.
1. NXT (second generation) related kits are as follows:
NXT Toy Edition (retail version) LEGO 8547 NXT Education Edition LEGO 9797
2. EV3 (third generation) related kits are as follows:
EV3 Home Edition (retail version) LEGO 31313 EV3 Education Edition LEGO 45544
236 Scratch (mBlock) Program Design — Using mBot Robot
Official works EV3 humanoid robot
XT humanoid robot
Works by the author “Original” Lego Sapphire sports car
“Transformed” into the EV3 host F1 car
“Transformed” into the NXT host super sports “Original” super sports car
car
Chapter 13 Innovative Applications When Combining mBot with Lego 237
13-2
Lego Crossbar
Also known as a smooth rail because it has no studs. When constructing the framework of a robot
or the structure of a variety of vehicles, in addition to the use of beams with holes in, the EV3 kit has
already replaced with the traditional “bump beam”.
Length unit
Module (written as M)
Calculated differently from the bump beam
It is calculated according to the “number of holes”.
Classification ㄑ-shaped beam (3×7) T-shaped beam (3×3)
Smooth beam (1×7)
ㄑ-shaped beam (4×4) Small L-shaped beam (2×4)
ㄑ-shaped beam (4×6) J-shaped beam
Big L-shaped beam (3×5)
238 2M Description
Amongst them, we can subdivide the
“smooth beam” into the following 8
types:
The shortest is currently 2M and the
longest is 15M.
15M
Scratch (mBlock) Program Design — Using mBot Robot
Name
Technic Liftarm is 1x15 Thick, and represents a length of 15 hole beam. It is the lowest beam shown
in the diagram above.
Use
Can be used to strengthen the main beam of the robot as well as the strength of the main structure
of various vehicles.
Method
It is connected by various “pins, axles and collars.”
Advantages
It is more diverse in its use and functions. In the “smooth beam”, in addition to having “round
holes”, there are “cross holes” that can be connected to the “gear”. On top of that, it comes in various
shapes and sizes, so that students or players are able to design power machinery of different shapes.
Practical examples Sports car
A large crane and a sports car.
Large crane
Chapter 13 Innovative Applications When Combining mBot with Lego 239
13-3
Lego Pin
Definition
It is used to connect different parts onto the beams or other building bricks.
Pins Image Long pin Short pin Long pin
(Fixed type) (movable type) (movable type)
Short pin
(fixed type)
Features
Used to connect the components “cross and round hole” or “round hole and round hole” in order to
produce fixed or movable results.
Illustration
“Active pin” and “fixed pin” connection test:
Easy to rotate Not easy to rotate
Short beige pin Short blue pin
Description
1. With the short blue pin (fixed type), you will find that the car tires, while rotating, do not
rotate easily.
2. With the short beige pin (movable type), you will find the car tires, while rotating, rotate
easily.
240 Scratch (mBlock) Program Design — Using mBot Robot
13-4
Lego Connector
Same as with pins
They are used to connect different parts onto the beams or other building bricks.
Different from pins
Its style is the composite type.
Schematic diagram
“Double-axle” connector “Angle” connector “H type” connector “L type” connector
Vertical connector “Steering” connector 3L vertical connector
Separated double hole pin Upright three hole pin
Double cross axle upright Upright double hole pin Three-axle connector Double pin connector
connector
Description
There are six types of angle connectors, with numbers on them.
No. 1 No. 2 No. 3 No. 4 No. 5 No. 6
(0 degree) (180 degrees) (157.5 degrees) (135 degrees) (112.5 degrees) (90 degrees)
Chapter 13 Innovative Applications When Combining mBot with Lego 241
13-4.1 Application of a double-axle connector
When to use
It can be connected to a longer cross axle when the length of the cross axle is insufficient.
1 double axle connector and 1 double axle connector to connect
2 pieces of 3M cross axles 2 pieces of cross axles
Actual Example
Assembly of a slow moving insect machine.
Connect the two cross axles
242 Scratch (mBlock) Program Design — Using mBot Robot
13-5
Combining mBot with Lego
In the previous unit, we have understood Lego's related parts and how to assemble them. In
contrast, an mBot does not provide as many parts in its model. At this point, if you begin to think that
the development of an mBot is limited, then you are wrong.
In fact, this problem has been thought of when designing the mBot’s metal components. Thus, the
metal plate at the mBot’s base have holes, the same size as those of Lego’s, on in. It is so that it can be
used together with Lego, which will aid its future expansion and marketability.
Combining the Seven-Segment Display with Combining the Face Panel with Lego Parts
Lego Parts
Same size as the holes on a Lego beam Face Panel
Seven-segment display module
Note The “7-segment display module” and “face panel” in the above figure must be purchased separately.
Based on the above after we have successfully used the Lego parts to install the “seven-segment
display module” and the “face panel” in our mBot, you can then use them to write a series of mBlock
programs, so that students can learn more about the mBot’s combination, scalability and future.
Chapter 13 Innovative Applications When Combining mBot with Lego 243
13-6
Using 7 Segment Display Module to Display Detected Value
In the previous unit, we have used the mBot with Lego parts in conjunction with the "seven-
segment display" and “face panel”. Therefore, in this unit, we will use the “seven-segment display
module” to display the “ultrasonic and light sensor” detected value.
1 Displays the ultrasonic detected value
mBlock Program
Implementation screen
Short distance (obstacles ahead) Long distance (obstacle far ahead)
244 Scratch (mBlock) Program Design — Using mBot Robot
2 Displays the light sensor detected value
mBlock Program
Implementation screen Exposure to lamp
No exposure to lamp
Chapter 13 Innovative Applications When Combining mBot with Lego 245
13-7
Using Face Panel to Display Detected Value
In the previous unit, we have used the mBot with Lego parts in conjunction with the “seven-segment
display” and “face panel”. Therefore, in this unit, we use the “face panel” to display the “ultrasonic and
light sensor” detected value.
1 Display the value of the ultrasonic detection (also displayed in the
seven-segment module + face module)
mBlock Program
Implementation screen
Short distance (obstacles ahead) Long distance (obstacle far ahead)
246 Scratch (mBlock) Program Design — Using mBot Robot
2 Display the value of the light sensor detection (also displayed in the
seven-segment module + face module)
mBlock Program
Implementation screen Exposure to lamp
No exposure to lamp
Chapter 13 Innovative Applications When Combining mBot with Lego 247
13-8
Using Face Panel to Display Paint Picture
In the previous unit, we have used the mBot with Lego parts in conjunction with the “seven-segment
display” and “face panel”. Therefore, in this unit, we will use the “face panel” to display “paint pictures”.
Implementation
mBlock Program
Implementation screen Exposure to lamp
No exposure to lamp
248 Scratch (mBlock) Program Design — Using mBot Robot
Extended Learning—— Explanation of the tool for painting
In the mBlock’s “face panel” module, the painting tool (8 * 16 grid) is provided to users to create
their own design. The designers only need to “click” the two-dimensional grid box to easily design
patterns. As shown in the diagram below:
Chapter 13 Innovative Applications When Combining mBot with Lego 249
13-9
Using Face Panel to Display Marquee
In the previous unit, we have learnt to use the “face panel” to display “paint picture”. Next, we will
learn to use "from right to left" of the face panel to display the “Marquee”.
Implementation
Please use “from right to left” of the face panel to display the "Marquee", which will display the text “I
love mBot!”.
Answer
mBlock Program
250 Scratch (mBlock) Program Design — Using mBot Robot