Explorer: Follow line

The lesson explains how the eXperiBot uses a sensor as a Line follower to follow a predetermined line independently.

The eXperiBot follows a black line.

Learn how your eXperiBot can follow a line.

Explorer, Smart Team 5. to 8. Medium

Model solutions

Unit 1

No program code is required for this unit. You just need to make the eXperiBot ready to start, which means:

  • Assemble the eXperiBot completely

  • Establish a connection to the app

  • Draw or stick a black line on the floor

Unit 2

First, attach the Multisensor to the front bottom of the eXperiBot. The Multisensor’s module LED should then light up blue.

Model solution: Unit 2 (Follow line)

Solution file to download and import into the eXperiBot Blockly app.

Unit 3

Model solution: Unit 3 (Follow line)

Solution file to download and import into the eXperiBot Blockly app.

Unit 4

Model solution: Unit 4 (Follow line)

Solution file to download and import into the eXperiBot Blockly app.

Lesson contents

Unit 1

Assemble your eXperiBot.

The assembled eXperiBot.
Step 1

Connect your eXperiBot to the app.

Proceed as follows:

  1. Switch on your eXperiBot.

  2. Then press the “Connect” button at the top right of the screen. Follow the instructions to connect your eXperiBot to the app.

A green button labelled with “Connect”.
The “Connect” button
The Powerbrain’s control panel with a blue status LED.
The Powerbrain’s status LED lights up blue. Your eXperiBot is connected to the app.
Step 2
The assembled eXperiBot. The Powerbrain’s status LED lights up blue.

You’ve assembled your eXperiBot and connected it to the app—now you’re ready to go!

Step 3

Show how you want your eXperiBot to drive—make your own line!

Take a black pen. Draw a straight line on a large, light-colored piece of cardboard. The line should be at least 3 cm wide and 50 cm long.

Or: Take black adhesive tape and stick a line on the floor.

Now your eXperiBot can start! Program your eXperiBot and show what it can do!

The picture shows the eXperiBot. A hand draws a line on a surface with a black pen. Next to the hand is a roll of black adhesive tape. The text ’3 cm’ with red markings shows the width of the line.

Step 4

Unit 2

Your eXperiBot needs sensors to function like a robot in a shopping center. These sensors help it recognize its surroundings and respond appropriately.

In the “Avoid obstacles” lesson, you already got to know the Multisensor. You learned how it recognizes objects.

This is how your eXperiBot can avoid obstacles.

The following module is called Multisensor.

The Multisensor is a black, cylindrical component with several built-in sensors.

But the Multisensor can do even more: it can also detect a black line.

Knowledge update: the Multisensor as a light sensor

The Multisensor in your eXperiBot can detect whether the surface is light or dark.

This feature allows your eXperiBot to distinguish whether it is driving on the dark line or on the light surface.

Here’s how it works:

An LED in the sensor emits infrared light (IR) onto the floor:

  • Light surfaces reflect a lot of light.

  • Dark surfaces reflect little light.

The IR sensor measures how much infrared light is reflected back.

This allows your eXperiBot to reliably detect the line.

The Multisensor—a black, cylindrical building block contains several built-in sensors.
  1. Status LED

  2. Illumination LED and sensor unit with infrared, color, and ambient light sensor

  3. Infrared sensor on the right

  4. Infrared sensor on the left

Attach the Multisensor to the front bottom of the eXperiBot in the direction of travel.

The image shows how to assemble the eXperiBot. On the left, you can see a black cylindrical part, the Multisensor. A green arrow indicates where you should attach the Multisensor to the eXperiBot. On the right, you can see the finished robot with two large Wheels, white and red cube-shaped modules, and the new black Multisensor.
Step 1

For your eXperiBot to follow a line, the Multisensor must constantly check: Am I still on the line?

The Multisensor has two infrared sensors (IR sensors):

  • one for the left side,

  • one for the right side.

This allows your eXperiBot to recognize three situations (a to c):

Three eXperiBots on a line labelled a to c. In variant A, the eXperiBot sits centrally on the line; in variant B, it sits offset to the right in the direction of travel; and in variant C, it sits offset to the left.

For each situation, consider which direction your eXperiBot should travel to follow the line.

Tip

If both infrared sensors detect the line, your eXperiBot is completely on the line.

Solution

The following setup lets your eXperiBot recognize the three situations:

a) If both IR sensors see the dark line, your eXperiBot drives straight ahead.

b) If only the left IR sensor sees the dark line, your eXperiBot turns left.

c) If only the right IR sensor sees the dark line, your eXperiBot turns right.

Step 2
Three representations of the eXperiBot on the line. In variant A, the eXperiBot is positioned centrally on the line, in variant B it is offset to the right in the direction of travel, and in variant C it is offset to the left.

In order for your eXperiBot to respond correctly in situations a, b, and c, you need the “if—do” block from the “Logic” category.

Knowledge update “if-do” block

What is an “if-do” block?

This block only executes statements if a certain condition is true.

This is called a conditional block.

With a conditional block, you can control the flow of your program using conditions.

