06LineFollowingCar
Introduction:
Using the two line tracking sensors on the bottom of TabbyBot, we will write a program for a car that follows a black line track.
Objectives:
- Master the usage of line tracking sensors.
- Master the programming logic for a line-following car.
编写程序
Our car follows the black line by sandwiching it. There are three possible scenarios:
- When the black line is between the two line tracking sensors - move forward.
- When the black line is on the left line tracking sensor (indicating the car is veering to the right) - turn left.
- When the black line is on the right line tracking sensor (indicating the car is veering to the left) - turn right.
First, we need to determine the values of the sensors when they are on the black line and on a blank surface, in order to set the threshold for line detection.
This can be done by observing the data returned through the serial port.
By running the following program, we can test and find out that:
The sensor value on the black line is approximately between 250-400.
The sensor value on a blank surface is approximately above 700.
Therefore, we can set the threshold to 600 (slightly lower than the value on a blank surface).
Based on the logic described above, we can proceed with the program. We have added button A to start or stop the car.
https://makecode.microbit.org/S67065-32045-71472-77348
Actual Result:
Press button A to start.