How Smart Car Kits Achieve Infrared Line Tracking Function

How Smart Car Kits Achieve Infrared Line Tracking Function

0 comments

Working Principle

An infrared line-tracking sensor is composed of two core components: infrared emitting diode and infrared receiving tube.

Its working process can be summarized as: Emission → Reflection → Reception → Judgment.

1.Infrared emission

The infrared emitting diode on the sensor continuously emits a beam of infrared light that is invisible to the human eye.

2.Light reflection

This infrared beam irradiates the ground surface below the sensor.

If the ground is white (or light-colored): the white surface reflects most of the infrared light.

If the ground is black (or dark-colored): the black surface absorbs most of the infrared light and reflects only a small part.

3.Receive reflected light

The infrared receiving tube detects the intensity of the reflected infrared light.

On a white surface: the reflected light is strong, and the receiving tube receives a large amount of infrared light.

On a black line: the reflected light is weak, and the receiving tube receives only a small amount.

4.Signal conversion and output

The receiving tube converts the received light intensity into an electrical signal (current change). This weak electrical signal is processed by the comparator circuit on the sensor.

Strong reflection (white background) → Large current → Output low level (usually 0V) or digital signal “0”

Weak reflection (black line) → Small current → Output high level (usually 5V) or digital signal “1”

Note: The trigger signal of indicator lights differs by sensor. Some sensors output digital signal “0” when the indicator is lit; others output “1” when the indicator is lit.

Finally, the microcontroller (such as Micro:bit, Arduino, STM32, Raspberry Pi) or the robot’s main control board reads the digital high/low level to determine whether the sensor is above a black line.

Demonstration of Different Line-Tracking States

(Taking a two-channel infrared line-tracking sensor on a Micro:bit smart car as an example)

Generally divided into four cases:

1.Both probes detect the black line;

2.The left probe detects the black line, the right probe does not;

3.The right probe detects the black line, the left probe does not;

4.Both probes do not detect the black line.

How to Write the Line-Tracking Code for Smart Car

Before coding, we need to know that the core logic is:

Sensor reads data → Controller makes decision → Motor executes action

Based on the above principle:

When both probes detect the black line → the car stops;

When neither probe detects the black line → the car moves straight forward;

When the left probe detects the black line and the right does not → the car turns left;

When the right probe detects the black line and the left does not → the car turns right.

Micro:bit MakeCode graphical programming code

Example: https://makecode.microbit.org/_1d5KAJ9dCapg

Common Problems and Solutions

Q1: No response from the sensor regardless of black line or white paper, indicator light does not change

Power issue: Check if VCC and GND are reversed or loose → Ensure correct wiring.

Signal wire issue: Check whether the sensor’s signal wire is connected to the correct analog or digital pin of the controller → Verify pin definition.

Code issue: Ensure the pin number set in the code matches the actual wiring → Modify the code.

Sensor damaged → Replace with another sensor for testing.

Q2: Inaccurate recognition of black track during line tracking

Incorrect height: The sensor is too far or too close to the ground → Adjust sensor height, usually 1–2 cm.

Ambient light interference: Strong light (indoor or sunlight) contains infrared components that interfere → Use in dim indoor light.

Potentiometer not adjusted: Many analog sensors have adjustable resistors → Adjust with screwdriver until the largest difference between black and white readings.

Ground or line issue: White ground not reflective enough, or black line not dark enough → Use pure white board and black tape with high contrast.

Q3: Car rushes out at bends, cannot turn in time

Speed too fast: The forward speed is too high → Reduce motor speed in code.

Sensor missed detection: At turns, sensors may be off the line → Arrange sensors to cover bends; for complex tracks, use multi-channel line-tracking sensor.

More Extended Functions

Exp-1: Add RGB light effects during line tracking

Enhance visual feedback by changing RGB light colors during line-tracking.

Based on Micro:bit smart car,

Example code: https://makecode.microbit.org/_fVmboxgAve07

Exp-2: Multi-task execution

Color recognition stop: Place a colored paper area on the track, car stops for N seconds when detected, then continues.

Automatic obstacle avoidance: Place obstacles near track, car stops when ultrasonic sensor detects an obstacle, and resumes when cleared.

 


Tags:
【Unboxing and Reviewing】---ROSMASTER M3 Pro ROS2 Robot with Multimodal AI Large Model

Leave a comment