ENGG1320 - Graphical Programming
ENGG1320 - Graphical Programming
1 Objective
➢ Learn to use graphical programming for apps development
➢ Learn to use mBlock (v5) to develop an app for controlling Arduino-based products
2 Introduction
The mBlock, v5.3.5 used in this document, is a graphical programming environment based on Scratch 3.0
Open Source Project that makes it easy to program Arduino projects and create interactive applications.
The mBlock has the following features:
- scratch-style programming
- rich hardware support, such as Arduino Uno, Arduino Mega 2560, Raspberry Pi, BBC micro:bit, etc.
- real-time code generator
- all-in-one easy-to-use solution
- modular and expandable
- internationalization
Page 1 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
The brain in an mBot robot is an easy-to-use mCore control board, which is based on Arduino Uno, and
integrates various onboard sensors, such as a buzzer, light sensor, RGB LED, etc., which provides you with
an easier way to start learning electronics and developing interactive products. It has the following features:
2. Remove default devices (click on a cross symbol at the top-right corner of the device’s icon) from the
Devices Tab if it is not a “mBot”.
Page 3 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
3. Click the “Add” icon to add a new device. Click on “mBot” and highlight the star icon on the top-left
corner. Then, click the “OK” button to save and apply changes.
Page 4 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
5. Select the “USB” Tab. Select the correct Serial Port number and then click the “Connect” button.
Page 5 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
3. Select the “Bluetooth” Tab. Select correct mBot robot and then click the “Connect” button.
3. Select “2.4G” Tab. Select correct mBot robot and then click the “Connect” button.
Page 6 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
The factory firmware is a standalone firmware running in an mBot robot that has three standalone operation
modes. The operation mode named “Mode A” is a remote control driving mode. A user can use IR remote
controller to move the mBot robot. The operation mode named “Mode B” will move the mBot robot forward
until it detects an obstacle using an ultrasound distance sensor module. The operation mode named “Mode
C” is a simple line follower demonstration program. The mBot robot will move along a black line using a
line-follower sensor module.
Page 7 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 8 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 9 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 10 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
• Me 7-Segment Display-Red module adopts a 4-digit common-anode digital tube for displaying the numbers and
a few special characters
A Stack Block is a rectangular shaped block with a notch at the top and a
bump on the bottom that can fit above or below other blocks. Stack blocks are
used to execute commands.
A Reporter Block is a round-shaped block that stores a value that can be a
numerical value or character string. It can be configured to be accessed among
all scripts or just accessed within a single script. A reporter block must be put
into the round-shaped slot of another block, and therefore cannot be used
independently.
A Boolean Block is a hexagon-shaped block that contains a Boolean value
which can be either "true" or "false". A Boolean block must be put into the
hexagonal slot of another block, and therefore cannot be used independently.
A Cap Block is a rectangular shaped block with a notch at the top. It is used
at the end of a script, and therefore can be put only under all blocks.
Page 11 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Instruction block D
Page 12 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 13 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Broadcast a specific
message with an
associated value.
5.5.2 How to add “Upload Mode Broadcast” and “Maker’s Platform” extension
1. Select “Upload” mode
3. Click on the “Sprite Extensions” tab. Enter “upload” in the search bar and press the “enter” key. Click the “+
Add” button to add the “upload Mode Broadcast” extension for sprites.
Page 14 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
5. Click on the “Device Extensions” tab. Enter “upload” in the search bar and press the “enter” key. Click the “+
Add” button to add the “upload Mode Broadcast” extension for devices.
Page 15 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
7. Click on the “Device Extensions” tab. Look for the “Maker’s Platform” extension. Click the “+ Add” button to
add the “Maker’s Platform” extension for devices.
Page 16 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 17 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 18 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
End
Page 19 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 20 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 21 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
1. When first power up the robot, a variable “count” is initialised to zero and reset the timer.
2. Check how many times the onboard button is being pressed within 10 seconds.
3. When the green light is on, places the robot at the starting point of the runway.
4. Press the “B” button on IR remote controller. The robot will move forward for the number of seconds
according to the value of the variable “count” and then stop.
Page 22 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Begin
N
Does it reach
10 seconds?
Page 23 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
7.4 Trying to create an app that controls the moving of the robot
7.4.1 An mBot robot program
Script Script Description
Page 24 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
A Bluetooth controller must be paired with an mBot robot to establish a communication link. The communication
link will be auto-connected if the communication link is dropped.
2. Turn on an mBot robot without connecting a USB cable. The blue colour LED on the Bluetooth module will
blink slowly if it does not connect with a Bluetooth device.
3. Turn on a Bluetooth controller.
Page 25 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
4. Place Bluetooth Controller close to mBot robot, press the Bluetooth button on the controller until the indicator
blinks faster, and then release the button.
5. Pairing is automatically performed. The indicator is solid in blue if the pairing is successful.
A mBlock extension “Bluetooth controller” provides some blocks to check the status of buttons on the Bluetooth
controller and the reading of joysticks on the Bluetooth controller.
Page 26 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Page 27 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
8.4 Trying to create the app a simple app to control a robot using a Bluetooth controller
8.4.1 An mBot robot program
Script Script Description
Page 28 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
A line-follower sensor mounted on the bottom of an mBot robot is used for facilitating the robot to move on a black
line; its detection range is 1 to 2 cm. The line-follower sensor consists of two sensors named as Sensor 1 and 2. Each
sensor consists of an infrared emitter (IR LED) and an infrared receiver (Photodiode). The IR LED continually emits
infrared light when the mBot robot is powered on. If the infrared light is reflected (encountering white or other light
colour surfaces) to the photodiode with enough intensity, the sensor will output a logic value 1 (now you can see the
blue LED on the back of the line-follower sensor is lighted). If the infrared light is absorbed or cannot be reflected,
the sensor will not receive enough intensity and the output will be logic 0 (the blue LED on the back of the line-
follower sensor do not light).
According to the table, it can be known that the value of the line-follower sensor can be four only: 0, 1, 2, and 3.
Not Not
Situation 1 0 0 00 0
received received
Not
Situation 2 Received 0 1 01 1
received
Not
Situation 3 Received 1 0 10 2
received
Remark: When there is no object in front of the line-follower sensor or the object is far away from the sensor,
what value is on the line-follower sensor?
When there is no object or the object is far away from the sensor, the infrared light cannot be reflected or the signal
reflected is poor. It is deemed that Sensors 1 and 2 do not receive an infrared signal and the returned value is 0. So
according to Situation 1 in the above table, the value of the line-follower sensor should be 0.
Page 29 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
Knowledge point
The line-patrolling sensor is the best to identify pure white or black surface without reflection. Commonly you can
use black electrician tape to make a patrolling line on a light colour surface to achieve the best effects.
Page 30 of 31
ENGG1320 – Hands-on Project HH Cheung, IMSE
10 References
1. Makeblock mBot - Tutorial
http://docs.makeblock.com/mbot/en/
https://www.mblock.cc/doc/en/part-one-basics/basics.html
https://www.mblock.cc/doc/en/hardware-basic/interact-with-sprite.html
https://www.mblock.cc/doc/en/hardware-guide/bluetooth-controller/quick-start-guide.html
Page 31 of 31