Authorized Amazon Seller:
Robot Tank Car Chassis
| Buy from US | Buy from CA | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES |
Robot Tank Car Electronic Parts Kit
| Buy from US | Buy from CA | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES |
In this lesson, we will use 2 black/white tracking sensors to read data and automatically guide the smart car to move along the black track line in the white ground.
There are two probe on tracking sensor module,one is sender diode(IR LED) and the other one is receiver diode(Photo Diode).
If the tracking sensor is not on black track,the infrared ray from IR LED can be reflected and received by photo diode. The sensor will output low level.
If the tracking sensor is on black track,the infrared ray from IR LED can not be reflected and not received by photo diode. The sensor will output high level.

There are 2 tracking sensor on left and right. When the left tracking sensor on black line, the tank car will turn left. When the right tracking sensor on black line, the tank car will turn right. When the left and right tracking sensor on both sideways of black line, the tank car will go straight. When both tracking sensor are on black line,the tank car will stop.



Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step)
Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.
Step 2:Download Lesson 5 sample code from http://www.kookye.com/download/Arduino_Tank_Car_Kit/tank_robot_lesson5.zip , unzip the download zip file tank_robot_lesson5.zip, you will see a folder called tank_robot_lesson5.
Step 3: Connect UNO R3 board to PC with USB cable, Open Arduino IDE -> click file -> click Open -> choose code “tank_robot_lesson5.ino” in tank_robot_lesson5 folder, load the code into arduino.

Step 4: Choose corresponding board and port for your project,upload the sketch to the board.

Step 1: Define the pinout of left and right tracking sensor.
#define LFSensor_1 A0 //line follow sensor1 #define LFSensor_2 A1 //line follow sensor2
Step 2:Read the signal from tracking sensor and store the signal value.
void read_sensor_values()
{
sensor[0]=digitalRead(LFSensor_1);
sensor[1]=digitalRead(LFSensor_2);
}
Step 3:Control the tank car movement. The structure of auto_tarcking() can get the left and right sensor signal via call the structure of read_sensor_values(),then judge the signals via “if “control structure.
void auto_tarcking(){
read_sensor_values();
if((sensor[0]==LOW)&&(sensor[1]==HIGH)){ //The right sensor is on the black line.The left sensor is on the white line
set_motorspeed(M_SPEED1,M_SPEED1);
turn_right(250);
}
else if((sensor[0]==HIGH)&&(sensor[1]==LOW)){//The right sensor is on the white line.The left sensor is on the black line
set_motorspeed(M_SPEED1,M_SPEED1);
turn_left(250);
}
else if((sensor[0]==LOW)&&(sensor[1]==LOW)){//The left an right sensor are on the white line.
set_motorspeed(M_SPEED2,M_SPEED2);
go_ahead();
}
else if((sensor[0]==HIGH)&&(sensor[1]==HIGH)){//The left an right sensor are on the blac
Step 1: Install ESP8266 Expansion Board on UNO R3 board.

Step 2: Turn the switch of esp8266 to “1” and “2” position, as the following photo shows.

Step 3: Move the wire connected to pinout(GND,VCC,DO) in tracking sensor to the counterpart pin in expansion Board as the following picture.
![]()
Step 4: Put two 12865 batteries in battery box and turn the swith of box to “ON”.
(If you have finished the above steps on lesson one, please skip these step)
Step 5:Testing. Press the OK button to make the tank car go along with black line.Press “o” to make the tank car stop.
Prepare a black track (the width of the black track line is more than 20mm and less than 30mm) in white ground.Please make sure that the width of black track line is less than the 1/3 distance of two tracking sensors. Please note, the bend angle of track can’t be larger than 90 degree. If the angle is too large, the car will move out of the track. Turn on the car and put the middle of tracking sensor module facing over black track, and then the car will move along the black track.
Note: Please adjust the sensitivity of tracking sensor as per the follow way and check the wire connections if the tracking sensor can not work as expected.
Connect ESP8266 wifi board to tracking sensor as the following graph. Put the Expansion board on UNO R3 board and connect Arduino UNO to PC with USB cable.Then adjust the potentiometer on the tracking sensor with cross screwdriver until you get the best sensitivity status: the signal indicate LED light will turn on when sensor is above white ground, and the signal LED will turn off when the sensor is above black track.
在本课中将介绍用循迹模块让坦克小车循迹,当按下遥控器某个按键,小车开始循迹;按下另一个按键,小车停止。
循迹原理
循迹传感器模块上有2个探头,一个是红外发射二极管,一个是红外接收管。红外发射二极管不断向外发射红外线,若循迹模块不在黑色轨道上,红外发射管发射的红外线就会被反射回来,反射回来的红外线会被红外接收管接收到,循迹模块输出低电平;如果循迹模块在黑色轨道上,红外发射管发射的红外线不能被反射,红外接收管无法检测到红外线或检测到的红外线信号比较弱,模块输出高电平。

坦克底盘上一共有2个循迹传感器,左右各一个。若左边循迹传感器模块位于黑线上,坦克小车左转;若右边循迹传感器模块位于黑线上,坦克小车右转;若左右两个循迹模块位于黑色轨道两侧,则坦克小车直行;若左右循迹模块均在黑线上,坦克小车停止运动。如图所示



软件
下载http://www.kookye.com/download/car/tank_robot_lesson4.zip并解压文件,用arduino IDE打开tank_robot_lesson4.ino文件,下面对部分代码做简要说明。
#define LFSensor_1 A0 //line follow sensor1 #define LFSensor_2 A1 //line follow sensor2
上面两行代码定义了左右两个循迹传感器所接的端口
void read_sensor_values()
{
sensor[0]=digitalRead(LFSensor_1);
sensor[1]=digitalRead(LFSensor_2);
}
read_sensor_values()函数会读取左右两个循迹模块信号,并将左边模块信号存储在sensor[0]中;右边模块结果存储在sensor[1]中。
void auto_tarcking(){
read_sensor_values();
if((sensor[0]==LOW)&&(sensor[1]==HIGH)){ //The right sensor is on the black line.The left sensor is on the white line
set_motorspeed(M_SPEED1,M_SPEED1);
turn_right(250);
}
else if((sensor[0]==HIGH)&&(sensor[1]==LOW)){//The right sensor is on the white line.The left sensor is on the black line
set_motorspeed(M_SPEED1,M_SPEED1);
turn_left(250);
}
else if((sensor[0]==LOW)&&(sensor[1]==LOW)){//The left an right sensor are on the white line.
set_motorspeed(M_SPEED2,M_SPEED2);
go_ahead();
}
else if((sensor[0]==HIGH)&&(sensor[1]==HIGH)){//The left an right sensor are on the blac
在auto_tarcking()中先调用read_sensor_values()函数,获取到左右循迹模块信号,接着通过if语句判断左右循迹模块信号,控制坦克小车运动,实现循迹。
测试
step 1 用usb线把坦克下车与pc连接起来,选择正确的板子型号和端口号,将程序烧录到arduino中
step 2 打开电池盒电源,将坦克小车放到黑色轨道上
step 3 遥控器对着红外接收头,按下”OK”键,小车将沿着黑色轨道行驶;按下”0″小车停止。
注意:若无法循迹,请看考第一课调节循迹模块灵敏度,并检查接线。{:}
You must be logged in to post a comment
About the Author