Project 14:Line-tracking Tank

(1)Description:

The previous project introduced how to confine the smart car to move within a certain space. In this project, we will use the knowledge learned before to make it a line-tracking smart car. In the experiment, we use the line-tracking sensor to detect whether there is a black line around the smart car, and then control the rotation of the two motors according to the detection results, so as to make the smart car move along the black line.

The specific logic of the smart car is shown in the table below:

Sensor

Detection

Line-tracking sensor in the middle

Black line detected: in high level
White line detected: in low level

Line-tracking sensor on the left

Black line detected: in high level
White line detected: in low level

Line-tracking sensor on the right

Black line detected: in high level
White line detected: in low level

Condition 1

Condition 2

Movement

Line-tracking sensor
in the middle
detects the black line

Line-tracking sensor on the left detects the black line
the one on the right detects white lines

Rotate left

Line-tracking sensor
in the middle
detects the black line

Line-tracking sensor on the left detects white lines
the one on the right detects the black line

Rotate right

Line-tracking sensor
in the middle
detects the black line

Both the left and right line-tracking sensors detect white lines
Both the left and right line-tracking sensors detect the black line

Move forward

Line-tracking sensor
in the middle
detects white lines

Line-tracking sensor on the left detects the black line
the one on the right detects white lines

Rotate left

Line-tracking sensor
in the middle
detects white lines

Line-tracking sensor on the left detects white lines
the one on the right detects the black line

Rotate right

Line-tracking sensor
in the middle
detects white lines

Both the left and right line-tracking sensors detect white lines
Both the left and right line-tracking sensors detect the black line

Stop

(2)Flow chart:

(3)Connection Diagram:

(4)Test Code:

You can also drag blocks to edit your code, as shown below

(1)

(2)

(3)

(4)

(5)

(6)

(7)

(8)

Complete Test Code

(Note: Do not connect the Bluetooth module before uploading the code, because uploading the code also uses serial communication, and there may be conflicts with the Bluetooth serial communication, which can cause the upload to fail.)

(5)Test Results:

After uploading the test code successfully and powering on, the smart car moves along the black line.