Welcome to Roboduino V2 repository
09.Track Print
Track Print
Track PrintDevice connectionHardware connectionSoftware connectionThree-way patrol moduleControl principleControl pinCode analysisExperimental results
Use the serial port to print the data of the three-way patrol module and the direction that the simulated car needs to change.
Device connection
Hardware connection
Use the Type-B data cable to connect the Arduino Uno and the computer.
Software connection
Open the "Arduino IDE" software and select the model and serial port number corresponding to the development board.
Three-way patrol module
The basic principle of infrared sensor patrol is to use the reflective properties of objects: when infrared rays are emitted to the black line, they will be absorbed by the black line, and when they are emitted to materials of other colors, they will be reflected to the infrared receiver.
The position selected by the red box is the location of the three-way patrol module interface:

Control principle
By reading the analog value data of the three-way line patrol module X1, X2, and X3 interfaces, the location of the black line is determined.

xxxxxxxxxxWhen the three-way tracking module is installed, the infrared tracking sensor faces the ground, so the left, middle, and right sensors in the program are based on the left mark in the above figure
Control pin
The three-way line patrol module and the Robduino expansion board have a special interface for installation and connection.
| Peripheral module | Arduino Uno |
|---|---|
| VCC | VCC |
| X1 | X1 (A0) |
| X2 | X2 (A1) |
| X3 | X3 (A2) |
| GND | GND |
Note: The infrared light emitted by the infrared probe is invisible to the human eye; in order to avoid infrared light interfering with the sensor, we need to use this module indoors.
Code analysis
Here we only briefly introduce the code content. For detailed code, please refer to the corresponding code file, which is provided in the download area!
Define the three-way line patrol module pins and black line threshold
x// 定义三路循迹模块引脚 Define the three-way line patrol module pins#define L_TRACK_PIN A2#define M_TRACK_PIN A1#define R_TRACK_PIN A0// 定义巡线阈值 Define the patrol thresholdconst int Threshold = 500;
Get line patrol data and status
xxxxxxxxxx/*** @brief 获取三路巡线模块数据和状态 Get the status of the three-way line patrol module* @param iLeftPin: 左边红外传感器 Left tracking sensor* @param iMidPin: 中间红外传感器 Middle tracking sensor* @param iRightPin: 右边红外传感器 Right tracking sensor* @retval 无 None*/void getTrackLineState(int iLeftPin, int iMidPin, int iRightPin) {int leftValue = analogRead(iLeftPin);int middleValue = analogRead(iMidPin);int rightValue = analogRead(iRightPin);Serial.print("Left: ");Serial.print(leftValue);Serial.print(" Middle: ");Serial.print(middleValue);Serial.print(" Right: ");Serial.print(rightValue);// 进行简单的方向判断打印 The following is a simple judgmentif (leftValue > Threshold && middleValue < Threshold && rightValue < Thre