Line Tracking Sensor (Digital)
Overview
Can be used for line tracking detection. When black is detected, it outputs a high level; when white is detected, it outputs a low level.
Based on the infrared reflection principle, the infrared emitting diode continuously emits infrared light, and the infrared phototransistor receives the reflected infrared light. Since white reflects infrared strongly and black reflects infrared weakly, it can detect black and white lines.
Technical Specifications
Operating voltage: VCC 3.3V -5V
Module dimensions: 24*48mm
Mounting: 2 plastic building block compatible through-holes
Data type: Black–1 White–0
Detection distance: 0.5-1cm
Pin Definition
Pin |
Definition |
|---|---|
GND |
Ground |
VCC |
Power |
D1 |
D 1 trigger value |
D2 |
D 2 trigger value |
Example Code
1. When installing the line tracking module, keep it about 1cm from the tracking line;
2. The tracking line width should be at least 15mm;
3. Black electrical tape can be used to DIY the tracking line for better results.
from mpython import *
p13 = MPythonPin(13, PinMode.IN)
p14 = MPythonPin(14, PinMode.IN)
from mpython import ledong_shield
def boolean_P13():
return p13.read_digital() == 1
def boolean_P14():
return p14.read_digital() == 1
while True:
if boolean_P13() and boolean_P14():
ledong_shield.set_motor(1, -60)
ledong_shield.set_motor(2, 60)
elif boolean_P13() and not boolean_P14():
ledong_shield.set_motor(1, 10)
ledong_shield.set_motor(2, 60)
elif boolean_P14() and not boolean_P13():
ledong_shield.set_motor(1, -60)
ledong_shield.set_motor(2, -10)
elif not boolean_P13() and not boolean_P14():
ledong_shield.set_motor(1, -0)
ledong_shield.set_motor(2, 0)