3.4 Detect the Line

The line tracking module is used to detect whether there are black areas on the ground, such as black lines pasted with electrical tape.

One of its LEDs emits appropriate infrared light to the ground, and the black surface has a relatively strong ability to absorb light and a weaker reflection ability. White surfaces are the opposite. If it detects reflected light, it means the ground is currently white. If not detected, it means black.

That’s how it works.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

3 in 1 Starter Kit

380+

3 in 1 Starter Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

SunFounder R3 Board

BUY

Jumper Wires

BUY

Line Tracking Module

BUY

Schematic

../_images/circuit_3.4_line.png

The digital pin 2 is used to read the signal of line track module. We get the VCC of the module connected to 5V, GND to GND, OUT to digital pin 2.

Wiring

../_images/detect_the_line_bb.jpg

Code

Note

  • You can open the file 3.4.detect_the_line.ino under the path of 3in1-kit\basic_project\3.4.detect_the_line.

  • Or copy this code into Arduino IDE.

  • Or upload the code through the Arduino Web Editor.

When the line tracking module detects there is black line, there appears [1] on the Serial Monitor; otherwise, [0] is displayed.