INTERMEDIATE
PROGRAMMING
LESSON
INTRODUCTION TO MY BLOCKS
By Sanjay and Arvind Seshan
Lesson Objectives
Learn how to make custom blocks in the EV3 Classroom Software (My Blocks)
Learn why a My Block is useful
Learn to construct a My Block with Inputs and Outputs (Parameters)
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 2
What is a My Block?
• A My Block is a combination of
one or more blocks that you
create that can be grouped
into a single block
• My Blocks are basically your The blocks above is an example of a
own custom blocks My Block:
• Move_CM tells the robot to move
• Once a My Block is created, the number of CM we input
you can use it in multiple
programs • You will create this My Block in the
• Just like any other block in EV3, next lesson
My Blocks can have both
inputs and outputs
(parameters)
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 3
When do You Use a My Block?
• Whenever the robot is going to repeat an action inside
your program
• When code is repeated in a different program
• Organize and simplify your code
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 4
Why Should You Bother?
Because of My Blocks, your missions will look like this…
This makes your code easier to read and easier to modify!
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 5
What Makes a Useful My Block
Note: Making My Blocks with inputs and outputs can make them far more useful.
However, you need to be careful not to make the My Block too complicated.
Question: Look at the list of three My Blocks below. Which ones do you think are
useful for to use?
◦ Move5CM (Moves the robot five centimeters)
◦ MoveCM with a centimeter and power input
◦ MoveCM with centimeter, power, angle, coast/brake, etc. inputs
Answer:
◦ Move5CM may be used often, but you will be forced to make other My Blocks for other
distances. This will not be fixable later.
◦ MoveCM with centimeters and power as inputs is probably the best choice.
◦ MoveCM with centimeters, power, angle, coast/brake, etc. might be most customizable, but
some of the inputs might never be used.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 6
Step 1: Create a My Block
•Go to the My Blocks tab on the left side and select
“Make a Block.”
•You are then taken to the Block Making menu.
•Type in the name for the block
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 7
Step 2: Add Inputs and Labels
•Use the buttons below
the block to add inputs.
You can add number or
text inputs, as well as
Boolean (true/false).
•Labels can be used to
indicate what each input
is when you use the My
Block in your programs.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 8
Step 3: My Block Location
•Once you click ”Save,” a Define Block appears in the
canvas.
•The code for the My Block goes under the Define Block.
•In addition, the My Block can now be found in the My
Blocks tab. To use the My Block in your code, simply
drag in the block.
•Note: the My Block in EV3 Classroom can only be used
inside one project
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 9
Step 4: Defining the My Block
•Add the programming blocks
that you want in your My
Block under the Define Block.
•To use the inputs from the
My Block, drag the oval
inputs from the Define Block
to the places where you
need them as demonstrated
in the images to the right.
•The code on the right sets up
a My Block that takes in
speed and rotations and
moves straight with the
speed and rotations
inputted.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 10
Step 5: Adding Outputs
Unlike My Blocks in EV3-G, you
cannot define Outputs. Here is a
work-around.
1. Define a variable to store the
value of your output.
2. Write the data you want to
input to the variable inside
the My Block.
3. Use the variable in your main
code
In the code on the right, the My
Block reads the ultrasonic sensor,
sets it to a variable.
The value can be used later in the
program such as print to the
screen.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 11
How to Edit or Delete a My Block
• Right Click on a My Block in the
Programming Canvas and select
“Edit” to edit the My Block.
• This will take you back to the My
Block creation screen where you
can edit the name, add inputs, or
delete inputs.
• To delete, you must first right click
and press delete on all uses of the
My Block in your program. Then,
you can press delete on the
definition of the My Block.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 12
Credits
This tutorial was created by Sanjay Seshan and Arvind Seshan
More lessons are available at www.ev3lessons.com
This work is licensed under a Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International License.
© 2020 EV3LESSONS.COM (LAST EDIT 12/24/2019) 13