yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
8-channel Grayscale Tracking Module📖
0. Precautions for use
  • Identifying Defective Solutions
1.About 8-channel tracking module
  • 8-channel grayscale module introduction
2.MCU data reading
  • 1.MSPM0G3507
  • 2.MSPM0G3519new
  • 3.STM32F103C8T6
  • 4.ESP32
  • 5.Arduino
  • 6. Raspberry Pi Pico
3.Car gray line tracking
  • 1. MSPM0 Smart Car
  • 2. STM32 development board for small car
  • 3. ESP32 wheeled car chassis V1
  • 4. Arduino Wheeled Car Chassis V2
  • 5. Raspberry Pi Pico Wheel Car Chassis V2
Download
  • Code
  • 3D Model File
  • Serial Port Assistant
Download ZIP

Welcome to 8-channel Grayscale Tracking Module repository

1. MSPM0 Smart Car

Eight-channel grayscale moduleHardware WiringPartial Code AnalysisMain FunctionsExperimental Phenomena

Eight-channel grayscale module

Our store offers four types of eight-channel grayscale modules: distinguished by light color, namely: Red, Green, Blue, White. Different colored grayscale modules are suitable for different line inspection scenarios. The provided source code is applicable to all sensors.

Sensor ClassificationRedGreenBlueWhite
White backgroundGreen, Cyan, Blue, BlackRed, Blue, Purple, BlackYellow, Red, Green, BlackBlack
Black backgroundRed, Orange, Yellow, WhiteGreen, Yellow, Cyan, WhiteBlue, Purple, Cyan, WhiteWhite

Hardware Wiring

Eight-channel grayscale moduleMSPM0G3507
5V5V
GNDGND
AD2X1
AD1X2
AD0X3
OUTX4

Start the car

image-20251030204804857

Partial Code Analysis

Control Principle

Line Following Control Logic
Calculate the deviation based on x1-x8 to get err
Get data from x1-x8 sensors
Calculate the steering amount using positional PID
Control the car's movement based on the PID output

Modify the effective level by changing ACTIVE_VALUE to 0/1

bsp_ir_eight.c

x
​
/**
* @brief Read the status of eight infrared sensors
​
* @param ir_results An array of length 8, used to store the status (0/1) of each channel
​
*/ 
void ReadEightIR(uint8_t ir_results[8]) {
​
    for (int channel = 0; channel < 8; channel++) {
        // Calculate the C, B, and A values corresponding to the current channel (C is the most significant bit, A is the least significant bit)
        uint8_t c = (channel >> 2) & 0x01;
        uint8_t b = (channel >> 1) & 0x01;
        uint8_t a = channel & 0x01;       
        SET_CHANNEL(c, b, a); // Set the channel selection pin 
                //This delay time can be adjusted to a stable state
        delay_us(100);
        // Read the infrared status of the current channel and store it in the result array
        ir_results[channel] = READ_IR_OUT() ? 1 : 0;            
    }
}
​

bsp_ir_eight.h

x
#define EIGHT_IR_PORT Eight_IR_PORT // Port
#define EIGHT_IR_AD0_PIN Eight_IR_AD0_X3_PIN // Channel selection: A (least significant bit)
#define EIGHT_IR_AD1_PIN Eight_IR_AD1_X2_PIN // Channel selection: B
#define EIGHT_IR_AD2_PIN Eight_IR_AD2_X1_PIN // Channel selection: C (most significant bit)
#define EIGHT_IR_OUT_PIN Eight_IR_OUT_X4_PIN // Infrared detection output pin
​
// Set the level (0 or 1) of channel selection pins C, B, and A
#define SET_CHANNEL(c_val, b_val, a_val) \
    do { \
        GPIO_setPins(EIGHT_IR_PORT, EIGHT_IR_AD2_PIN, c_val); \
        GPIO_setPins(EIGHT_IR_PORT, EIGHT_IR_AD1_PIN, b_val); \
        GPIO_setPins(EIGHT_IR_PORT, EIGHT_IR_AD0_PIN, a_val); \
    } while(0)
​

Main Functions

ReadEightIR

Function Prototypevoid ReadEightIR(uint8_t ir_results[8])
Function DescriptionReads the status of eight infrared sensors and stores the status (0 or 1) of each channel into a specified array. Channel selection is achieved by calculating the corresponding C, B, and A values. The status is read and stored after a 1ms delay.
Input Parametersir_results: An 8-byte uint8_t array used to store the status of the eight infrared sensors (0 indicates no detection, 1 indicates detection).
Return ValueNone

Experimental Phenomena

After connecting the car to the OLED module and programming the MSPM0, place the car on the map. The car will automatically start tracking, and the sensor data will be displayed on the OLED. Due to differences in motor parameters and ground material, if the tracking effect is poor, the parameters need to be adjusted manually.

image-20251028191614823

Raspberry Pi Pico
STM32 development board for small car

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文