Tracking mode——Introduction to the use of infrared tracking module

Tracking mode——Introduction to the use of infrared tracking mode

Infrared Tracking Module Introduction

insert image description here

The infrared emitting diode of the TCRT5000 sensor continuously emits infrared rays. When the emitted infrared rays are not reflected back or are reflected back but the intensity is not strong enough, the infrared receiving tube is always in the off state . At this time , the output terminal of the module is at a high level , indicating The diode is always off ;

When the detected object appears within the detection range, the infrared rays are reflected back with sufficient intensity, and the infrared receiving tube is saturated. At this time, the output terminal of the module is at a low level , and the indicator diode is lit.

In a word: no reflection back, D0 output high level, turn off the light

No reflection - D0 output high level - light off

Reflection - D0 output low level - light up

wiring

1. VCC: Connect to the positive pole of the power supply (3-5V)

2. GND: connected to the negative pole of the power supply

3. D0: TTL switch signal output

4. A0: Analog signal output (different voltages are output at different distances, this pin can generally be left unconnected)

Tracking car principle

Black has a strong absorption capacity. When the infrared rays emitted by the tracking module hit the black line, the infrared rays will be absorbed by the black line, causing the phototransistor on the tracking module to be turned off, and an LED on the module is off at this time. When no black wire is detected, the two LEDs on the module are always on

That's why ordinary track tracks are black

It is also a one-sentence summary: the black line is sensed, D0 outputs high level, and the light is turned off

insert image description here

Summary

1. Both the left and right tracking modules are irradiated on the white - infrared return - both output low level - the indicator light is on - go straight

2. The left tracking module shines on the black runway - the left infrared is absorbed and does not return - the left output is high - the indicator light is off - it is necessary to turn left

3. The right tracking module shines on the black runway - the right infrared is absorbed and does not return - the right outputs high level - the indicator light is off - it is necessary to turn right

(The car in the above picture is moving in the opposite direction, which is a right turn situation)

Installation and Wiring

Install the tracking modules with the two infrared emitters down on both sides of the front of the car, and fix them with hot melt glue. Both VCC and GND are connected to the 5V and GND of the microcontroller, and the D0 on the left is connected to P2.7 The D0 on the right is connected to the P2.6 port. Of course, it is also possible to connect to other pins. Just modify the pin number in the program.

program

It is relatively simple to realize the tracking function, and there are not many other functions used, just a few judgment statements

program files:

1.main.c: It mainly judges the output pin levels of the two infrared tracking modules, and then calls the motor drive to make the car turn left and right

2.Motor.c: functions for the car to move forward, backward, turn left, turn right and stop

3.Delay.c: delay function

insert image description here

main.c:

The whlie loop continuously judges the signal pin levels of the left and right sensors, analyzes the current state, whether it is moving forward or turning, and then these statements can be modularized, and the next time you can use the direct call method

/*
循迹功能,增加引脚定义,然后判断两个传感器输出引脚的高低电平
*/

//左右红外传感器的信号引脚
sbit LeftSersor = P2^7;
sbit RightSersor = P2^6;

void main()
{
    
    
	while(1)
	{
    
    
		//两个都反射,都亮灯
		if(LeftSersor == 0 && RightSersor == 0)
		{
    
    
			GoForward();
		}
		//左边反射,右边没反射,左亮,说明右边碰到黑线红外线被吸收,要右转
		if(LeftSersor == 0 && RightSersor == 1)
		{
    
    
			GoRight();
		}
		//右边反射,左边没反射,右亮,说明左边碰到黑线红外线被吸收,要左转
		if(LeftSersor == 1 && RightSersor == 0)
		{
    
    
			GoLeft();
		}
		//两个都不反射,都灭灯
		if(LeftSersor == 1 && RightSersor == 1)
		{
    
    
			Stop();
		}
	}
}

Guess you like

Origin blog.csdn.net/weixin_46251230/article/details/126319060