Chapter 1
CHAPTER OBJECTIVES
• H e l p re a d e r s u n d e r s t a n d t h e
definition of a robot and its usage in
various fields.
• Help readers understand the mBot’s
composition, setup and power
mechanical transmission method.
CHAPTER OUTLINE
1-1 What is a Robot
1-2 Basic Introduction to Makeblock
1-3 mBot Robot
1-4 mBot Robot Version
1-5 mBot Robot Common Usage
Introduction to
Robots
1-1
What is a Robot
The Myth of the Robot
A “robot” is only a “human-shaped toy or remote-controlled vehicle”; this type of definition is far
too narrow and inaccurate as well.
Table 1.1 Human-Shaped Toy vs. Remote-Controlled Vehicle
Item Illustration Description
Human-Shaped Toy Considered a static puppet, unable to receive
any signal messages, and unable to operate
independently.
Remote-Controlled Vehicle Can receive signals shot from remotes, but
lacks “sensors” to detect the changes in the
external environment. For example: If there
were no remote to control it, and it met an
obstacle, it would not automatically stop or
move around it.
In-Depth Discussion
We all know, humans can use “eyes” to look at objects in their surroundings, use “ears” to listen
to sounds in their surroundings; but since robots have neither eyes nor ears, how should they best
simulate human thought and behavior, and thus be able to assist humans in dealing with complex
problems?
In reality, a “robot” is a computer (simulating the human brain); it has computer controller (including
central processing units and memory units), and has an input port, used for connecting sensors
(simulating human sensory organs), and an output port, used for connecting the motor (simulating
human limbs.)
Definition
Robot is not necessarily limited to “human form”, anything that can be used to simulate “human
thought” and “behavior” and is programmable can be called as such.
2 Scratch (mBlock) Program Design — Using mBot Robot
Processor(brain)
Three Types of Main Elements Sensor(sensory organs)
1. Sensor (input)
2. Processor (processing)
3. Service Motor (output)
Operation Mode of the Robot
1. Input End: similar to human “sensory Service Motor(limbs)
organs”, uses different types of “sensors” to Figure 1.1 mBot
detect change in the external environment, and receives news and information.
2. Processor End: similar to human “brain”, provides “programming” developers to make different
response actions in response to detect news and information.
3. Output End: similar to human “limbs”, makes actual movement through the “service motor”.
Example —— Robots That Can Navigate Mazes
After an mBot vehicle (also known as wheel-type robots) has been assembled, when the “ultrasonic
sensor” of the “input end” detects obstacles in front of it, its programming in its “processor end” can
have possible responses of “directly back up” or “back up and then proceed forward” or “stop” motions
etc.; if “back up and then proceed forward” is chosen, the “service motor” of the “output end” will
actually back up in reality, move left or right, and then finally move forward, along with other such
actions.
Figure 1.2 The robot that can navigates Mazes 3
Chapter 1 Introduction to Robots
Use of the Robot
Because people do not like to do jobs with “dangerous” or “repetitive” characteristics, there is a
motivation to invent robots of all kinds of uses, with the objective of substituting or helping humans
with many types of complex work.
Common Uses
1. Industrial: Mechanical arms used for welding (e.g. for car manufacturing) or production-line
packaging.
2. Military: Defusing explosive objects (e.g. bombs)
3. Space: Autopilot (e.g. detecting airplanes, exploration vehicles, see Figure 1.3)
4. Medical: Home care (e.g. reporting situations with the elderly)
5. Everyday Life: Automatic house cleaning (e.g. automatic vacuum cleaner)
6. Exercise: Automatic serving machines (e.g. automatic table tennis serving machine)
7. Transportation: Driverless vehicles (e.g. Google’s research and development in driverless cars)
8. Safety Testing: Car collision testing
9. Entertainment: Takes place of traditional single-feature toys
10. Educational: Trains students’ critical thinking and general application capabilities, with the main
goal of helping students learn the general application of robots’ mechanical principles, sensors,
hosts, and service motors. Thus, it develops a variety of robotic programs and practical application.
Figure 1.3 Mars Exploration Rover
4 Scratch (mBlock) Program Design — Using mBot Robot
1-2
Basic Introduction to Makeblock
Makeblock is known as a “metal version of Lego”; besides providing a wide variety of metal
components, it urges the users to make all sorts of different modules of metal structures themselves.
Figure 1.4 Metal Lego
Composition Elements
1. Mechanical Structure
Aluminum alloy components, which comprise
both strength and the aesthetic.
2. Electronic Circuits
Use the sensors, motors, and related electronic components of various modules.
Table 1.2 Electronic Circuit modules Motors
Various Sensors
Ultrasonic Sensor Line-follower Sensor Direct-Current Stepper Motor
Deceleration Motor
Chapter 1 Introduction to Robots 5
3. Control System
Using the open Arduino hardware platform as a basic controller, can integrate electronic circuits.
Table 1.3 Control System mBot Integrated Electronic Circuit
mBot Mainboard
4. Programming Language
Use “circular drag-and-drop” program. This can lower the learning curve, and raise the learner’s
motivation and interest.
Table 1.4 Programming Language mBot Integrated Electronic Circuit
mBot Mainboard
6 Scratch (mBlock) Program Design — Using mBot Robot
Currently, officials have also launched a series of products with different applications. Table 1.5 is
the author’s compilation of five currently common, different types of sets:
Table 1.5 5 Common Types of Sets 2. 3D printer
1. mBot kit (2.4G version and Bluetooth version)
3. Ultimate 2.0 Robot Kit 4. Inventors Electronic Kit
5. mDrawBot Drawing Robot
Chapter 1 Introduction to Robots 7
1-3
mBot Robot
Definition
mBot is a set robot designed to train students’ critical thinking and hands-on ability.
mBot Robots Advantages Over Lego Robots
1. In terms of price: 1/8 of the Lego Robot’s. The education version EV3 third generation Lego robot
is around NT$ 20,000, whereas the mBot is around NT$ 2,500.
2. In terms of structural strength: considered as having aluminum alloy components, stronger than
Lego components, often can be used in industrial work.
mBot (Aluminum Alloy Components) Lego (Plastic Components)
3. In terms of sensor type: currently providing several dozen types of sensors with different uses,
broadening the area of possible usage.
Makeblock Electronic Module Illustration Features
(Common)
Ultrasonic Sensor Module Detects distance
Ex: if there is an obstacle ahead
Line-Follower Sensor Module Detects different colors
Ex: black and white
8 Scratch (mBlock) Program Design — Using mBot Robot
Makeblock Electronic Module Illustration Features
(Common)
Displays data and information
Seven Segment Display Module Such as: speed, heat, distance…
Joystick Module
Potentiometer Module Controls movement direction
Sound Sensor Module Such as: forwards, backwards,
Temperature Sensor Module left, right
Infrared receiver Module
LED Series 8x16 Face Panel Corrects states of other modules
Bluetooth Module Such as: control speed or LED
Wifi Module light brightness
Detects different volumes 9
Such as: Sound control robots
Detects heat in different
environments
Such as: under sunlight or
indoors
Detects people or animals
Such as: monitors approaching of
people or animals
Used to display dynamic patterns
Such as: current number of black
lines crossed
Receive or send Bluetooth
information
Such as: cell phone displays
immediate temperature and
humidity
IEEE802 protocol WIFI module
Such as: Internet of Things (IOT)
usage
Chapter 1 Introduction to Robots
Makeblock Electronic Module Illustration Features
(Common)
Detects touch
Touch Sensor Such as: program opens after
touch
RJ25 Converter
RJ25 turns DuPont line
Camera Electronic Shutter Such as: connects heat sensor
Full-Color Light Output Board Connects to camera or video
camera, used to control shutter
Flame Detector and focus
Gas Sensor Four full-color LED, can be used
to emit light
Temperature-humidity Sensor
Can detect wavelengths of
Encoder Motor Driver 760nm to 1100nm for flame or
light sources
Compass Module Such as: firefighting robots
Detects smoke, butane, methane,
alcohol, hydrogen, and other
gases
Detects temperature and humidity
Such as: Smart household
temperature-humidity control
system
Code motor and mainboard
connector
Displays current position
Such as: robot’s current facing
direction
10 Scratch (mBlock) Program Design — Using mBot Robot
Makeblock Electronic Module Illustration Features
(Common)
USB connector
USB Module Such as: connecting wireless
handheld controller to move the
LED RGB Strip robot
Full-color LED light strips
Such as: situation control system
4. In terms of assembly: Assembly is easier than for Lego robot, with approximately 45 components.
Chapter 1 Introduction to Robots 11
5. In terms of combination with outside parts: It can be combined with Lego parts, and can create
more models and make up for the lack of strength in Legos.
Use Lego Parts in Combination with Use Lego Parts in Combination with
“Seven Segment Display” “Face Panel”
Note: In principle, mBot’s framework structure uses “aluminum alloy components”, while the outside or model
uses “Lego components”.
mBot Robot Advantages Over Arduino
1. Low threshold: No need for background in electronics or electrical engineering, and also does not
require learning to setup the electrical circuits of the breadboard.
mBot + Motor (Low Threshold) Arduino + Breadboard (High Threshold)
12 Scratch (mBlock) Program Design — Using mBot Robot
2. Module-Type Assembly: Various sensors and motors are connected to the mBot’s mainboard by a
port.
mBot’s Mainboard Arduino Mainboard
AA Battery Holder
Bluetooth/2.4G Module
Me Ultrasonic Sensor
Motor(Right) 3.7V Lithium Battery
Line Follower Sensor
Motor(Left)
3. Plug and play immediately: Plug into mainboard according to the different colors on the sensor.
Sensor Sensor
Main Control Board
Sensor
Sensor
Chapter 1 Introduction to Robots 13
Learning Territory Covered by the mBot
1. In terms of hardware course material: Control system (Arduino), mechanical structure and
robotics.
2. In terms of software course material: Algorithms and programming design (Scratch).
Info Source: http://www.zigobot.ch/en/home-english/robots/mbot-blu-detail.html
mBot Robot and mBlock Software Introduction
mBot Robot mBot Software
Description
In mBlock software, we can order the hardware mBot to proceed with different controls through
the “Drag-and-Drop Program”, thus making it easier for students to write robotics code, without
having to understand the robot’s internal soft and hardware structure.
Common Development Tools
1. mBlock software: uses “visualized” “Drag-and-Drop Programming” to code the mBot.
2. Arduino C: uses C language specifically made for Arduino controller.
When to Apply
1. mBlock software: suitable for middle school/elementary school students, or beginning learners
of the mBot.
2. Arduino C: suitable for students in high school/college, or higher.
mBlock Software Advantages
1. Uses “visualized” “Drag-and-Drop Programming” to code the mBot, can decrease the need to
study complex C-language programming.
2. mBlock software provides complete components for controlling mBot hardware.
14 Scratch (mBlock) Program Design — Using mBot Robot
1-4
mBot Robot Version
Basically, when you want to purchase an mBot, you should know your uses for it. Because it can be
divided into two versions: one is the 2.4G version, the other is the Bluetooth version. Next, we will use
Tables 1.6 to describe the points of difference between the two:
Table 1.6 5 mBot Version
Version 2.4 Version Bluetooth Version
Differences
Place of Use Classroom use (education centers) Individual/family use (because it can be
controlled via phone)
Pairing Unnecessary (can be directly connected) Necessary (needs to be paired in order
to connect)
Supporting App None (Cannot be used via mobile Some (can be used via laptop or cell
devices) phone)
1-4.1 2.4G Version
Features
2.4 G Module can quickly connect with computer, and is suitable for classes with a large number of
students.
Module Illustration Install onto mBot 2.4G USB (Launcher) Install onto Computer
2.4G Chip Module
(Receiver)
Description
In the Bluetooth module pictured above, it’s considered a mCore design, simultaneously
supporting Bluetooth 2.0 and 4.0, and is suitable for individual or family use.
Advantages
1. Does not require Bluetooth pairing, highly suitable for usage in a classroom setting.
2. Does not require installing of drivers, supports plug and use.
Disadvantages
Cannot use a phone app to control the mBot.
Chapter 1 Introduction to Robots 15
1-4.2 Bluetooth Version
Features
When the Bluetooth communication module is installed onto the mBot, the mBot can be controlled
with a smart phone.
Module Illustration Install onto the mBot
Bluetooth Communication Module
Description
In the Bluetooth module pictured above, it’s considered a mCore design, simultaneously
supporting Bluetooth 2.0 and 4.0, and is suitable for individual or family use.
Advantages
1. Can use Android or iOS smart phones to go to the official website and download the App, pair it
through Bluetooth, and then be able to control mBot through your cell phone.
2. Mobile device launchers can write special-purpose programming in order to control the mBot.
For example: use cell phone to control mBot to use a shovel and move objects or sweep the floor.
Phone App Operation Interface Control the mBot
16 Scratch (mBlock) Program Design — Using mBot Robot
1-5
mBot Robot Common Usage
From previous chapters, we hope that you now have an initial understanding of the mBot; next,
you probably want to ask, in possession of an individual mBot, what can I do? This is a very important
question. Don’t worry, next, the author will summarize some usages for the readers.
1. In terms of entertainment
when the original came onto the market, small children and parents could control the robots with
“infrared remote controllers”, and could switch to self-propelled mode too. For example: Remote-
controlled cars, obstacle-avoiding cars, and tracking cars, etc.
mBot Remote Controller —— Illustration Description
Mode 2: Wall
avoidance robot
Mode 1: Remote Line follwer robot
manual control
Forward
Left Right
Backward
Mode Set the speed of
the robot
Source: http://kiki166.blogspot.tw/
Description
First Mode: use the “direction keys” on the remote control to
control the direction of the mBot’s movement, and use the
“number keys” to adjust movement speed.
Second Mode: as the mBot moves forward, use “ultrasonic
sensor” to detect if there are obstacles ahead, and if there
are, it will automatically avoid them, and if there are not, it will
continue straight.
Third Mode: mBot uses the “line-following sensor” to follow the
pre-determined black or white lines.
Chapter 1 Introduction to Robots 17
2. Exercises logical thinking and problem-solving skills:
i. To be hands-on in “assembling” so as to train the students’ abilities to “observe” and “transform
space”.
ii. To write a “program” themselves so as to train the students’ abilities to “focus” and “think
logically”.
iii. To practice on an actual “test” by themselves so as to train the students' abilities to “verify”
and “solve problem”.
3. Change and Innovation in Mechanisms
i. Construct specialized creative mechanisms
based on different uses.
ii. Combine the mechanisms, electronic
control, and program design’s ability to
span several areas at once.
Source: http://arduino-elektronika.eu/hr/109-makeblock http://www.monoprice.com/product?p_id=13957
To summarize above, after students assemble an mBot, they can use a “figure-control program”
method to lower the learning threshold for programming, and then be able to solve the problem.
18 Scratch (mBlock) Program Design — Using mBot Robot
Chapter
1 Review questions
1. Describe the reasons that neither “human-shaped toys” nor “remote-controlled
cars” can be classified as robots.
2. What are the three elements of a robot?
3. List real-life uses of robots. Write at least five examples.
4. What are the main assembly elements of Makeblock Company’s newly produced
series “the metal version of Legos”?
5. What advantages does the mBot have over the Lego robot?
6. What advantages does the mBot have over Arduino?
7. What areas of study does mBot cover?
8. What are some common development tools used by the mBot?
9. When we’re purchasing mBot robots, what version choices are available? Explain
the differences in a table.
10. After we’ve bought an mBot robot, what uses does it have? List at least three.
Chapter 1 Introduction to Robots 19
20 Scratch (mBlock) Program Design — Using mBot Robot
Chapter 2 CHAPTER OBJECTIVES
mBot
• To let the reader understand the
Programming mBot programming process.
Development
Environment • To let the reader understand the
assembly of the mBot, its integrated
development and to write the first
mBlock program.
CHAPTER OUTLINE
• 2 - 1 m B o t ’s P r o g r a m m i n g
Process
• 2-2 Assembling an mBot
• 2 - 3 I n t ro d u c t i o n t o m B o t ’s
mainboard
• 2 - 4 m B o t P r o g r a m m i n g
Development Environment
• 2-5 Downloading and Installing
mBlock Software for mBot
• 2-6 mBlock Integrated Development
Environment
• 2 - 7 Wr i t i n g t h e F i r s t m B l o c k
Program
2-1
mBot’s Programming Process
Introduction
In the previous chapter, we learned about the components of the mBot, but with only these parts,
the robot can only be assembled into an external mechanism, and the user is not able to control its
actions. Therefore, it is an important topic in this chapter to learn how to write a program on the mBot
so as to allow users to test and manipulate it.
Three-pronged Program to Design a Robot
Basically, three steps must be included to complete a robot to which tasks are assigned: assembly,
write a program, and test.
Explanation
Table 2.1 Human-Shaped Toy vs. Remote-Controlled Vehicle
Assembly Mount the “Motor, Sensor and
Accessories” on the ‘mBot’ according to
the specified task.
Write a program Write the action and sequences of the
Test program according to the specified task
(mBlock program).
Upload the mBlock program to “mBot”
in accordance with the specified task’s
actions and sequences to perform the
simulation.
22 Scratch (mBlock) Program Design — Using mBot Robot
Flow chart
Start AA Battery Holder
Bluetooth/2.4G Module
Me Ultrasonic Sensor
Motor(Right) 3.7V Lithium Battery
Assembly Line Follower Sensor
Motor(Left)
Write a Program
Fail Test
Success
Completed
mBot design
End
Description
From the above flow chart, we can understand clearly that the “Program to Design a Robot”
must go through three major steps. If the test is unsuccessful in the third step, in addition to
modifying the program, we also have to check whether it was assembled correctly, and then
test it repeatedly until it is successfully completed.
Chapter 2 mBot Programming Development Environment 23
2-2
Assembling an mBot
If you are a beginner, you can refer to the mBot assembly manual or related websites. In this unit,
assume you have already assembled an mBot. Assembly instructions and their components are shown
below:
mBot Components descriptions Completed mBot (basic vehicle)
Note: mBot Components descriptions (Source of picture: Teacher Qiu Xinren: mBot Robot Instructions Kit).
Assembly Sequence 2STEP Install “Right motor”
1STEP Install “Left motor”
3STEP Attach the “Tires” to the “Tire rims” 4STEP Install both left and right “Wheels”
24 Scratch (mBlock) Program Design — Using mBot Robot
5STEP Installation of “Line-follower sensor” 6STEP Install “Ultrasonic sensor”
and “Caster”
7STEP Install four brass bolts (to support the 8STEP Install four brass bolts (to support the
Board) Board)
STEP Stick the Velcro to 3 STEP Stick both the Velcro to each other
9 10
11STEP Install mBot 12STEP Install 2.4G or Bluetooth module to
mBot
Chapter 2 mBot Programming Development Environment 25
Wiring diagram
AA Battery Holder
Bluetooth/2.4G Module
Me Ultrasonic Sensor Motor(Right)
3
3.7V Lithium Battery
2
Line Follower Sensor
Motor(Left)
NOTE
1. Facing the direction that mBot runs forward, the left “motor L” connects to M1, and the right “motor
R” connects to M2.
2. “Line-follower Sensor” connects to the second port.
3. “Ultrasonic Sensor” connects to the third port.
4. If you are connecting a third motor, be sure to use No. 3 battery holder (1.5V * 4). The power will
be insufficient if you use “Lithium battery (3.7V)”.
5. You can purchase Bluetooth and 2.4G module according to your needs. However, only one can
be used at a time.
26 Scratch (mBlock) Program Design — Using mBot Robot
2-3
Introduction to mBot’s mainboard
Basically, mBot’s mainboard is made up of input, mCore core controller, output, related power
switches etc. As shown below:
AA Battery Holder Interface 3.7V Lithium Battery Holder Interface
Reset Power Switch
USB Connector Motor Interface
RJ25 Port RJ25 Port
RGB LED RGB LED
Buzzer Button
Light Sensor
IR Receiver
IR Transmitter
Figure 2.1 The basic hardware components of an mBot’s mainboard
Description
1. Input
21 43
Button IR Receiver Light Sensor Four RJ25 ports
(Used to connect a variety of sensors)
2. mCore Core Controller (using Arduino UNO base)
The mBot processor is specifically designed to handle the input of the analysis of
information, before making the appropriate output action.
Chapter 2 mBot Programming Development Environment 27
Description
3. Output
IR transmitter RGB LED Buzzer Motor wire slot
4. Power and setting switch
Power switch 3.7V Lithium battery AA Battery holder Reset
holder interface interface
In summary, a completed mBot apart from the “mainboard”, can also have “other kinds of
sensors” added at “input”. Such as: ultrasonic sensor and line-follower sensor etc. Additional
“motor” can also be added at “output”, as shown below.
Potentiometer
Ultrasonic Sensor Seven Segment Display
Passive IR Detector
Sound Sensor
RJ25 Adaptor
Servo
28 Scratch (mBlock) Program Design — Using mBot Robot
2-4
mBot Programming Development Environment
When the reader has Figure 2.2 mBlock programming language
successfully assembled an mBot,
and also understood the mBot’s
hard body structure of input,
processing and output, I am
sure everyone cannot wait to
write a program to experiment
with it. But if you wish to write
a program, then you have to
first understand the mBot
development environment.
The two most often used
programs to control the mBot
are the following:
The first is the mBlock
code blocks development
environment: it is based on
Scratch 2.0 as the programming
language.
The second is the Arduino
IDE development environment:
it is a C Language tailored for
Arduino controller.
Figure 2.3 Arduino IDE programming language
Chapter 2 mBot Programming Development Environment 29
Regardless of which development environment you use, if you want to control an mBot offline, you
need to “upload” it to the mCore (mBot controller) in order for the mBot to operate independently, the
so-called “self-propelled vehicle”.
Figure 2.4 mBlock programming → Upload to Arduino
Figure 2.5 Arduino IDE → Upload
NOTE
In this book, the writer uses the first type of mBlock development environment, which is based on
Scratch 2.0 Open Source Code.
30 Scratch (mBlock) Program Design — Using mBot Robot
2-5
Downloading and Installing mBlock Software for mBot
After we have assembled the mBot and understand the basic hardware components, we can now
download its software on the official website to control the mBot, called the “mBlock” software. The
complete steps are as follows:
Step Download Windows version at the official website http://www.mblock.cc/download/
1
Step Note: On the official website, the “mBlock” software is available in two different operating
2 system versions. In this book, use “Windows” as an example.
Install the “mBlock” software.
After you successfully download it, it will produce a compressed file “mBlock_win_
v3.4.10.zip”. Please extract and install the program as shown below:
Chapter 2 mBot Programming Development Environment 31
1 Double click the “mBlock_win_v3.2.2.exe” file to open the file, and then click on the “Proceed”
button.
2 Select the installation language ("English" is the default), and then click on the “OK” button.
3 Accept the agreement then click the "Next >" button.
32 Scratch (mBlock) Program Design — Using mBot Robot
4 Select the location where the installer will be installed, and click on the “Next” button.
5 Select the location where the shortcut will be installed, and then click on the “Next” button.
Chapter 2 mBot Programming Development Environment 33
6 “Check” to create a desktop icon, and then click on the “Next” button.
7 Click on the “Install” button when ready to install.
34 Scratch (mBlock) Program Design — Using mBot Robot
8 Installing.
9 When installation is completed, click on the “Finish” button.
Chapter 2 mBot Programming Development Environment 35
2-6
mBlock Integrated Development Environment
If you want to use the “mBlock program” to develop mBot program, you must first be familiar with
mBlock integrated development environment interface.
Player Project name Function table Editing tools Sprites scaling tools
(Full screen)
Stage area
Component area
Block program area
(Script)
Sprites area
In the mBlock development environment, apart from having the same function as Scratch 2.0,
it also increases the components for the Robots. The author in this unit will thus only introduce the
functional area that the mBot needs.
2-6.1 Stage Area
When we create a new project, the system will automatically load a character, the “panda” in the
stage area. While it is writing the mBot program, most of them, in fact are used to show the “variable”
value during the process of change. Next, I will further introduce its two uses:
36 Scratch (mBlock) Program Design — Using mBot Robot
Method 1 When there is no mBot.
It is identical to Scratch 2.0. In other words, if you install mBlock without mBot, you can have the
same functions as Scratch 2.0.
Features
It is used to render the result of the “Script” executed in the “Block programming area”.
1. Drawing a flow chart (script description) 2. Design Block programming
When click “green ag” one time
Change to Costume 1 rst
Move 10 steps
Wait for 0.3 seconds
Change to Costume 2 rst
Move 10 steps
Wait for 0.3 seconds
Method 2 When there is mBot.
Features
Used to present the values of a number of “variables”, that is; the values detected by various sensors
or related information can be displayed by the variables.
• To detect the distance of the ultrasonic sensor in the mBlock programming language.
Figure 2.3 mBlock program 37
• Test the distance
1. Place your hand in front of the ultrasonic sensor
2. Move your hand horizontally slowly
Chapter 2 mBot Programming Development Environment
• Test Results Detection distance (relatively longer)
Detection distance (relatively shorter)
Return value ≒ 4 Return value ≒ 20
2-6.2 Component Area
There are ten different kinds of functions in
the component area, each one using a different
“color” to distinguish from each other. The
detailed description is as follows:
Motion command(dark blue) Looks command (lilac) Sound command (pink)
38 Scratch (mBlock) Program Design — Using mBot Robot
Pen command Data & Block command Events command
(Dark Green) (Orange) (Dark Brown)
......more Sensing command(light blue) ......more
Control command Operators command
(light brown) (light green)
......more ......more ......more
Arduino Robots Communication
mBot
......more ......more ......more
NOTE
In this book, the focus is on the introduction of “Data & Block”, “Control”, “Operators” and “Robots” in
the “mBot” versus “Communications” module.
Chapter 2 mBot Programming Development Environment 39
2-7
Writing the First mBlock Program
After understanding the development of mBlock, we can begin to write the first mBlock program to
control the actions of the mBot. The complete steps are as follows:
Connection settings Step 1: One of the following three methods can be selected
Programming 1. Connect (serial port USB wired remote control)
2. Bluetooth (mobile phone or tablet wireless remote control)
3. 2.4G serial (computer wireless remote control)
Step 2: Update the firmware
Step 3: Write a program with code blocks
Step 4: Wired or wireless remote control test
Step 5: Upload to the mBot, and carry out “offline autonomy control” test.
• Implementation
Step 1 Choose one of the following three methods according to your actual situation.
Choose one of the following three methods Connection method
1. Connect (serial port USB wired remote control)
2. Bluetooth (mobile phone or tablet wireless remote
control)
3. 2.4G serial (computer wireless remote control)
Step 2 Upgrade the firmware
The mBot's mainboard can only save the last uploaded program. Therefore, to ensure that the
current written program is being executed as usual, you have to carry out “Upgrade firmware” each
time there is a connection. As shown below:
Note: Please perform "Reset Default Program" procedure if you are not able to execute it even after
the firmware has been updated.
40 Scratch (mBlock) Program Design — Using mBot Robot
Step 3 Write a “Block program”
Draw a flow chart Block program
When double-clicking the
“mBot main program”
Runs forward 1 second
Stops
LED lights up in red 1 second
LED goes off
Beep 1 second
Step 4 Wired or wireless remote control test (optional test)
1. Wired remote control test: refers to the computer connecting mBot through the USB, and
assigning a serial port to mBot to use.
Connect COM4 in mBlock Look from “Device Manager”
2. Bluetooth (mobile phone or tablet wireless remote control)
Chapter 2 mBot Programming Development Environment 41
3. 2.4G serial (computer wireless remote control)
After connecting, click on the "mBot program" twice. As shown below:
Double click
Step 5 Upload to the mBot and carry out the "offline autonomy control” test
1. Execute Arduino mode 2. Upload to Arduino
When you have completed step 5, the mBot will no longer need to be instructed using the PC
as the program can be executed directly from mBot. This is the race of "self-propelled" carried out
in many robot competitions, i.e., the mode in which robots can autonomously execute commands.
42 Scratch (mBlock) Program Design — Using mBot Robot
Chapter
2 Review questions
1. Assume we want to design a robot program, what are at least three of the steps to go
through?
2. Please explain what are the input, processing and output terminals on the mBot’s
mainboard?
3. Would are the steps to writing an mBlock program to control the actions of an mBot?
Chapter 2 mBot Programming Development Environment 43
44 Scratch (mBlock) Program Design — Using mBot Robot
Chapter 3
CHAPTER OBJECTIVES
• To let the reader understand the
source of an mBot action, and the
way to control the motor.
• To let the reader understand how
the motor receives data from other
sources which in turn, become the
source of its speed.
CHAPTER OUTLINE
3-1 Introduction to Motors
3-2 Controlling Motor Speed and
Direction
3-3 Making the Robot Move
3-4 Moving the Robot in a Square
3-5 Motor Receiving Other Power
Sources
mBot Starts to
Move
3-1
Introduction to Motors
To get the mBot to move, you must first understand the basic principles and functions of the
motor. In fact, it is used to allow the robot to move freely (forward, backward, left, right and rotates in
position), or to perform a specific action.
mBot motor
Two motors Position of mBot assembled motor
Basic functions
Forward, backward, left, right and rotate in position.
Advanced functions
Machine arms (shovel vehicle, brushing vehicle, drilling vehicle, gripping jaw vehicle... etc).
Basic functions ICCI mBot extended mechanism group
(Forward, Backward ,Left and Right)
46 Scratch (mBlock) Program Design — Using mBot Robot
Shovel vehicle Brushing vehicle
Drilling vehicle Gripping jaw vehicle
Self-propelled vehicle in Dark Face module + 5 sensors
Chapter 3 mBot Starts to Move 47
3-2
Controlling Motor Speed and Direction
To accurately control the mBot running “forward, backward, left, and right”, it is necessary to know
how to set the “speed” and “direction” of the mBlock program.
The first control method: "dual-motor" control through Block program.
There are four directions to the mBot moving mBot motor speed
The second control method: "single motor" control through Block program.
Motor connection port speed is equal and greater Motor connection port speed is equal to 0 (stop)
than 0 (forward)
Motor connection port 1 and2 at different speeds (turn) Motor connection port 1 and2 at different speeds (turn)
M 1> M 2 → Turn right M1 <M 2 → Turn left
Motor connection port speed is equal and less than 0 Motor connection port speed is equal but with one
(Backward) positive and with one negative (rotate in position)
Description
1. The speed ranges between: -255 ~ 255, where when there’s "negative power", the motor
will reverse in rotation, that is; the robot will run backward.
2. The larger the value, the faster it is.
48 Scratch (mBlock) Program Design — Using mBot Robot
Distance moved (determined by wheel size)
Distance moved = wheel circumference × number of rotations of the motor
The diameter is 6.5 cm.
wheel circumference = wheel diameter x Pi ( ≒ 3.14) = 6.5 x 3.14 ≒ 20 ㎝
Example 1
When the “button” is pressed, the mBot runs forward 1 second and runs backward for 1 second.
Answer
Flow chart mBlock program
When double-clicking the
“mBot program”
The judgment
button is pressed
True
Runs forward 1 second
Runs backward 1 second
mBot stops
Chapter 3 mBot Starts to Move 49
Example 2
Both wheels are turning and when the “button” is pressed, the mBot rotates right for 1 second and
then rotates left for 1 second.
Answer
Flow chart mBlock program
When double-clicking the
“mBot program”
The judgment
button is pressed
True
Rotates right 1 second
Rotates left 1 second
mBot stops
Example 3
One wheel is turning and when the “button” is pressed, the mBot turns right for 1 second and then
to left for 1 second.
Answer
Flow chart mBlock program
When double-clicking the
“mBot program”
The judgment
button is pressed
True
Turns right 1 second
Turns left 1 second
mBot stops
50 Scratch (mBlock) Program Design — Using mBot Robot