INTERMEDIATE
PROGRAMMING
LESSON
COLOR LINE FOLLOWER MY BLOCK WITH INPUTS:
MOVE UNTIL BLACK
By Sanjay and Arvind Seshan
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 1
Lesson Objectives
1. Learn how to write a line follower that takes multiple inputs
2. Learn how to write a line follower that stops when it sees another line
3. Practice making useful My Blocks
Prerequisites: My Blocks with Inputs & Outputs, Variables
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 2
Tips to Succeed
1. You will need to know how to make a Simple Color Line Follower program and
how to make a My Block with inputs
2. Since you will use your EV3 Color Sensor in Color Mode, you will not have to
Calibrate your color sensor for this lesson
3. Check which ports you have your color sensor connected to the EV3 and adjust
the code as needed
4. You may have to adjust the speed or direction to work for your robot. Make
sure that the the color sensor is in front of the wheels in the direction of
travel.
5. Make sure you place the robot on the side of the line that you are following.
The most common mistake is placing the robot on the wrong side of the line to
begin with.
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 3
Color Follower Until Color
Challenge: Create a line follower My Block that stops when it sees black
STEP 1:
• Create a My Block with three
inputs (Color of the Line to Follow,
% Speed, Color to End on)
STEP 2:
• Define the My Block so that it line
follows in a loop until the exit
condition (black color)
STEP 3:
• Use the My Block to follow a Red
Line until it sees Black.
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 4
Step 1: Create the My Block
Add three Inputs and Labels
© 2020 [Link], LAST EDIT 12/24/2019
Step 2: Define the My Block
Drag variables as indicated
Repeat the line following loop until the
the same color sensor sees the Color End
If the color sensor reads the color of the
line you want to follow, turn right, else,
turn left
Stop motors
© 2020 [Link], LAST EDIT 12/24/2019
Step 3: Use and Reuse the My Block
Line follow a Red Line until a Black Line
Note: You have to Color Code:
enter a number 0 - No Color
into the parameter 1 - Black
for the color. You 2 - Blue
cannot just spell 3 - Green
out the color. The 4 - Yellow
numbers are not 5 - Red
very clearly 6 - White
defined in EV3 7 - Brown
Classroom.
As with all the other My Block examples on EV3Lessons, you can now reuse this Line
Follower My Block as many times are you need to.
Just remember that My Blocks only work in the Project they are in.
© 2020 [Link], LAST EDIT 12/24/2019
Next Steps
• We use a simple line follower in this lesson. You can combine these techniques
with any line follower.
• Learn how to create a proportional line follower for light or a smooth line
follower for color à check out our Advanced: Proportional Line Follower lesson.
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 8
Credits
This tutorial was created by Sanjay Seshan and Arvind Seshan
More lessons are available at [Link]
This work is licensed under a Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International License.
COPYTIGHT © 2020 [Link], LAST EDIT 12/24/2019 9