Labs / Bipes + MicroPython / 7 Sensors: Enable Programs to "Perceive the World"

7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! —— Single-channel line tracking module based on TCR5000L

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, now let's unlock the super fun "path-tracking magic tool" – the single-line tracking module ✨! It acts as the "eyes" of your car, capable of accurately distinguishing between black and white lines, so your smart car can follow the black line obediently without manual control. Isn't that totally cool?

1. Module Introduction

When playing with a smart car, have you ever wanted it to automatically follow a pre-drawn route? The single-channel tracking module is exactly the "little expert" for this job!

A single-channel tracking module is a infrared reflective sensor module: it continuously emits infrared light outwards, and when the infrared light hits the ground of different colors, the intensity of the reflected light varies completely — black absorbs most of the infrared light and reflects very little, while white reflects most of the infrared light. After detecting the intensity difference of the reflected light, the module will output different level signals to inform the development board "I've spotted a black line" or "I've spotted a white line"!

Compared with manually controlled trolleys, it boasts these extremely practical features:

In graphical programming, the single-channel line-tracking module mainly uses these blocks:

In practical projects, it is often used for the following purposes:

Quick Science Pop

Why do black and white surfaces produce different reflection effects? The reason is that black objects have a relatively rough surface and can absorb light of all wavelengths, including infrared light; in contrast, the surface of white objects reflects most incoming light. When infrared light hits a white object, it is reflected back to the receiving end of the module, which allows the module to distinguish between these two colors!

2. Wiring Instructions

To make the line-tracking module help the car "see the road", the first step is still to connect the wires correctly!

7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! —— Single-channel line tracking module based on TCR5000L

We connect the single-channel tracking module to the DIO0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 6

DIN

Tracking probe digital signal input pin

Pin 7

NC

-

📌 Note

3. Calibration Instructions

Before using the single-channel tracking module based on TCR5000L, you need to perform calibration first:

7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! —— Single-channel line tracking module based on TCR5000L
  1. White background calibration: Aim the probe at a pure white background and observe DO indicator and output; adjust the R5 potentiometer to turn on the indicator.
  2. Black line calibration: Align the probe with the center of the black line, and keep adjusting the potentiometer until the indicator light goes out;
  3. Boundary verification: Slowly move the module, it should switch quickly at the black-and-white boundary without prolonged jitter; if the switching is blurry, fine-tune the potentiometer until the boundary is clear.

4. Example: Detect black and white lines and print a prompt

Experiment Objective: To implement the most basic line-tracking detection function: when the single-channel line-tracking module is aligned with a black line, the terminal will print "Black line detected"; when it is aligned with a white line, the terminal will print "White line detected", so that you can intuitively observe the detection effect of the module.

Fun Little Thought: The reason why robot vacuums can automatically avoid stairs and clean along the edges of walls is that they rely on similar sensors to detect changes in the ground surface. Now, let's make a "tiny detector that can tell black lines apart from white ones"!

The graphical program is as follows:

7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! —— Single-channel line tracking module based on TCR5000L

Building Block Assembly Steps:

  1. infinite loop
  1. Read the tracking status
  1. conditional judgment
  1. Add delay (optional)

Experimental Effect:

Graphical blocks will be automatically converted into MicroPython code for execution on the development board:

7.9 How to make a small car run along the black line automatically without deviation? Realize automatic line tracking without off-track! —— Single-channel line tracking module based on TCR5000L

Directly importable building blocks:

Line-tracking module.xml 2 KB

Tips

  1. If there is no response from the test:
  • Check whether the pins are selected correctly;
  • Adjust the height of the module from the ground; the optimal height is generally 2 to 5 millimeters.
  1. Ambient light will affect the detection result:
  • Under direct strong light, the module may make misjudgments, so it is recommended to conduct the experiment under indoor natural light as much as possible;
  1. For more accurate detection:
  • You can attach a black light shield to the bottom of the module to reduce interference from external light.

✨ Interactive Mini Quiz

  1. Think about it: If the installation height of the module is adjusted to 10 mm, will the detection effect become better or worse? And why?
  2. Try it out: Replace the black and white lines with red and blue paper, and see if the module can detect them. What does this indicate – does the line-tracking module recognize colors or light reflectance?

Summary

  1. The single-channel tracking module is a infrared reflective sensor that distinguishes between black and white lines by detecting the intensity of reflected light;
  2. Compared with manual control, it enables the trolley to automatically recognize the route and realize tracking navigation;
  3. The basic function is to detect black and white lines, and the advanced usage is to control the car to follow the track in coordination with the motor module;
  4. The installation height and ambient light will affect the detection accuracy, so patient adjustment is required.