SlideShare a Scribd company logo
1 of 61
Download to read offline
Skills Workshop: mBlock 5 and Arduino
Upon completion of this course, the participant will be able to:
i. Explain the fundamental of visual programming.
ii. Use algorithm and flowchart in basic programming.
iii. Demonstrate visual programming using mBlock.
iv. Identify feature of Arduino Uno.
v. Construct a system using Arduino Uno. Demonstrate a project using Arduino Uno with
mBlock.
SKILL MODULE: DIGITAL STEM
1
Contents
1.0 Introduction: Visual Programming ........................................................................................................2
2.0 The Algorithm, Flowchart and Programming........................................................................................7
3.0 Visual Programming: mBlock...............................................................................................................14
3.1 THE INTERFACE .....................................................................................................................................14
3.2 SPRITE PROGRAMMING........................................................................................................................16
i. Add a Sprite..........................................................................................................................................16
ii. Move the Sprite...................................................................................................................................18
iii. Add Sounds.........................................................................................................................................19
iv. Add a Costume ...................................................................................................................................22
Activity 1: Bouncing ball......................................................................................................................24
Activity 2: Bouncing ball with a static obstacle...................................................................................25
Activity 3: Bouncing ball with a moving obstacle ...............................................................................25
Activity 4: Complete bouncing ball game ...........................................................................................26
4.0 Programming Arduino..........................................................................................................................28
4.1 ARDUINO BOARD ..................................................................................................................................28
4.2 PROGRAM ARDUINO UNO USING MBLOCK 5.......................................................................................30
Activity 5: Blinking LED........................................................................................................................30
Activity 6: ON and OFF the LED with keyboard keys...........................................................................38
Exercise 1: Improve the program in Activity 6................................................................................42
Exercise 2: Create a mood lights based on the flowchart...............................................................43
Activity 7: Control LED using buttons in mBlock (virtual buttons)......................................................44
Activity 8: Integrate push button and buzzer .....................................................................................53
Exercise 3: Create a program to turn on/off an LED and buzzer using a single push button.........54
Activity 9: Turn on LED with a clap (using microphone).....................................................................54
4.3 INTEGRATE SENSORS AND ACTUATOR .................................................................................................56
Activity 10: Light sensor with LED.......................................................................................................56
Activity 11: Control Blinking LED with potentiometer........................................................................58
Exercise 4: Make some adjustment so that potentiometer able to control (ON/OFF) 3 LEDs.......59
Activity 12: Auto Awning System (using Light Dependent Resistor (LDR) and Servomotor)..............60
SKILL MODULE: DIGITAL STEM
2
1.0 Introduction: Visual Programming
i. What is programming
It is a field of skill that entails the creation of computer applications, websites, and software.
Programming is the creation of digital language. It provides a way for human to interact with the
computer through a set of instructions called code.
ii. Types of Programming
Text-based: programming language using script or text and think like computer
Visual-based: programming language using illustration that make sense to human
iii. Visual programming language
In computing, a visual programming language (VPL) is any programming language that lets users create
programs by manipulating program elements graphically rather than by specifying them textually. A
VPL allows programming with visual expressions, spatial arrangements of text and graphic symbols,
used either as elements of syntax or secondary notation. For example, many VPLs (known as dataflow
or diagrammatic programming) are based on the idea of "boxes and arrows", where boxes or other
screen objects are treated as entities, connected by arrows, lines or arcs which represent relations.
iv. Example of visual programming
It can be divided into a noted categories such as Educational, Multimedia, Video Games,
System/simulation, Automation, Data warehousing/ business intelligence. Refer to
https://en.wikipedia.org/wiki/Visual_programming_language
v. mBlock Installation
Step 1: Open the website: https://mblock.makeblock.com/en-us/download/
Figure 1: mBlock Download page
NOTE: Win7 or Win10 (64-bit are recommended)
Click this button to
Download
SKILL MODULE: DIGITAL STEM
3
Step 2: Double-click the .exe file.
Figure 2: mBlock .exe file
Step 3: Click Yes to start the Setup.
Figure 3: Download and setup windows
SKILL MODULE: DIGITAL STEM
4
Step 4: Click Finish to complete the Setup.
Figure 4: mBlock Setup completion
Step 5: Click INSTALL to install the driver so that the USB port can be used with external device.
Click OK if succesfully installed, and Exit (X) DriverSetup(X64).
Figure 5: Installation windows
SKILL MODULE: DIGITAL STEM
5
Step 6: The mBlock will upload with the complete interface.
Figure 6: Loading mBlock software
Figure 7: mBlock UI
The mBlock is loading.
The mBlock is ready.
SKILL MODULE: DIGITAL STEM
6
Step 7: Complete your profile by click the Login/Signup icon indicated.
Figure 8: Profile setup
Note: If you do not have the account, please setup your email in gmail.
Login/Signup icon.
SKILL MODULE: DIGITAL STEM
7
2.0 The Algorithm, Flowchart and Programming
Algorithm
It is a logical step-by-step approach to solve the problem. This is the first step in the process to solve a
mathematical or computer problem. An algorithm includes calculations, reasoning, and data processing.
Algorithms can be presented by natural languages, pseudocode, and flowcharts, etc.
According to Dr. Christoph Koutschan, a computer scientist working at the Research Institute for Symbolic
Computation (RISC) in Austria, he has surveyed voting for the important types of algorithms. As a result,
he has listed 32 crucial algorithms in computer science. Despite the complexity of algorithms, we can
generally divide algorithms into six fundamental types based on their function.
Pseudocode is an artificial and informal language that helps programmers develop algorithms.
Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably
straightforward. All statements showing "dependency" are to be indented.
Flowchart
A flowchart is the graphical or pictorial representation of an algorithm with the help of different symbols,
shapes, and arrows to demonstrate a process or a program. With algorithms, we can easily understand a
program. The main purpose of using a flowchart is to analyse different methods.
Terminal Box - Start / End
Input / Output
Process / Instruction
Decision
Connector / Arrow
https://www.edrawsoft.com/explain-algorithm-flowchart.html
SKILL MODULE: DIGITAL STEM
8
Basic Flow Control
Behind all of the software we use on a daily basis, there's a code being run with all sorts of terms
and symbols. Surprisingly, it can often be broken down into three simple programming structures
called Sequential, Selections, and Loops. These come together to form the most basic instructions
and algorithms for all types of software. There are three basic constructs in an algorithm.
1. Sequential - The simplest control statement. A sequence of sequential statements runs from the
top to bottom (from the first to the last block of flowchart). Runs exactly once. Example:
1) unlock the door
2) open the door
3) enter the room
4) switch on the light
5) close the door behind you
2. Selections (also known as decisions) ā€“ Is used to make choices based on information. Instead of
following a specific order of events, they ask a question in order to figure out which path to take
next. An algorithm can be made more intelligent or jump to different parts of the program.
if
if-else
switch (with cases)
The previous example about entering the room could be changed to consider for different
conditions. For instance, it could change to:
SKILL MODULE: DIGITAL STEM
9
1) IF the door is locked, then unlock the door, ELSE do nothing (go to next instruction)
2) IF the door is closed, then open the door, ELSE do nothing
3) Enter the room
4) IF the room is dark, then switch on the light, ELSE do nothing
5) Close the door behind you
The sequence of actions is carried out is selected based upon the information provided. The only
way for a computer to discover the circumstances is to collect inputs and compare it to known
values.
In this case, known values would be values such as 'locked' or 'unlocked', 'closed' or 'open'. The
computer looks at the door and checks to see if its current state matches 'closed' and 'locked'. If
it matches 'locked', the door needs to be unlocked. Otherwise, nothing should be done.
*CASE
The selection IF-THEN-ELSE is useful if the choices are binary, such as 'locked' or 'unlocked' ('yes'
or 'no').
The alternative to the IF-THEN-ELSE structure is the CASE structure. Using CASE, the algorithm
searches a list of options until it finds the correct condition. For example, on a multiple-choice
quiz, the answers might be A, B or C - the correct condition is either A, B or C.
SKILL MODULE: DIGITAL STEM
10
Basically, IF-THEN-ELSE looks for the correct option from two choices where CASE looks at the
correct option from multiple choices.
3. Loops (iteration) - The process of repeating sections of a program to achieve a particular target or
goal.
for
for-each (also known as range-based)
while
do-while
Computer programs can use different types of loops; infinite loops (repeat forever), count-
controlled loops (repeat a number of times) and condition-controlled loops (repeat until
something happens).
a. Infinite loops
A sequence on an infinite loop keeps repeating until the user terminates the program or it crashes.
For example, on a desktop computer, the operating system has a program that continually checks
your USB ports to see if you have plugged in a device. Even after you have plugged in a device, it
still continues to check for any new devices.
b. Count-controlled loop
Count-controlled loops are used to make a computer do the same thing a specific number of
times. The count-controlled loop can be described as a FOR loop. The program repeats the action
FOR a number of times. The count-controlled loop can be described as the FOR-NEXT structure.
The program repeats the action between the FOR and NEXT number of times.
c. Condition-controlled loops
A program could be made more intelligent by programming it to avoid hazards. For example, if
the robot vehicle is 3 cm from the edge of the table and you tell it to move forwards 5 cm, it will
drive off the edge of the table. To stop this from happening, you might write a condition-
controlled loop like this:
move forward
repeat until (touching table edge)
Condition-controlled loops can be used to add a high degree of intelligence to a computer
system.
SKILL MODULE: DIGITAL STEM
11
WHILE
Condition-controlled loops are also called WHILE loops or WHILE-ENDWHILE statements. A WHILE
loop code is repeated based on a certain condition. The condition could be 'true' or 'false'. The
WHILE loop executes while a condition is true. Whether the condition is met or not is checked at
the beginning of the loop. If the condition is 'true' it repeats, if not then the code is not executed.
DO WHILE
A similar condition-controlled loop is a DO WHILE loop. This method differs from a WHILE
condition-controlled loop in that the condition is checked at the end of the loop. If the condition
is ā€˜trueā€™, the loop repeats. Thus, the code in the loop is executed at least once.
SKILL MODULE: DIGITAL STEM
12
Infinite loops
Condition-controlled loops can result in intentional or unintentional infinite loops. If we wanted
to loop indefinitely, we could set a condition that would never be met, thus iterating infinitely.
The following examples would result in an infinite loop:
WHILE:
count = 1
while count <>0:
print(count)
count +=1
DO WHILE:
count = 1
do
print(count)
count+=1
while count <>0
REPEAT UNTIL:
count = 1
repeat
print(count)
count+=1
until count =0
It is important to check that the conditions we set can be met if we wish them to be.
Differentiating between the four types of loops
A count-controlled loop (FOR loop) iterates the number of times specified in the loop.
With a WHILE condition-controlled loop the iteration occurs indefinitely as long as the specified
condition is being met. If the condition is already met, the code in the loop is never executed.
With a DO WHILE condition-controlled loop the iteration occurs indefinitely as long as (or until)
the specified condition is met. The code in the loop is executed at least once.
SKILL MODULE: DIGITAL STEM
13
With a REPEAT UNTIL condition-controlled loop the iteration occurs indefinitely until the
specified condition is met. The code in the loop is executed at least once.
An infinite loop can occur with all condition-controlled loops but not with a count-controlled
loop.
https://www.bbc.co.uk/bitesize/guides/zrxncdm/revision/7
Exercise
1. Label the name of each flowchart structure.
2. Write pseudocode of SOP to enter the restaurant
a. Based on Sequential structure
b. Based on Selections structure (e.g. body temperature cannot exceed 37.5 ā°C)
c. Based on Loops structure (e.g. mysejahtera apps )
3. Repeat Exercise 3 for:
a. Manual/Smart Light.
b. Making an omelette
c. Boil water using Electronic Kettle
d. Calculate character ā€œaā€ in word ā€œkebangsaanā€.
Algorithm: a process or set of rules to be followed in calculations or other problem-solving operations,
especially by a computer
Pseudocode: Pseudocode is an artificial and informal language that helps programmers develop
algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are
reasonably straightforward. All statements showing "dependency" are to be indented.
Flowchart: A flowchart is simply a graphical representation of steps. It shows steps in sequential order
and is widely used in presenting the flow of algorithms, workflow or processes. Typically,
a flowchart shows the steps as boxes of various kinds, and their order by connecting them with arrows.
A B C
SKILL MODULE: DIGITAL STEM
14
3.0 Visual Programming: mBlock
3.1 THE INTERFACE
The user interface (UI) for mBlock is distributed into five major sections/area as follow.
1. Menu/Toolbar
No. Function Description
1 Language Change the UI language.
2 File
Create, open, save a project, import a project from your PC, or export your
project to PC.
3 Edit Turn on/off the stage turbo mode or hide/unhide the stage.
4 Title Set or change the title of the current project.
5 Save Save the current project to My Projects.
6 Publish Publish the current project to the mBlock community.
7 Courses Visit the website for courses available.
8 Tutorials View the online mBlock 5 help documents and example programs.
9 Feedback
Give your feedback to us. Your experience is what we care about. Any
feedback is welcome.
10
Sign up/
Sign in
Sign up an mBlock account or sign in. After signing in to mBlock 5, you can
click it to view your projects, profile, account center, and cloud service
authentication code, or click to sign out.
4. Stage
5.Panels
3.Scripts
2.Blocks
1.Menu/Toolbar
1 2 3 4 5 6 7 8 11
9 10
SKILL MODULE: DIGITAL STEM
15
11
Python
Editor
Enter mBlock-Python Editor.
2. Blocks
Blocks grouped by category with different color.
3. Scripts
Construct and compile program by dragging blocks to this area.
4. Stage
Present designs/animation (sprites) and test the program.
5. Panels
Edit the designs (edit sprites and background in stage) and connect to devices
(microcontroller).
https://www.yuque.com/makeblock-help-center-en/mblock-5/ui-navigation
SKILL MODULE: DIGITAL STEM
16
3.2 SPRITE PROGRAMMING
Lets learn how to program the sprite. Sprite is a computer graphic which may be moved on-screen
and otherwise manipulated as a single object.
i. Add a Sprite
a. Click Sprites under the stage and click + to add a sprite.
Note: The default sprite is Panda, and you can click Ɨin the upper right corner of the sprite to delete it.
b. Choose the sprite in the Sprite Library dialog box appears and click OK. Choose Bee1.
SKILL MODULE: DIGITAL STEM
17
c. Bee1 sprite appears on the stage.
SKILL MODULE: DIGITAL STEM
18
ii. Move the Sprite
a. Drag the Events block to the Scripts area.
b. Drag the Motion block and drop it under the current blocks.
c. Click the green flag under the stage to run it. Bee1 moves.
SKILL MODULE: DIGITAL STEM
19
iii. Add Sounds
a. Click Sounds on the Sprites tab.
b. Click Add Sound in the lower left corner.
SKILL MODULE: DIGITAL STEM
20
c. Choose the sound in the dialog box appears, and click OK.
d. The sound choose appears in the sound list. Click Ɨ to return to the editing page.
SKILL MODULE: DIGITAL STEM
21
e. Drag the Sound block and drop it under the current blocks, and then
choose ā€œChee Cheeā€ from the drop-down list box.
(6) Click the green flag in the lower right corner of the stage and see what happens.
SKILL MODULE: DIGITAL STEM
22
iv. Add a Costume
a. Click Costumes on the Sprites tab.
b. Click Add Costume in the lower left corner.
SKILL MODULE: DIGITAL STEM
23
c. Choose the costume in the dialog box appears, and click OK.
d. The costume choose appears in the sound list, and can be modified. Click Ɨ to return to the
editing page.
SKILL MODULE: DIGITAL STEM
24
e. Drag the Looks block and drop it under the current blocks.
e. Click the green flag in the lower right corner of the stage and observe what happens.
Activity 1: Bouncing ball
Able to add sprite, move and control it. Using forever loop control.
SKILL MODULE: DIGITAL STEM
25
Activity 2: Bouncing ball with a static obstacle
Able to add sprite custom made sprite and control it. Using single if loop control.
Activity 3: Bouncing ball with a moving obstacle
Able to control sprite to move it by key board.
SKILL MODULE: DIGITAL STEM
26
Activity 4: Complete bouncing ball game
Able to include additional control using multiple if loop.
Complete the program with the following scripting. Edit sprites ā€œBasketballā€ and ā€œGame Overā€.
SKILL MODULE: DIGITAL STEM
27
Review Questions:
1. How to adjust speed of the bouncing ball?
2. How to come out custom made shape sprite?
3. What game can you think you can make using mBlock?
SKILL MODULE: DIGITAL STEM
28
4.0 Programming Arduino
4.1 ARDUINO BOARD
Arduino is an open-source computer hardware and software company, project, and user
community that designs and manufactures single-board microcontrollers and microcontroller kits
for building digital devices and interactive objects that can sense and control objects in the physical
and digital world. Microcontroller is a compact integrated circuit designed to govern a specific
operation in an embedded system.
It is a micro-computer that can control and carry out data analysis. Famous microcontroller
manufacturers are MicroChip, Atmel, Intel, Analog devices, and more. A microcontroller board,
contains on-board power supply, USB port to communicate with PC, and a microcontroller chip.
In circuit serial
programming (ICSP)
Analog Inputs
Power Supply
5 V / 3.3 V / GND
External Power Supply
9 V to 12 V (ā‰„ 250 mA)
USB
Programming
Port (Type B)
Main MCU
Atmega328
Reset
Button
Digital Output ~ : PWM
0,1 : Serial Port (Rx, Tx)
Digital ground pin
Analog Ref. pin
SKILL MODULE: DIGITAL STEM
29
In order to design the system, we need a tools or software to communicate with the microcontroller
(Arduino). We can instruct the Arduino to do automation system. Figure 1 shows the overall Arduino
environment in general.
Figure 1: Arduino Environment
There are many ways to program the Arduino with different software features. Many software is widely
available as open-source such as mBLOCK and nodeRED other than Arduino IDE itself.
SKILL MODULE: DIGITAL STEM
30
4.2 PROGRAM ARDUINO UNO USING MBLOCK 5
mBlock 5 can be used to program hardware devices as well as sprites. This section uses Arduino
UNO board as an example. First, letā€™s think about how the flowchart look like for each activity.
Activity 5: Blinking LED
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
1 x LED
1 x 220 Ohms Resistor
1 x Bread Board
Figure 1: Arduino UNO wiring diagram for Blinking LED.
Hardware Procedure:
a. Connect all components according to wiring diagram in Figure 1.
b. Positive (+ / anode) of LED to 220 ohms resistor and digital Pin 12 on Arduino. Negative (- /
cathode) of LED to pin GND of Arduino.
Figure 2: LED terminals.
GND
5V Pin 12
SKILL MODULE: DIGITAL STEM
31
mBlock Procedure:
a. On the mBlock interface, click on add devices to add Arduino UNO.
Click on add
button.
Scroll and
choose
Arduino Uno
by clicking
on it. Then,
click ok.
SKILL MODULE: DIGITAL STEM
32
b. Start first block scripting of the Arduino UNO board on the script area.
c. On the Block Script menu, click Events.
d. Choose when Arduino Uno starts up by dragging the block script and drop to the script area.
Block
script
menu
Script
area
SKILL MODULE: DIGITAL STEM
33
e. On the Block Script menu, click on Control.
f. Choose forever loop by dragging the block script and drop under when Arduino Uno starts up
block.
SKILL MODULE: DIGITAL STEM
34
g. On the Block Script menu, click on Pin.
h. Choose block, drag and drop it in forever loop. Change the pin
value 9 to pin 12. Set the output as low.
i. On the Block Script menu, click Control.
j. Choose wait 1 seconds, drag and drop to script area.
k. Arrange all the block as follow.
l. Right click on the set digital pinā€™s block scripts, click on Duplicate to copy the block script set.
Drop the block script set copied.
Right click
block, select
Duplicate.
SKILL MODULE: DIGITAL STEM
35
m. Complete the whole block script as follow.
n. Setup the connection to Arduino board.
Make sure
Upload
button is set.
Then, click
Connect
button.
SKILL MODULE: DIGITAL STEM
36
o. Connection is successful. Arduino now connected to mBlock software and can be
programmed.
p. Upload the block script by clicking Upload button.
Tick Show all
connectable
devices.
Check the
Arduino
connected to
the serial port
(USB) available
and click
Connect.
Click Upload
to upload
block script.
SKILL MODULE: DIGITAL STEM
37
q. The Arduino Uno has been programed. Observe the outcome from the circuit. Try adjust
by changing the number, reupload the block script and observe the output.
SKILL MODULE: DIGITAL STEM
38
Activity 6: ON and OFF the LED with keyboard keys
a. On the mBlock panel, click Sprite. From block script menu, click extension.
b. Select and click + Add for Upload Mode Boardcast extension.
i) Click
Sprite.
ii) Then, click
extension.
SKILL MODULE: DIGITAL STEM
39
c. On the mBlock panel, click Sprite. From block script menu, click Events and choose
by dragging the block script and drop to the script area.
d. On block script menu, click Upload Mode Broadcast and choose by
dragging the block script and drop to the script area. Edit the statement by replacing
ā€œmessageā€ with ā€œONā€.
iii) Drag and
position the
block here.
Edit
statement
to ON.
i) Select
Upload
Mode
Broadcast.
ii) Choose
this block.
SKILL MODULE: DIGITAL STEM
40
e. Duplicate the first block scripts and change space to alphabet a and edit the upload message
to OFF.
f. Select Devices in mBlock panel and click Arduino Uno. From block script menu, click extension.
Select and click + Add for Upload Mode Boardcast extension (same as step b.).
ii) Change to
character a.
iii) Edit
statement
to OFF.
i) Right-click,
and select
duplicate.
SKILL MODULE: DIGITAL STEM
41
g. Select Upload Mode Broadcast.
i) Choose
this block.
iii) Edit
statement
to ON.
i) Select
Upload
Mode
Broadcast
.
iv) Select Pin.
v) Choose
this block.
iii) Set the
output as
HIGH.
SKILL MODULE: DIGITAL STEM
42
h. Complete the block script as follow.
i. Upload the block script by clicking Upload button. Now we can control LED from keyboard.
Exercise 1: Improve the program in Activity 6
Improve the block script so that the LED can be control with three options.
1. ON ā€“ turn ON the LED
2. OFF ā€“ turn OFF the LED
3. Blink ā€“ set the LED ON for 1s and OFF for 2s.
SKILL MODULE: DIGITAL STEM
43
Exercise 2: Create a mood lights based on the flowchart
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
3 x LED (different color)
3 x 220 Ohms Resistor
1 x Bread Board
Circuit Diagram:
Blue LED Green LED Red LED
Key A ON OFF OFF
Key S OFF ON OFF
Key D OFF OFF ON
Flowchart:
Note: This flowchart still can be improved.
3
5
6
SKILL MODULE: DIGITAL STEM
44
Activity 7: Control LED using buttons in mBlock (virtual buttons)
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
1 x LED
1 x 220 Ohms Resistor
1 x Bread Board
Circuit Diagram:
Figure Activity 7: ON and OFF using button in mBlock
Hardware Procedure:
a. Connect all components according to wiring diagram in Figure.
b. Positive (+ / anode) of LED to 220 ohms resistor and digital Pin 12 on Arduino. Negative (- /
cathode) of LED to pin GND of Arduino.
SKILL MODULE: DIGITAL STEM
45
mBlock Procedure:
a. Select Background from mBlock panel. Click on + sign to add background to mBlock user
interface in Stage.
b. We can choose any available background or we can create custom made background by
clicking My Backdrops. Choose any background and click ok.
i) Select
Background.
ii) Click this
add button.
SKILL MODULE: DIGITAL STEM
46
c. The background should have changed with the one we selected. To adjust view of the stage,
select one of the buttons below the stage.
d. Now, we need to create our button in the stage. Click add button in Sprite panel.
Options to
view stage.
Click add
button.
SKILL MODULE: DIGITAL STEM
47
e. In Sprite library, click on Icons. Choose any button you like. In this example we choose Empty
button14 and click OK. Get one more button with the same design.
f. We can change the sprite button name. Letā€™s name it on button and off button respectively.
We can edit the label on the sprite buttons by clicking Costumes.
Select
button
design
and click
OK.
Select
button
design
and click
OK.
i) Edit
name for
the sprite
button.
ii) Redesign
the button
by clicking
Costumes
for selected
sprite .
SKILL MODULE: DIGITAL STEM
48
g. Select on button sprite and click Costumes. Click on Text symbol and locate cursor on button.
Type in ā€œONā€. We can edit the font such as color and type.
h. Edit color of on button by click Select editor and click the button. Change Fill color to green.
Click X button to complete the sprite editing.
i) Select
on_button
sprite.
iii) Type in
ā€œONā€ for this
button
ii) Select
Text
editor.
i) Click
Select
editor. ii) Select
green
color in
Fill.
iii) Click X to
close editing.
SKILL MODULE: DIGITAL STEM
49
i. Repeat the same process (step g and h) to edit the off button. Here how the stage and
sprites look like.
j. Click on-button sprite in Sprite panel. Click Events in Script Block. Drag the block
in scripting area.
ii) Select
Events
blocks.
iii) Drag and
drop the block.
i) Click on-button
sprite in Sprite
panel.
SKILL MODULE: DIGITAL STEM
50
k. Select Sound in Script Block menu. Click on and drag the block script to scripting
area.
l. Click on Upload Mode Broadcast in Script Block Menu. Select and
drag-drop on scripting area.
i) Select
Sound
blocks. ii) Drag and
drop the block.
ii) Drag and
drop the block.
Edit message to
ā€œONā€.
i) Select
Upload
Mode
Broadcast
blocks.
SKILL MODULE: DIGITAL STEM
51
m. Carry out the same scripting process for off-button. Click off-button sprite and prepare the
program as follow.
n. We can add another animated feature in stage. Click on Panda sprite to start block scripting.
Complete the block scripting as follow.
SKILL MODULE: DIGITAL STEM
52
o. Click on Devices and select Arduino UNO. Complete the block scripting as follow and upload
it into Arduino UNO. Click on the spite in the stage area.
SKILL MODULE: DIGITAL STEM
53
Activity 8: Integrate push button and buzzer
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
1 x 4 pins push button
1 x Buzzer
1 x 1k Ohms Resistor
1 x Bread Board
Circuit Diagram:
mBlock Scripting:
Build the block scripting below and upload it into Arduino UNO. Observe the output.
4
8
SKILL MODULE: DIGITAL STEM
54
Exercise 3: Create a program to turn on/off an LED and buzzer using a single push button.
Activity 9: Turn on LED with a clap (using microphone).
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
1 x 220 Ohms Resistor
1 x LED
1 x Bread Board
Circuit diagram:
mBlock Scripts:
Complete the following block scripts and upload it into Arduino UNO. Observe the output.
1. Sprite > Events > When loudness 50
2. Sprite > Upload Mode Boardcast > send upload mode message ON
12
SKILL MODULE: DIGITAL STEM
55
1. Devices > Arduino Uno > Upload Mode Boardcast > when receiving upload mode message ON
2. Devices > Arduino Uno > Pin > set digital pin 12 output as high
3. Devices > Arduino Uno > Control > wait 1 seconds
4. Devices > Arduino Uno > Pin > set digital pin 12 output as low
SKILL MODULE: DIGITAL STEM
56
4.3 INTEGRATE SENSORS AND ACTUATOR
Activity 10: Light sensor with LED
Components: 1 x Arduino UNO
1 x USB Type-B Cable
Male-male jumper wires
1 x 10k Ohms Resistor
1 x 220 Ohms Resistor
1 x LED
1 x Light Dependent Resistor (LDR)
1 x Bread Board
Circuit diagram:
mBlock Scripting:
Complete the following block scripts and upload it into Arduino UNO. Observe the output.
4
A0
GND
5V
- +
SKILL MODULE: DIGITAL STEM
57
Expected output:
SKILL MODULE: DIGITAL STEM
58
Activity 11: Control Blinking LED with potentiometer
We going to create a display and Arduino to convert analog value from potentiometer to value
second. The value second will be used to control duration of blinking LED.
SKILL MODULE: DIGITAL STEM
59
mBlock Scripting:
1. Complete the following block scripts for Arduino UNO under devices.
2. Add block scripts for Panda sprite as follow.
3. Add another sprite Bear3 and build block scripts as follow.
Reading on potentiometer is from 0 to 1023. We need to map it for each duration.
Exercise 4: Make some adjustment so that potentiometer able to control (ON/OFF) 3 LEDs.
Yellow LED ON when Potentiometer at level 1 to 2
Green LED ON when Potentiometer at level 3
Red LED ON when Potentiometer at level 4 to 5.
SKILL MODULE: DIGITAL STEM
60
Activity 12: Auto Awning System (using Light Dependent Resistor (LDR) and Servomotor)
Circuit: Build the circuit as in Diagram below.
mBlock scripting:
1. Block scripts for sprite.
2. Block scripts for Arduino UNO devices.
Note: Use ā€œif-elseā€ to control servo motor with control threshold for LDR is 100. You can adjust this threshold for
sensitivity of the system.