A condition can only be true or false.

If the condition is “true”, the program executes the statements; if it is “false”, the program skips them.

This feature lets your eXperiBot respond appropriately to different situations.

When do you need the “if—do” block?

Use it whenever you want your eXperiBot to respond differently in a situation:

  • If the condition is true, your eXperiBot executes the statement.

  • If the condition is false, your eXperiBot does not execute the statement.

How do you insert the “if—do” block?

Drag the “if—do” block from the “Logic” category into your program.

The image shows a blue programming block. The block says “if … do…”. The condition is entered in the field after “if”, and the statement that is executed when the condition is met is entered in the field after “then.”
  1. Top: Condition

  2. Inside: Statement

Drag the block into the editor and connect it to the “start program” block.

Step 3
Three eXperiBots on a line labelled a to c. In variant A, the eXperiBot sits centrally on the line; in variant B, it sits offset to the right in the direction of travel; and in variant C, it sits offset to the left.

Situation a: If both IR sensors detect the dark line, do the following: Drive the motor forward.

Tip: When does your eXperiBot drive forward?

Your eXperiBot only drives forward along the line when both IR sensors detect the dark line. To do this, both IR sensors must be on the dark line. (Situation a)

Your eXperiBot should only drive when both IR sensors see the line. To make this work, you need a condition that checks both IR sensors, so use the “and” block.

Knowledge update, “and” block

In computer science, the “AND” operator links two conditions.

This logical connection is called a logical AND.

Both conditions must be true for the “if—do” block to execute the statement.

Example: If the left IR sensor AND the right IR sensor detect the dark line, then “motor drive forward”.

Drag the “and” block from the “Logic” category into the “if—do” block. Place it in the field for the condition.

Step 4
Three eXperiBots on a line labelled a to c. In variant A, the eXperiBot sits centrally on the line; in variant B, it sits offset to the right in the direction of travel; and in variant C, it sits offset to the left.

Situation a: If both IR sensors detect the dark line, drive the motor forward.

Drag two matching conditions from the “Multisensor” category into the “and” block.

The conditions should match situation a: both IR sensors detect the dark line.

Solution

From the “Motor” category, add the “Motor drive forward” statement to the “do” section. This tells your eXperiBot what to do when it detects the line.

Then adjust the speed and duration.

Solution
Step 5

Place your eXperiBot at the start of your line and test your program.

Make sure that both IR sensors on the multisensor are aligned with the line at the start.

A green, oval button. The button has white lettering that reads, “Run program.”

Your eXperiBot will now only move forward when both IR sensors detect the line.

Step 6

What happens if your eXperiBot does not recognize the line?

If the left or right sensor is no longer on the line, your program must also detect situations b and c.

Three eXperiBots on a line labelled a to c. In variant A, the eXperiBot sits centrally on the line; in variant B, it sits offset to the right in the direction of travel; and in variant C, it sits offset to the left.

To ensure your eXperiBot responds correctly to situations b and c, add more conditions to your program.

You can expand the “if—do” block by inserting “else if” statements.

Brief explanation—click here!
How to edit the “if-do” block.
Tip

Your program checks the conditions from top to bottom. As soon as a condition is true, it executes only that statement and then stops checking.

Step 7
Three eXperiBots on a line labelled a to c. In variant A, the eXperiBot sits centrally on the line; in variant B, it sits offset to the right in the direction of travel; and in variant C, it sits offset to the left.

Help your eXperiBot become a Line follower!

First, look at the code for situation a. Then set up the conditions for b and c correctly.

Finally, insert the appropriate blocks from the “Motor” category.

Tip

When the left sensor detects light, your eXperiBot must move to the right. This allows it to find the line again.

Hint

Your program could look like this:

Step 8

If you want your eXperiBot to drive along the line indefinitely, you must repeat this entire sequence infinitely.

Drag the appropriate block from the “Loops” category into the editor.

Tip

In the “Drive back and forth” lesson, you already learned about the Loop that repeats a Sequence over and over again. This Loop allowed your eXperiBot to drive back and forth between two stations without interruption.

Test your program.

A green, oval button. The button has white text that says, “Run program.”
Step 9

Try out how your eXperiBot behaves when you change the values for

  • time,

  • rotation angle, or

  • speed in the blocks from the “Motor” category.

Test your program after each change.

A green, oval button. The button has white lettering that reads, “Run program.”

Observe closely how your eXperiBot behaves. What do you notice?

Which values work particularly well?

Step 10

Your eXperiBot follows a line.

eXperiBot follows a black line on a white background.
Step 11

Unit 3

Currently, your eXperiBot repeats the commands to be a line follower indefinitely. This means that your eXperiBot constantly checks whether it is still on the line.

Now your eXperiBot should stop and play a melody as soon as it reaches the end of the line. To do this, both IR sensors must detect the white surface.

Replace the “repeat forever” loop with a loop that stops when both IR sensors detect the light-colored surface.

Tip

Your eXperiBot continues to drive as long as one IR sensor can still see the dark line.

Your eXperiBot only stops when both sensors can no longer detect a dark surface.

