Simple line follow program

Author: Yisong Xu, Si Xu

Let mBot move along a black track on a light-color surface.

Hardware requirements:



Upload the program to Arduino

Example program download:

Simple Line-Follow Program.sb2


Example: mBot program(Arduino download)
kids programming language

Script description
As black can absorb infrared light, then in consideration of Example 21 Value of the line-follower sensor, and we can let mBot identify a black track on a light-color surface or let mBot identify a light color track on a black surface
Here we take a black track on a light color surface for example to explain how to use a line-patrolling sensor to make mBot move along a track.
The following introduces four situations where mBot is relative to the black line, which can be dealt with using the following strategies:
1, if it is on the black line, it keeps moving forward;
2, if it deviates from the black line, it turn left or right in time to keep itself on the line;
3, if it is not on the black line, it turns back to find the black line.

kids programming language2

For the above four situations, the program can be the example:
kids programming language

Knowledge point

The line-patrolling sensor is the best to identify pure white or black surface without reflection. Commonly you can use a black electrician tape to make a patrolling line on a light color surface to achieve the best effects.

Extended tasks

Task 1 Firstly, change the speed of mBot when it is moving forward or turning, then observe mBot’s line patrolling effects.
Task 2 Let’s think: In Situation 4, what strategy can mBot use to find the black line.

Attached – Line-patrolling sensor structure diagram

kids programming language

kids programming language