More Related Content

Similar to Modul mBlock 5 and arduino.pdf

A Practical Introduction To Hardware Software Codesign
A Practical Introduction To Hardware Software CodesignA Practical Introduction To Hardware Software Codesign
A Practical Introduction To Hardware Software CodesignFelicia Clark
Ā 
Finding Resource Manipulation Bugs in Linux Code
Finding Resource Manipulation Bugs in Linux CodeFinding Resource Manipulation Bugs in Linux Code
Finding Resource Manipulation Bugs in Linux CodeAndrzej Wasowski
Ā 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
Ā 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report Dileep Maurya
Ā 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5Alok Jain
Ā 
Software engineering
Software engineeringSoftware engineering
Software engineeringFahe Em
Ā 
Software engineering
Software engineeringSoftware engineering
Software engineeringFahe Em
Ā 
Basics of Programming
Basics of ProgrammingBasics of Programming
Basics of ProgrammingAkNirojan
Ā 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
Ā 
Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxAdam Englander
Ā 
Physical Computing
Physical ComputingPhysical Computing
Physical Computingkturvey
Ā 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfjaymaraltamera
Ā 
An introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cAn introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cSuresh Murugesan
Ā 
Emotion recognition from facial expression using fuzzy logic
Emotion recognition from facial expression using fuzzy logicEmotion recognition from facial expression using fuzzy logic
Emotion recognition from facial expression using fuzzy logicFinalyear Projects
Ā 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsOMWOMA JACKSON
Ā 
Coding And Robotics Presentation 1.4 2024.pptx
Coding And Robotics Presentation 1.4 2024.pptxCoding And Robotics Presentation 1.4 2024.pptx
Coding And Robotics Presentation 1.4 2024.pptxodhiambojoseph281
Ā 