Step 1

Did you choose the right Loop?

You can replace the “repeat forever” loop with this loop:

Knowledge update “repeat-while” block

What is a “repeat-while” block?

The “repeat-while” block is a Loop. It repeats the statements in the block over and over again as long as the condition is true.

Before the loop starts, the program checks the condition.

  • If the condition is true, the loop begins and the statements are executed.

  • If the condition is false, the loop does not start.

Computer scientists call this loop a head-controlled conditional loop because the condition sits, so to speak, “at the head” of the loop and decides whether it runs or not.

When do you need the “repeat-while” block?

Use the block when you need to repeat something as long as a certain condition is true.

How do you insert the “repeat-while” block?

Drag the “repeat-while” block from the “Loops” category into your program.

Green Blockly block labeled “repeat-while do.”
  1. Insert the condition to be checked.

  2. Place all the statements that your eXperiBot should execute in the loop block as long as the condition is true.

Step 2

Insert a suitable condition in the “repeat-while” block.

This will stop your eXperiBot as soon as it is no longer on the line. In other words, when both IR sensors no longer detect a dark surface.

Tip 1

If the condition is true, the “repeat-while” block executes all statements.

For the condition to be true, at least one of the two IR sensors must detect the dark line.

Tip 2

In computer science, you use the logical operator “or” for this purpose.

This block allows you to connect two conditions together.

The “or” block returns true if at least one of the two conditions is true.

This means that it is sufficient for one IR sensor to detect the dark line. Then the condition remains true and the loop continues to run.

Step 3

If the condition in the “repeat-while” block becomes false, the loop stops.

Then your eXperiBot has reached the end of the line. At that point, both IR sensors no longer see a dark background.

To make it easy to recognize when the Loop stops, your eXperiBot should play a sound.

Now complete your program: Add a suitable block that plays a sound.

Tip

The new block for playing a sound does not belong in the loop.

The block is only executed after the loop has stopped.

Step 4

Test your program now. Place your eXperiBot at the beginning of the line and start the program.

A green, oval button. The button has white lettering that reads, “Run program.”

Observe whether your eXperiBot follows the line and stops at the end of the line.

Your eXperiBot stops at the end of the line and plays a sound.

Step 5

Unit 4

Currently, you are using the “repeat-while” block in your program. This block executes statements as long as the condition is true.

Now change the block to “repeat-until”.

Briefly explained—click here!
Step 1

Now adjust the condition in the “repeat-until” block so that your eXperiBot can continue to follow the line.

Tip

The “repeat-until” block executes statements until the condition becomes true.

Step 2

Test your program.

A green, oval button. The button has white lettering that reads, “Run program.”

Does your eXperiBot still drive along the line just as well? Does it stop at the end of the line as before? This is how it should work if you use “repeat-while” instead of “repeat-until”.

If not, check your condition.

Important: The “repeat-until” block repeats the statements until the condition becomes true.

Tip: repeat-while or repeat-until

If you use “repeat-while”, your program will continue to run as long as the condition is true.

For example, as long as an IR sensor detects the dark line.

If you use “repeat-until”, your program will continue to run until the condition becomes true.

For example, until both IR sensors see the light background.

Step 3

If your eXperiBot follows the line and stops at the end, you have used the “repeat-until” block correctly.

For the “Line follower” program, you can use either the “repeat-while” or the “repeat-until” loop.

Step 4

Bonus unit 1

Extend your black line with a few curves. Make sure that the curves are not too tight so that your eXperiBot can drive them easily.

eXperiBot sits on a white surface with a black, curved line. A hand traces this line with a black pen, marking the path that the robot can follow later. Next to the hand is a roll of black tape, which can also be used to mark the path. The line drawn is three centimeters wide.
Step 1

Place your eXperiBot on the line and start your program.

A green, oval button. The button has white lettering that reads, “Run program.”

Observe: Does your eXperiBot remain reliably on the line even when cornering?

If not, adjust your program or your line accordingly.

Tip

If your eXperiBot veers off the line when turning:

  • reduce the speed,

  • decrease the turning angle for “Motor turn left” or “Motor turn right”,

  • make the line slightly wider,

  • and don’t draw the curves too tightly.

Step 2

Your eXperiBot follows a curved line.

eXperiBot moves along a black, curved line on a white surface.
Step 3

Bonus unit 2

Use your program to make your eXperiBot act as a line follower and stop at the end of the line.

Modify your program so that your eXperiBot stops at the end of the line for a few seconds and then turns around on the line.

Step 1

Now repeat these statements continuously.

To do this, insert a suitable Loop into your program.

Step 2

Test your program.

A green, oval button. The button has white lettering that reads, “Run program.”

Observe whether your eXperiBot stops at the end of the line, turns around, and follows the line again.

Adjust your code if something is not working properly.

Your eXperiBot stops, turns around, and drives back along the line—again and again.

Step 3
eXperiBot Documentation eXperiBot Documentation Version 1.1.4 (Latest)
Made with by the eXperiBot Team © 2026 Cornelsen Experimenta GmbH