Inspiring Mindstorms EV3 Programming for FLL Part 9: Reusable EV3 Line Detection My Block

In addition to Line Following, lines on a FLL Robot Game map can be used for Line Detection. Using a Light Sensor, Line Detection is a very effective technique to consistently navigate a robot to the right location.  Line Detection is not limited to the regular white/black line strips; it can also work for other shapes where reflection light changes can be detected.

We used Line Detection a lot for FLL Robot Game. In this post, we’ll provide a step-by-step guide on creating a reusable My Block for Line Detection.

The following edge detection logic is used.

1. Turn Motor Power on

2. Wait for a white line using Wait Block.

3. Wait for a black line. using Wait Block.

4. Loop 2 & 3 for the number of lines to detect.

5. Turn Motor Power off

Based on the above logic, the Line Detection program is shown below. Using the color senor on port 2, the program will move our robot at power 35, detect the white/black line strip once, and stop. The Wait Block The block stops waiting when the threshold comparison is True. The first Wait Block stops waiting when the light sensor’s reflection reading is greater than 80% (white). The second Wait Blocks stops waiting when the light sensor’s reflection reading is smaller than 20% (black).

EV3 Line Detection Program
EV3 Line Detection Program

Creating a Reusable EV3 Line Detection My Block

Now, let’s convert the above program into a reusable My Block!

Creating EV3 Line Detection My BlockEV3 Line Detection
Creating EV3 Line Detection My Block a)

Enter My Block name, description, and select an icon.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block b)

Add the Port parameter for the light senor which will be used for line detection.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block c)

Add the White Reflection Light parameter to wait for the white line or bright area.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block d)

Add the Black Reflection Light parameter to wait for the black line or dark area.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block e)

Add the Count parameter for how many lines to detect.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block f)

Add the Power parameter for the Move Steering Block then Click Finish.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block g)

Finally, connect the data wires.

Creating EV3 Line Detection My Block
Creating EV3 Line Detection My Block h)

Using the Line Detection My Block

The following map is for 2020 RePLAY season. From the start position, the left My Block will make our robot travel with 35 power until the port 2 Light Sensors detects the first line. The right My Block will make our robot stop right at the 4th line.

Using Line Detection My Block
Using Line Detection My Block

Using Line Detection for 2019 CITY SHAPER Bridge Mission

For the 2019 CITY SHAPER Bridge Mission, we wanted to move our robot right onto the flag to raise them. To precisely moved our robot there, we found that there were patterns on the Bridge that we could use for Line Detection as shown below.

Initially, we aligned our robot with the bridge by using Line Following on the line leading to the bridge. It’s important to align the robot with the bridge accurately. However, how close the robot is to the bridge isn’t as important. Regardless of where the robot started, we utilized Line Detection to enable the robot to halt consistently at the second line.

As you can find,  they aren’t actually lines. But the light reflection changes between the gaps can still be used for Line Detection.

Line Detection for CITY SHAPER Bridge Mission
Line Detection for CITY SHAPER Bridge Mission

The following screenshot is the last part of the program for the Bridge Mission. It used Line Following My Block to align with the Bridge model, used Line Detection to stop at the second line, then used the Move Inches My Block to move the robot on to the flags.

Line Detection for CITY SHAPER Bridge Mission
Line Detection Program for CITY SHAPER Bridge Mission