Similar to Modul mBlock 5 and arduino.pdf (20)

A Practical Introduction To Hardware Software Codesign
A Practical Introduction To Hardware Software CodesignA Practical Introduction To Hardware Software Codesign
A Practical Introduction To Hardware Software Codesign
Ā 
Finding Resource Manipulation Bugs in Linux Code
Finding Resource Manipulation Bugs in Linux CodeFinding Resource Manipulation Bugs in Linux Code
Finding Resource Manipulation Bugs in Linux Code
Ā 
Mca 504 dotnet_unit1
Mca 504 dotnet_unit1Mca 504 dotnet_unit1
Mca 504 dotnet_unit1
Ā 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
Ā 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
Ā 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
Ā 
PROBLEM SOLVING
PROBLEM SOLVINGPROBLEM SOLVING
PROBLEM SOLVING
Ā 
Software engineering
Software engineeringSoftware engineering
Software engineering
Ā 
Software engineering
Software engineeringSoftware engineering
Software engineering
Ā 
Basics of Programming
Basics of ProgrammingBasics of Programming
Basics of Programming
Ā 
scratch-3-tutorial.pdf
scratch-3-tutorial.pdfscratch-3-tutorial.pdf
scratch-3-tutorial.pdf
Ā 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
Ā 
Beekman5 std ppt_13
Beekman5 std ppt_13Beekman5 std ppt_13
Beekman5 std ppt_13
Ā 
Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
Ā 
Physical Computing
Physical ComputingPhysical Computing
Physical Computing
Ā 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
Ā 
An introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cAn introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_c
Ā 
Emotion recognition from facial expression using fuzzy logic
Emotion recognition from facial expression using fuzzy logicEmotion recognition from facial expression using fuzzy logic
Emotion recognition from facial expression using fuzzy logic
Ā 
structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
Ā 
Coding And Robotics Presentation 1.4 2024.pptx
Coding And Robotics Presentation 1.4 2024.pptxCoding And Robotics Presentation 1.4 2024.pptx
Coding And Robotics Presentation 1.4 2024.pptx
Ā 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
Ā 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
Ā 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
Ā 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
Ā 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
Ā 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
Ā 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
Ā 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
Ā 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
Ā 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
Ā 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
Ā 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
Ā 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
Ā 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
Ā 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
Ā 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
Ā 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Ā 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
Ā 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
Ā 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
Ā 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
Ā 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
Ā 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
Ā 
Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Ā 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Ā 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
Ā 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
Ā 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
Ā 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
Ā 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Ā 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
Ā 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
Ā 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
Ā 

