yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

1.2 Car line tracking-4 channel infrared tracking sensor module

Car Line Tracking - 4 Channel Infrared Tracking Sensor Module

Car Line Tracking - 4 Channel Infrared Tracking Sensor Module1. Hardware Connection2. Partial Code Analysis3. Main Functions4. Experimental Phenomenon

 

1. Hardware Connection

4 Channel Infrared Tracking Sensor ModuleMSPM0G3507
5V5V
GNDGND
X1X1
X2X2
X3X3
X4X4

启动小车 (15)

PixPin_2025-11-05_12-08-33

PixPin_2025-11-05_17-32-38

2. Partial Code Analysis

Control Principle

Start
Loop to get new data
Display sensor status
Calculate deviation err based on sensor status
Calculate PID output
Control motor movement based on results

Four_linewalking.c

​x
//带死区处理的位置式 / Positional PID with dead zone processing
float APP_IR_PID_Calc(int8_t actual_value)
{
​
    float IRTrackTurn = 0;
    int8_t error;
    static int8_t error_last=0;
    static float IRTrack_Integral;//积分 / Integral   
    
    error=actual_value;
    
    IRTrack_Integral +=error;
    
    //位置式pid / Positional PID   
    IRTrackTurn=error*IRTrack_Trun_KP
                            +IRTrack_Trun_KI*IRTrack_Integral
                            +(error - error_last)*IRTrack_Trun_KD;
    
​
​
    if (IRTrackTurn > (MAX_SPEED - MOTOR_DEAD_ZONE))
            IRTrackTurn = (MAX_SPEED - MOTOR_DEAD_ZONE);
    if (IRTrackTurn < (MOTOR_DEAD_ZONE - MAX_SPEED))
            IRTrackTurn = (MOTOR_DEAD_ZONE - MAX_SPEED);
    return IRTrackTurn;
}
//得到四路循迹模块的数据 / Get data from 4-channel line tracking module
void Four_GetLineWalking(int *LineL1, int *LineL2, int *LineR1, int *LineR2)
{
    *LineL1 = LineWalk_L1_IN;
    *LineL2 = LineWalk_L2_IN;
    *LineR1 = LineWalk_R1_IN;
    *LineR2 = LineWalk_R2_IN;
}
//
void Four_LineWalking(void)
{
​
    Four_GetLineWalking(&LineL1, &LineL2, &LineR1, &LineR2);//获取黑线检测状态 / Get black line detection status    
        sprintf((char *)oledbuf, "L2:%d L1:%d R1:%d R2:%d",
        LineWalk_L2_IN,LineWalk_L1_IN,LineWalk_R1_IN,LineWalk_R2_IN);
        OLED_ShowString(0, 10, (uint8_t *)oledbuf, 8, 1);
​
    // 0 0 X 0 / 0 0 X 0
    // 1 0 X 0 / 1 0 X 0
    // 0 1 X 0 / 0 1 X 0
    //处理右锐角和右直角的转动 / Handle right sharp angle and right straight angle turns
    if( (LineL1 == LOW || LineL2 == LOW) && LineR2 == LOW) 
    {
        err=13;
​
    }
   // 0 X 0 0 / 0 X 0 0       
   // 0 X 0 1 / 0 X 0 1 
   // 0 X 1 0 / 0 X 1 0       
   //处理左锐角和左直角的转动 / Handle left sharp angle and left straight angle turns
    else if ( LineL1 == LOW && (LineR1 == LOW || LineR2 == LOW)) 
    { 
        err=-13;
​
    }
    // 0 X X X / 0 X X X
   //最左边检测到 / Leftmost sensor detected
    else if( LineL1 == LOW )
    {  
        err=-9;
​
    }
    // X X X 0 / X X X 0
   //最右边检测到 / Rightmost sensor detected
    else if ( LineR2 == LOW)
    {  
        err=9;
​
​
    }
    // X 0 1 X / X 0 1 X
   //处理左小弯 / Handle left small turn
    else if (LineL2 == LOW && LineR1 == HIGH) //中间黑线上的传感器微调车左转 / Sensors on the middle black line slightly adjust car to turn left  
    {   
        err=-1;
    }
    // X 1 0 X / X 1 0 X  
   //处理右小弯 / Handle right small turn
    else if (LineL2 == HIGH && LineR1 == LOW) //中间黑线上的传感器微调车右转 / Sensors on the middle black line slightly adjust car to turn right 
    {   
        err=1;
    }
    // X 0 0 X / X 0 0 X
   //处理直线 / Handle straight line
    else if(LineL2 == LOW && LineR1 == LOW) // 都是黑色, 加速前进 / Both are black, accelerate forward 
    {  
        err=0;
    }   
    // 0 0 0 0 / 0 0 0 0
    else if(LineL1 == LOW && LineL2 == LOW && LineR1 == LOW && LineR2 == LOW) // 都是黑色, 加速前进 / All are black, accelerate forward
    {  
        err = 0;
    }
    
    //当为1 1 1 1时小车保持上一个小车运行状态 / When it's 1 1 1 1, the car maintains the previous running state 
    pid_output_IRR = (int)(APP_IR_PID_Calc(err));
    
        Motion_Car_Control(IRR_SPEED, 0, pid_output_IRR);
   
}
​

3. Main Functions

APP_IR_PID_Calc

Function Prototypefloat APP_IR_PID_Calc(float actual_value)
Function DescriptionImplements infrared line tracking positional PID calculation, calculates control amount based on input deviation value, and applies output limiting
Input Parametersactual_value: actual deviation value (used for PID output calculation)
Return Valuefloat type, control amount after PID calculation (with limiting applied)

Four_GetLineWalking

Function Prototypevoid Four_GetLineWalking(int *LineL1, int *LineL2, int *LineR1, int *LineR2)
Function DescriptionGets pin level status of four line tracking sensors (LineL1, LineL2, LineR1, LineR2) and returns through pointers
Input ParametersLineL1: pointer to variable storing left first sensor status; LineL2: pointer to variable storing left second sensor status; LineR1: pointer to variable storing right first sensor status; LineR2: pointer to variable storing right second sensor status
Return ValueNone

Four_LineWalking

Function Prototypevoid Four_LineWalking(void)
Function DescriptionFour-sensor line tracking main function: reads sensor status, calculates deviation value err based on different detection conditions, calls PID to calculate control amount, and finally controls car movement through Motion_Car_Control (straight line speed is IRR_SPEED, steering determined by PID output)
Input ParametersNone
Return ValueNone

4. Experimental Phenomenon

After connecting the car properly, connecting the OLED module, and burning the program to MSPM0, place the car on a white background with black lines map, the car will follow the line, and sensor data will be displayed on the OLED

Where L2, L1, R1, R2 represent the four sensor data from left to right

image-20251028201826877

Car line tracking-8 channel infrared tracking sensor module
Drawing a circle-8 channel infrared tracking sensor module

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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文