Modul mBlock 5 and arduino.pdf

  • 1. Skills Workshop: mBlock 5 and Arduino Upon completion of this course, the participant will be able to: i. Explain the fundamental of visual programming. ii. Use algorithm and flowchart in basic programming. iii. Demonstrate visual programming using mBlock. iv. Identify feature of Arduino Uno. v. Construct a system using Arduino Uno. Demonstrate a project using Arduino Uno with mBlock.
  • 2. SKILL MODULE: DIGITAL STEM 1 Contents 1.0 Introduction: Visual Programming ........................................................................................................2 2.0 The Algorithm, Flowchart and Programming........................................................................................7 3.0 Visual Programming: mBlock...............................................................................................................14 3.1 THE INTERFACE .....................................................................................................................................14 3.2 SPRITE PROGRAMMING........................................................................................................................16 i. Add a Sprite..........................................................................................................................................16 ii. Move the Sprite...................................................................................................................................18 iii. Add Sounds.........................................................................................................................................19 iv. Add a Costume ...................................................................................................................................22 Activity 1: Bouncing ball......................................................................................................................24 Activity 2: Bouncing ball with a static obstacle...................................................................................25 Activity 3: Bouncing ball with a moving obstacle ...............................................................................25 Activity 4: Complete bouncing ball game ...........................................................................................26 4.0 Programming Arduino..........................................................................................................................28 4.1 ARDUINO BOARD ..................................................................................................................................28 4.2 PROGRAM ARDUINO UNO USING MBLOCK 5.......................................................................................30 Activity 5: Blinking LED........................................................................................................................30 Activity 6: ON and OFF the LED with keyboard keys...........................................................................38 Exercise 1: Improve the program in Activity 6................................................................................42 Exercise 2: Create a mood lights based on the flowchart...............................................................43 Activity 7: Control LED using buttons in mBlock (virtual buttons)......................................................44 Activity 8: Integrate push button and buzzer .....................................................................................53 Exercise 3: Create a program to turn on/off an LED and buzzer using a single push button.........54 Activity 9: Turn on LED with a clap (using microphone).....................................................................54 4.3 INTEGRATE SENSORS AND ACTUATOR .................................................................................................56 Activity 10: Light sensor with LED.......................................................................................................56 Activity 11: Control Blinking LED with potentiometer........................................................................58 Exercise 4: Make some adjustment so that potentiometer able to control (ON/OFF) 3 LEDs.......59 Activity 12: Auto Awning System (using Light Dependent Resistor (LDR) and Servomotor)..............60
  • 3. SKILL MODULE: DIGITAL STEM 2 1.0 Introduction: Visual Programming i. What is programming It is a field of skill that entails the creation of computer applications, websites, and software. Programming is the creation of digital language. It provides a way for human to interact with the computer through a set of instructions called code. ii. Types of Programming Text-based: programming language using script or text and think like computer Visual-based: programming language using illustration that make sense to human iii. Visual programming language In computing, a visual programming language (VPL) is any programming language that lets users create programs by manipulating program elements graphically rather than by specifying them textually. A VPL allows programming with visual expressions, spatial arrangements of text and graphic symbols, used either as elements of syntax or secondary notation. For example, many VPLs (known as dataflow or diagrammatic programming) are based on the idea of "boxes and arrows", where boxes or other screen objects are treated as entities, connected by arrows, lines or arcs which represent relations. iv. Example of visual programming It can be divided into a noted categories such as Educational, Multimedia, Video Games, System/simulation, Automation, Data warehousing/ business intelligence. Refer to https://en.wikipedia.org/wiki/Visual_programming_language v. mBlock Installation Step 1: Open the website: https://mblock.makeblock.com/en-us/download/ Figure 1: mBlock Download page NOTE: Win7 or Win10 (64-bit are recommended) Click this button to Download
  • 4. SKILL MODULE: DIGITAL STEM 3 Step 2: Double-click the .exe file. Figure 2: mBlock .exe file Step 3: Click Yes to start the Setup. Figure 3: Download and setup windows
  • 5. SKILL MODULE: DIGITAL STEM 4 Step 4: Click Finish to complete the Setup. Figure 4: mBlock Setup completion Step 5: Click INSTALL to install the driver so that the USB port can be used with external device. Click OK if succesfully installed, and Exit (X) DriverSetup(X64). Figure 5: Installation windows
  • 6. SKILL MODULE: DIGITAL STEM 5 Step 6: The mBlock will upload with the complete interface. Figure 6: Loading mBlock software Figure 7: mBlock UI The mBlock is loading. The mBlock is ready.
  • 7. SKILL MODULE: DIGITAL STEM 6 Step 7: Complete your profile by click the Login/Signup icon indicated. Figure 8: Profile setup Note: If you do not have the account, please setup your email in gmail. Login/Signup icon.
  • 8. SKILL MODULE: DIGITAL STEM 7 2.0 The Algorithm, Flowchart and Programming Algorithm It is a logical step-by-step approach to solve the problem. This is the first step in the process to solve a mathematical or computer problem. An algorithm includes calculations, reasoning, and data processing. Algorithms can be presented by natural languages, pseudocode, and flowcharts, etc. According to Dr. Christoph Koutschan, a computer scientist working at the Research Institute for Symbolic Computation (RISC) in Austria, he has surveyed voting for the important types of algorithms. As a result, he has listed 32 crucial algorithms in computer science. Despite the complexity of algorithms, we can generally divide algorithms into six fundamental types based on their function. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. Flowchart A flowchart is the graphical or pictorial representation of an algorithm with the help of different symbols, shapes, and arrows to demonstrate a process or a program. With algorithms, we can easily understand a program. The main purpose of using a flowchart is to analyse different methods. Terminal Box - Start / End Input / Output Process / Instruction Decision Connector / Arrow https://www.edrawsoft.com/explain-algorithm-flowchart.html
  • 9. SKILL MODULE: DIGITAL STEM 8 Basic Flow Control Behind all of the software we use on a daily basis, there's a code being run with all sorts of terms and symbols. Surprisingly, it can often be broken down into three simple programming structures called Sequential, Selections, and Loops. These come together to form the most basic instructions and algorithms for all types of software. There are three basic constructs in an algorithm. 1. Sequential - The simplest control statement. A sequence of sequential statements runs from the top to bottom (from the first to the last block of flowchart). Runs exactly once. Example: 1) unlock the door 2) open the door 3) enter the room 4) switch on the light 5) close the door behind you 2. Selections (also known as decisions) ā€“ Is used to make choices based on information. Instead of following a specific order of events, they ask a question in order to figure out which path to take next. An algorithm can be made more intelligent or jump to different parts of the program. if if-else switch (with cases) The previous example about entering the room could be changed to consider for different conditions. For instance, it could change to:
  • 10. SKILL MODULE: DIGITAL STEM 9 1) IF the door is locked, then unlock the door, ELSE do nothing (go to next instruction) 2) IF the door is closed, then open the door, ELSE do nothing 3) Enter the room 4) IF the room is dark, then switch on the light, ELSE do nothing 5) Close the door behind you The sequence of actions is carried out is selected based upon the information provided. The only way for a computer to discover the circumstances is to collect inputs and compare it to known values. In this case, known values would be values such as 'locked' or 'unlocked', 'closed' or 'open'. The computer looks at the door and checks to see if its current state matches 'closed' and 'locked'. If it matches 'locked', the door needs to be unlocked. Otherwise, nothing should be done. *CASE The selection IF-THEN-ELSE is useful if the choices are binary, such as 'locked' or 'unlocked' ('yes' or 'no'). The alternative to the IF-THEN-ELSE structure is the CASE structure. Using CASE, the algorithm searches a list of options until it finds the correct condition. For example, on a multiple-choice quiz, the answers might be A, B or C - the correct condition is either A, B or C.
  • 11. SKILL MODULE: DIGITAL STEM 10 Basically, IF-THEN-ELSE looks for the correct option from two choices where CASE looks at the correct option from multiple choices. 3. Loops (iteration) - The process of repeating sections of a program to achieve a particular target or goal. for for-each (also known as range-based) while do-while Computer programs can use different types of loops; infinite loops (repeat forever), count- controlled loops (repeat a number of times) and condition-controlled loops (repeat until something happens). a. Infinite loops A sequence on an infinite loop keeps repeating until the user terminates the program or it crashes. For example, on a desktop computer, the operating system has a program that continually checks your USB ports to see if you have plugged in a device. Even after you have plugged in a device, it still continues to check for any new devices. b. Count-controlled loop Count-controlled loops are used to make a computer do the same thing a specific number of times. The count-controlled loop can be described as a FOR loop. The program repeats the action FOR a number of times. The count-controlled loop can be described as the FOR-NEXT structure. The program repeats the action between the FOR and NEXT number of times. c. Condition-controlled loops A program could be made more intelligent by programming it to avoid hazards. For example, if the robot vehicle is 3 cm from the edge of the table and you tell it to move forwards 5 cm, it will drive off the edge of the table. To stop this from happening, you might write a condition- controlled loop like this: move forward repeat until (touching table edge) Condition-controlled loops can be used to add a high degree of intelligence to a computer system.
  • 12. SKILL MODULE: DIGITAL STEM 11 WHILE Condition-controlled loops are also called WHILE loops or WHILE-ENDWHILE statements. A WHILE loop code is repeated based on a certain condition. The condition could be 'true' or 'false'. The WHILE loop executes while a condition is true. Whether the condition is met or not is checked at the beginning of the loop. If the condition is 'true' it repeats, if not then the code is not executed. DO WHILE A similar condition-controlled loop is a DO WHILE loop. This method differs from a WHILE condition-controlled loop in that the condition is checked at the end of the loop. If the condition is ā€˜trueā€™, the loop repeats. Thus, the code in the loop is executed at least once.
  • 13. SKILL MODULE: DIGITAL STEM 12 Infinite loops Condition-controlled loops can result in intentional or unintentional infinite loops. If we wanted to loop indefinitely, we could set a condition that would never be met, thus iterating infinitely. The following examples would result in an infinite loop: WHILE: count = 1 while count <>0: print(count) count +=1 DO WHILE: count = 1 do print(count) count+=1 while count <>0 REPEAT UNTIL: count = 1 repeat print(count) count+=1 until count =0 It is important to check that the conditions we set can be met if we wish them to be. Differentiating between the four types of loops A count-controlled loop (FOR loop) iterates the number of times specified in the loop. With a WHILE condition-controlled loop the iteration occurs indefinitely as long as the specified condition is being met. If the condition is already met, the code in the loop is never executed. With a DO WHILE condition-controlled loop the iteration occurs indefinitely as long as (or until) the specified condition is met. The code in the loop is executed at least once.
  • 14. SKILL MODULE: DIGITAL STEM 13 With a REPEAT UNTIL condition-controlled loop the iteration occurs indefinitely until the specified condition is met. The code in the loop is executed at least once. An infinite loop can occur with all condition-controlled loops but not with a count-controlled loop. https://www.bbc.co.uk/bitesize/guides/zrxncdm/revision/7 Exercise 1. Label the name of each flowchart structure. 2. Write pseudocode of SOP to enter the restaurant a. Based on Sequential structure b. Based on Selections structure (e.g. body temperature cannot exceed 37.5 ā°C) c. Based on Loops structure (e.g. mysejahtera apps ) 3. Repeat Exercise 3 for: a. Manual/Smart Light. b. Making an omelette c. Boil water using Electronic Kettle d. Calculate character ā€œaā€ in word ā€œkebangsaanā€. Algorithm: a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer Pseudocode: Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. Flowchart: A flowchart is simply a graphical representation of steps. It shows steps in sequential order and is widely used in presenting the flow of algorithms, workflow or processes. Typically, a flowchart shows the steps as boxes of various kinds, and their order by connecting them with arrows. A B C
  • 15. SKILL MODULE: DIGITAL STEM 14 3.0 Visual Programming: mBlock 3.1 THE INTERFACE The user interface (UI) for mBlock is distributed into five major sections/area as follow. 1. Menu/Toolbar No. Function Description 1 Language Change the UI language. 2 File Create, open, save a project, import a project from your PC, or export your project to PC. 3 Edit Turn on/off the stage turbo mode or hide/unhide the stage. 4 Title Set or change the title of the current project. 5 Save Save the current project to My Projects. 6 Publish Publish the current project to the mBlock community. 7 Courses Visit the website for courses available. 8 Tutorials View the online mBlock 5 help documents and example programs. 9 Feedback Give your feedback to us. Your experience is what we care about. Any feedback is welcome. 10 Sign up/ Sign in Sign up an mBlock account or sign in. After signing in to mBlock 5, you can click it to view your projects, profile, account center, and cloud service authentication code, or click to sign out. 4. Stage 5.Panels 3.Scripts 2.Blocks 1.Menu/Toolbar 1 2 3 4 5 6 7 8 11 9 10
  • 16. SKILL MODULE: DIGITAL STEM 15 11 Python Editor Enter mBlock-Python Editor. 2. Blocks Blocks grouped by category with different color. 3. Scripts Construct and compile program by dragging blocks to this area. 4. Stage Present designs/animation (sprites) and test the program. 5. Panels Edit the designs (edit sprites and background in stage) and connect to devices (microcontroller). https://www.yuque.com/makeblock-help-center-en/mblock-5/ui-navigation
  • 17. SKILL MODULE: DIGITAL STEM 16 3.2 SPRITE PROGRAMMING Lets learn how to program the sprite. Sprite is a computer graphic which may be moved on-screen and otherwise manipulated as a single object. i. Add a Sprite a. Click Sprites under the stage and click + to add a sprite. Note: The default sprite is Panda, and you can click Ɨin the upper right corner of the sprite to delete it. b. Choose the sprite in the Sprite Library dialog box appears and click OK. Choose Bee1.
  • 18. SKILL MODULE: DIGITAL STEM 17 c. Bee1 sprite appears on the stage.
  • 19. SKILL MODULE: DIGITAL STEM 18 ii. Move the Sprite a. Drag the Events block to the Scripts area. b. Drag the Motion block and drop it under the current blocks. c. Click the green flag under the stage to run it. Bee1 moves.
  • 20. SKILL MODULE: DIGITAL STEM 19 iii. Add Sounds a. Click Sounds on the Sprites tab. b. Click Add Sound in the lower left corner.
  • 21. SKILL MODULE: DIGITAL STEM 20 c. Choose the sound in the dialog box appears, and click OK. d. The sound choose appears in the sound list. Click Ɨ to return to the editing page.
  • 22. SKILL MODULE: DIGITAL STEM 21 e. Drag the Sound block and drop it under the current blocks, and then choose ā€œChee Cheeā€ from the drop-down list box. (6) Click the green flag in the lower right corner of the stage and see what happens.
  • 23. SKILL MODULE: DIGITAL STEM 22 iv. Add a Costume a. Click Costumes on the Sprites tab. b. Click Add Costume in the lower left corner.
  • 24. SKILL MODULE: DIGITAL STEM 23 c. Choose the costume in the dialog box appears, and click OK. d. The costume choose appears in the sound list, and can be modified. Click Ɨ to return to the editing page.
  • 25. SKILL MODULE: DIGITAL STEM 24 e. Drag the Looks block and drop it under the current blocks. e. Click the green flag in the lower right corner of the stage and observe what happens. Activity 1: Bouncing ball Able to add sprite, move and control it. Using forever loop control.
  • 26. SKILL MODULE: DIGITAL STEM 25 Activity 2: Bouncing ball with a static obstacle Able to add sprite custom made sprite and control it. Using single if loop control. Activity 3: Bouncing ball with a moving obstacle Able to control sprite to move it by key board.
  • 27. SKILL MODULE: DIGITAL STEM 26 Activity 4: Complete bouncing ball game Able to include additional control using multiple if loop. Complete the program with the following scripting. Edit sprites ā€œBasketballā€ and ā€œGame Overā€.
  • 28. SKILL MODULE: DIGITAL STEM 27 Review Questions: 1. How to adjust speed of the bouncing ball? 2. How to come out custom made shape sprite? 3. What game can you think you can make using mBlock?
  • 29. SKILL MODULE: DIGITAL STEM 28 4.0 Programming Arduino 4.1 ARDUINO BOARD Arduino is an open-source computer hardware and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical and digital world. Microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. It is a micro-computer that can control and carry out data analysis. Famous microcontroller manufacturers are MicroChip, Atmel, Intel, Analog devices, and more. A microcontroller board, contains on-board power supply, USB port to communicate with PC, and a microcontroller chip. In circuit serial programming (ICSP) Analog Inputs Power Supply 5 V / 3.3 V / GND External Power Supply 9 V to 12 V (ā‰„ 250 mA) USB Programming Port (Type B) Main MCU Atmega328 Reset Button Digital Output ~ : PWM 0,1 : Serial Port (Rx, Tx) Digital ground pin Analog Ref. pin
  • 30. SKILL MODULE: DIGITAL STEM 29 In order to design the system, we need a tools or software to communicate with the microcontroller (Arduino). We can instruct the Arduino to do automation system. Figure 1 shows the overall Arduino environment in general. Figure 1: Arduino Environment There are many ways to program the Arduino with different software features. Many software is widely available as open-source such as mBLOCK and nodeRED other than Arduino IDE itself.
  • 31. SKILL MODULE: DIGITAL STEM 30 4.2 PROGRAM ARDUINO UNO USING MBLOCK 5 mBlock 5 can be used to program hardware devices as well as sprites. This section uses Arduino UNO board as an example. First, letā€™s think about how the flowchart look like for each activity. Activity 5: Blinking LED Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 1 x LED 1 x 220 Ohms Resistor 1 x Bread Board Figure 1: Arduino UNO wiring diagram for Blinking LED. Hardware Procedure: a. Connect all components according to wiring diagram in Figure 1. b. Positive (+ / anode) of LED to 220 ohms resistor and digital Pin 12 on Arduino. Negative (- / cathode) of LED to pin GND of Arduino. Figure 2: LED terminals. GND 5V Pin 12
  • 32. SKILL MODULE: DIGITAL STEM 31 mBlock Procedure: a. On the mBlock interface, click on add devices to add Arduino UNO. Click on add button. Scroll and choose Arduino Uno by clicking on it. Then, click ok.
  • 33. SKILL MODULE: DIGITAL STEM 32 b. Start first block scripting of the Arduino UNO board on the script area. c. On the Block Script menu, click Events. d. Choose when Arduino Uno starts up by dragging the block script and drop to the script area. Block script menu Script area
  • 34. SKILL MODULE: DIGITAL STEM 33 e. On the Block Script menu, click on Control. f. Choose forever loop by dragging the block script and drop under when Arduino Uno starts up block.
  • 35. SKILL MODULE: DIGITAL STEM 34 g. On the Block Script menu, click on Pin. h. Choose block, drag and drop it in forever loop. Change the pin value 9 to pin 12. Set the output as low. i. On the Block Script menu, click Control. j. Choose wait 1 seconds, drag and drop to script area. k. Arrange all the block as follow. l. Right click on the set digital pinā€™s block scripts, click on Duplicate to copy the block script set. Drop the block script set copied. Right click block, select Duplicate.
  • 36. SKILL MODULE: DIGITAL STEM 35 m. Complete the whole block script as follow. n. Setup the connection to Arduino board. Make sure Upload button is set. Then, click Connect button.
  • 37. SKILL MODULE: DIGITAL STEM 36 o. Connection is successful. Arduino now connected to mBlock software and can be programmed. p. Upload the block script by clicking Upload button. Tick Show all connectable devices. Check the Arduino connected to the serial port (USB) available and click Connect. Click Upload to upload block script.
  • 38. SKILL MODULE: DIGITAL STEM 37 q. The Arduino Uno has been programed. Observe the outcome from the circuit. Try adjust by changing the number, reupload the block script and observe the output.
  • 39. SKILL MODULE: DIGITAL STEM 38 Activity 6: ON and OFF the LED with keyboard keys a. On the mBlock panel, click Sprite. From block script menu, click extension. b. Select and click + Add for Upload Mode Boardcast extension. i) Click Sprite. ii) Then, click extension.
  • 40. SKILL MODULE: DIGITAL STEM 39 c. On the mBlock panel, click Sprite. From block script menu, click Events and choose by dragging the block script and drop to the script area. d. On block script menu, click Upload Mode Broadcast and choose by dragging the block script and drop to the script area. Edit the statement by replacing ā€œmessageā€ with ā€œONā€. iii) Drag and position the block here. Edit statement to ON. i) Select Upload Mode Broadcast. ii) Choose this block.
  • 41. SKILL MODULE: DIGITAL STEM 40 e. Duplicate the first block scripts and change space to alphabet a and edit the upload message to OFF. f. Select Devices in mBlock panel and click Arduino Uno. From block script menu, click extension. Select and click + Add for Upload Mode Boardcast extension (same as step b.). ii) Change to character a. iii) Edit statement to OFF. i) Right-click, and select duplicate.
  • 42. SKILL MODULE: DIGITAL STEM 41 g. Select Upload Mode Broadcast. i) Choose this block. iii) Edit statement to ON. i) Select Upload Mode Broadcast . iv) Select Pin. v) Choose this block. iii) Set the output as HIGH.
  • 43. SKILL MODULE: DIGITAL STEM 42 h. Complete the block script as follow. i. Upload the block script by clicking Upload button. Now we can control LED from keyboard. Exercise 1: Improve the program in Activity 6 Improve the block script so that the LED can be control with three options. 1. ON ā€“ turn ON the LED 2. OFF ā€“ turn OFF the LED 3. Blink ā€“ set the LED ON for 1s and OFF for 2s.
  • 44. SKILL MODULE: DIGITAL STEM 43 Exercise 2: Create a mood lights based on the flowchart Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 3 x LED (different color) 3 x 220 Ohms Resistor 1 x Bread Board Circuit Diagram: Blue LED Green LED Red LED Key A ON OFF OFF Key S OFF ON OFF Key D OFF OFF ON Flowchart: Note: This flowchart still can be improved. 3 5 6
  • 45. SKILL MODULE: DIGITAL STEM 44 Activity 7: Control LED using buttons in mBlock (virtual buttons) Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 1 x LED 1 x 220 Ohms Resistor 1 x Bread Board Circuit Diagram: Figure Activity 7: ON and OFF using button in mBlock Hardware Procedure: a. Connect all components according to wiring diagram in Figure. b. Positive (+ / anode) of LED to 220 ohms resistor and digital Pin 12 on Arduino. Negative (- / cathode) of LED to pin GND of Arduino.
  • 46. SKILL MODULE: DIGITAL STEM 45 mBlock Procedure: a. Select Background from mBlock panel. Click on + sign to add background to mBlock user interface in Stage. b. We can choose any available background or we can create custom made background by clicking My Backdrops. Choose any background and click ok. i) Select Background. ii) Click this add button.
  • 47. SKILL MODULE: DIGITAL STEM 46 c. The background should have changed with the one we selected. To adjust view of the stage, select one of the buttons below the stage. d. Now, we need to create our button in the stage. Click add button in Sprite panel. Options to view stage. Click add button.
  • 48. SKILL MODULE: DIGITAL STEM 47 e. In Sprite library, click on Icons. Choose any button you like. In this example we choose Empty button14 and click OK. Get one more button with the same design. f. We can change the sprite button name. Letā€™s name it on button and off button respectively. We can edit the label on the sprite buttons by clicking Costumes. Select button design and click OK. Select button design and click OK. i) Edit name for the sprite button. ii) Redesign the button by clicking Costumes for selected sprite .
  • 49. SKILL MODULE: DIGITAL STEM 48 g. Select on button sprite and click Costumes. Click on Text symbol and locate cursor on button. Type in ā€œONā€. We can edit the font such as color and type. h. Edit color of on button by click Select editor and click the button. Change Fill color to green. Click X button to complete the sprite editing. i) Select on_button sprite. iii) Type in ā€œONā€ for this button ii) Select Text editor. i) Click Select editor. ii) Select green color in Fill. iii) Click X to close editing.
  • 50. SKILL MODULE: DIGITAL STEM 49 i. Repeat the same process (step g and h) to edit the off button. Here how the stage and sprites look like. j. Click on-button sprite in Sprite panel. Click Events in Script Block. Drag the block in scripting area. ii) Select Events blocks. iii) Drag and drop the block. i) Click on-button sprite in Sprite panel.
  • 51. SKILL MODULE: DIGITAL STEM 50 k. Select Sound in Script Block menu. Click on and drag the block script to scripting area. l. Click on Upload Mode Broadcast in Script Block Menu. Select and drag-drop on scripting area. i) Select Sound blocks. ii) Drag and drop the block. ii) Drag and drop the block. Edit message to ā€œONā€. i) Select Upload Mode Broadcast blocks.
  • 52. SKILL MODULE: DIGITAL STEM 51 m. Carry out the same scripting process for off-button. Click off-button sprite and prepare the program as follow. n. We can add another animated feature in stage. Click on Panda sprite to start block scripting. Complete the block scripting as follow.
  • 53. SKILL MODULE: DIGITAL STEM 52 o. Click on Devices and select Arduino UNO. Complete the block scripting as follow and upload it into Arduino UNO. Click on the spite in the stage area.
  • 54. SKILL MODULE: DIGITAL STEM 53 Activity 8: Integrate push button and buzzer Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 1 x 4 pins push button 1 x Buzzer 1 x 1k Ohms Resistor 1 x Bread Board Circuit Diagram: mBlock Scripting: Build the block scripting below and upload it into Arduino UNO. Observe the output. 4 8
  • 55. SKILL MODULE: DIGITAL STEM 54 Exercise 3: Create a program to turn on/off an LED and buzzer using a single push button. Activity 9: Turn on LED with a clap (using microphone). Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 1 x 220 Ohms Resistor 1 x LED 1 x Bread Board Circuit diagram: mBlock Scripts: Complete the following block scripts and upload it into Arduino UNO. Observe the output. 1. Sprite > Events > When loudness 50 2. Sprite > Upload Mode Boardcast > send upload mode message ON 12
  • 56. SKILL MODULE: DIGITAL STEM 55 1. Devices > Arduino Uno > Upload Mode Boardcast > when receiving upload mode message ON 2. Devices > Arduino Uno > Pin > set digital pin 12 output as high 3. Devices > Arduino Uno > Control > wait 1 seconds 4. Devices > Arduino Uno > Pin > set digital pin 12 output as low
  • 57. SKILL MODULE: DIGITAL STEM 56 4.3 INTEGRATE SENSORS AND ACTUATOR Activity 10: Light sensor with LED Components: 1 x Arduino UNO 1 x USB Type-B Cable Male-male jumper wires 1 x 10k Ohms Resistor 1 x 220 Ohms Resistor 1 x LED 1 x Light Dependent Resistor (LDR) 1 x Bread Board Circuit diagram: mBlock Scripting: Complete the following block scripts and upload it into Arduino UNO. Observe the output. 4 A0 GND 5V - +
  • 58. SKILL MODULE: DIGITAL STEM 57 Expected output:
  • 59. SKILL MODULE: DIGITAL STEM 58 Activity 11: Control Blinking LED with potentiometer We going to create a display and Arduino to convert analog value from potentiometer to value second. The value second will be used to control duration of blinking LED.
  • 60. SKILL MODULE: DIGITAL STEM 59 mBlock Scripting: 1. Complete the following block scripts for Arduino UNO under devices. 2. Add block scripts for Panda sprite as follow. 3. Add another sprite Bear3 and build block scripts as follow. Reading on potentiometer is from 0 to 1023. We need to map it for each duration. Exercise 4: Make some adjustment so that potentiometer able to control (ON/OFF) 3 LEDs. Yellow LED ON when Potentiometer at level 1 to 2 Green LED ON when Potentiometer at level 3 Red LED ON when Potentiometer at level 4 to 5.
  • 61. SKILL MODULE: DIGITAL STEM 60 Activity 12: Auto Awning System (using Light Dependent Resistor (LDR) and Servomotor) Circuit: Build the circuit as in Diagram below. mBlock scripting: 1. Block scripts for sprite. 2. Block scripts for Arduino UNO devices. Note: Use ā€œif-elseā€ to control servo motor with control threshold for LDR is 100. You can adjust this threshold for sensitivity of the system.