yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Self-balancing Robot Car📖
00.Get started quickly
  • 01.Balance car manual
  • 02.Balancing car assembly
  • 03.Get started quickly
  • 04.Balance car interface description
  • 05.Common Problem Analysis
  • 06.Balance Car V2 Library Function Development Manual
01.Environment development
  • 01.MDK-ARM installation
  • 02.STM32CubeIDE installation
  • 03.Common driver installation
  • 04.Download the program
  • 05.MDK-ARM project usage
  • 06.Program simulation
  • 07. VSCode Installation
02.STM32 getting started course
  • 01.Project creation
  • 02.LED Control(GPIO)
  • 03.Buzzer control(GPIO)
  • 04.Button control(EXTI)
  • 05.Serial communication(USART)
  • 06.Voltage detection(ADC)
  • 07.Basic timer(TIM)
  • 08.Universal timer(TIM)
  • 09.Advanced Timer(TIM)
  • 10.I2C Communication(I2C)-OLED
  • 11.SPI communication(SPI)-2.4G handle
  • 12.Independent Watchdog (IWDG)
  • 13.Window Watchdog (WWDG)
  • 14.DMA-USART
  • 15.DMA-I2C
03.STM32 expansion course
  • 01.Battery voltage detection (ADC)
  • 02.Ultrasonic module-measuring distance (TIM)
  • 03.Motor drive+encoder (TIM)
  • 04.OLED Data-Display(I2C)
  • 05.MPU6050-Data Read (I2C)
  • 06.Bluetooth module-Data reading (USART)
  • 07.2.4G handle-Data reading (SPI)
  • 08.Tracking module-Read status (GPIO)
  • 09.CCD module-Reading data (ADC)
  • 10.Electromagnetic module-Reading data (ADC)
  • 11.K210 module-Serial communication (USART)
  • 12.Tmini-Plus lidar-Reading data (USART)
04.Robot car PID control course
  • 01.PID basic concept
  • 02.PID example analysis
  • 03.P, PI, PD controller theory
  • 04.Position PID
  • 05.Incremental PID
  • 06.Cascade PID
  • 07.Balance principle of car
  • 08.Car upright control (PD)
  • 09.Car speed ​​control (PI)
  • 10.Car steering control (PD)
  • 11.Got angle and angular velocity (DMP algorithm)
  • 12.Got angle and angular velocity (Kalman filter algorithm)
  • 13.Got angle and angular velocity(Complementary filter algorithm)
05.Robot car basic course
  • 01.Car parameter adjustment
  • 02.Ultrasonic obstacle avoidance
  • 03.Ultrasonic follow
  • 04.Bluetooth remote control
  • 05.Load balance
06.Robot car advanced course
  • 01.4-channel tracking
  • 02.4-channel tracking avoid
  • 03.2.4G handle control
  • 04.CCD tracking
  • 05.CCD tracking avoid
  • 06.Electromagnetic tracking
  • 07.K210-QR code recognition
  • 08.K210-Color line tracking
  • 09.K210-Color follow
  • 10.K210-Self learning
  • 11.K210-Number recognition
  • 12.Lidar avoid
  • 13.Lidar guard
  • 14.Lidar follow
  • 15.Lidar patrol
  • 16.Lidar wall tracking-straight line
  • 17.Lidar wall tracking-multiple walls
  • 18. DIY Automatic driving car
07.Robot car LQR control
  • Robot car LQR control
08.Circuit design
  • 01.Overall circuit design
  • 02.STM32 minimum system
  • 03.Serial port circuit design
  • 04.Power circuit design
  • 05.MPU6050 Circuit Design
  • 06.Motor drive circuit design
09.Mathematical model
  • Mathematical model
10.Expand course
  • Autonomous Driving
Download
  • APP(Android)
  • Codes
  • Hardware-Info
  • SCH
  • Software Tools
  • STM32_Chip_DataSheet
  • 3D_Model_File
  • Video_PPT
Download ZIP

Welcome to Self-balancing Robot Car repository

03.2.4G handle control

2.4G handle control

2.4G handle controlHardware connectionControl principleMain codeProgram flow chartExperimental phenomenon

The tutorial mainly demonstrates the remote control function of the balance car combined with the 2.4G wireless handle.

xxxxxxxxxx
The tutorial only introduces the standard library project code

Hardware connection

PeripheralsDevelopment board
PS2: CSPB12
PS2: SCKPB13
PS2: MISOPB14
PS2: MOSIPB15

Control principle

Control the movement state of the balance car by reading the buttons of the handle.

  • 2.4G wireless handle

The 2.4G wireless handle is mainly composed of a handle and a receiver (the receiver adapter board is convenient for pin connection with the development board).

Handle

Send key information to the receiver.

Receiver

Receive the data sent by the handle and pass it to the development board; the development board can also configure the handle's sending mode by sending data through the handle.

image-20240807212212404

Handle Button Description

image-20240819100651601

Handle ButtonProgram Function DescriptionProgram Definition (Part)
Direction Key (①): △ForwardPSB_PAD_UP
Direction Key (①): ▽BackwardPSB_PAD_DOWN
Direction Key (①): ◁Turn LeftPSB_PAD_LEFT
Direction key (①): ▷Turn rightPSB_PAD_RIGHT
Function key (②): ▲ForwardPSB_TRIANGLE/PSB_GREEN
Function key (②): ×BackwardPSB_CROSS/PSB_BLUE
Function key (②): ☐Turn leftPSB_SQUARE/PSB_PINK
Function key (②): ◯Turn rightPSB_CIRCLE/PSB_RED
Joystick: ③Control direction (valid in dual light mode)PSB_L3/PSS_LX/PSS_LY
Joystick: ④Control direction (valid in dual light mode)PSB_R3/PSS_RX/PSS_RY
Button (⑤): L1/L2AcceleratePSB_L1/PSB_L2
Button (⑥): R1/R2DecelerationPSB_R1/PSB_R2
Button (⑦): STARTTurn off power saving modePSB_START
Button (⑧): MODESwitch mode (indicator light display: single light and dual light mode) 
Button (⑨): SELECTNot usedPSB_SELECT

Main code

The tutorial mainly explains the code for the 2.4G wireless controller remote control function. For detailed code, please refer to the corresponding project file.

PS2_Contorl_Car

Control the movement state of the car by reading the data of the corresponding key value.

​x
void PS2_Contorl_Car(void)
{
    //Analog value control
    g_PS2_LX = PS2_AnologData(PSS_LX);
    g_PS2_LY = PS2_AnologData(PSS_LY);
    g_PS2_RX = PS2_AnologData(PSS_RX);
    g_PS2_RY = PS2_AnologData(PSS_RY);
    g_PS2_KEY = PS2_DataKey();

    // The handle is not communicating
    if ((g_PS2_LX == 255) && (g_PS2_LY == 255) && (g_PS2_RX == 255) && (g_PS2_RY == 255))
    {
        if (g_flag == 1)
        {
            g_flag = 0;
        }
    }

    else
    {
        if (g_flag == 0)
        {
            g_flag = 1;
        }

        if((g_PS2_LX<50 && g_PS2_LY<50) || (g_PS2_RX<50 && g_PS2_RY<50))
        {
            g_newcarstate=enps2Fleft; // Front left
        }
        else if((g_PS2_LX>150 && g_PS2_LY<50) || (g_PS2_RX>150 && g_PS2_RY<50))
        {
            g_newcarstate=enps2Fright; // Front right turn
        }
        else if((g_PS2_LX<50 && g_PS2_LY>150) || (g_PS2_RX<50 && g_PS2_RY>150))
        {
            g_newcarstate=enps2Bleft; // Back left
        }
        else if((g_PS2_LX>150 && g_PS2_LY>150) || (g_PS2_RX>150 && g_PS2_RY>150))
        {
            g_newcarstate=enps2Bright; // Back right
        }
        else if((g_PS2_LY<90) || (g_PS2_RY<90))
        {
            g_newcarstate=enRUN; // go ahead
            return;
        }
            else if((g_PS2_LY>150) || (g_PS2_RY>150))
        {
            g_newcarstate=enBACK; // Back
            return;
        }
            else if((g_PS2_LX<90) || (g_PS2_RX<90))
        {
            g_newcarstate=enLEFT; // Turn left
            return;
        }
            else if((g_PS2_LX>150) || (g_PS2_RX>150))
        {
            g_newcarstate=enRIGHT; // Turn right
            return;
        }
        else
        {
            if (g_PS2_KEY == 0) // No buttons pressed
                g_newcarstate=enSTOP;
        }
    }

    // The following are key value controls
    switch (g_PS2_KEY)
    {
        case PSB_L1:
        case PSB_L2:
            speed_flag ++;
            if(speed_flag>5)
            {
                speed_flag = 5;
            }
            
            // real control
            Car_Target_Velocity +=10 ; 
            Car_Turn_Amplitude_speed +=12 ;
            if(Car_Target_Velocity > 50)
            {
                Car_Target_Velocity = 50;
            }
            if(Car_Turn_Amplitude_speed>60)
            {
                Car_Turn_Amplitude_speed =60;
            }
            break;
            

        case PSB_R1:
        case PSB_R2:
            speed_flag --;
            if(speed_flag<1)
            {
                speed_flag = 1;
            }
            
            // real control
            Car_Target_Velocity -=10 ; 
            Car_Turn_Amplitude_speed -=12 ;
            if(Car_Target_Velocity < 10)
            {
                Car_Target_Velocity = 10;
            }
            if(Car_Turn_Amplitude_speed<12)
            {
                Car_Turn_Amplitude_speed =12;
            }
            break;
        
        // forward
        case PSB_PAD_UP:
        case PSB_GREEN:
                g_newcarstate=enRUN;
                break;
        
        // back
        case PSB_PAD_RIGHT:
        case PSB_RED:
            g_newcarstate=enRIGHT;
            break;
        
        // left
        case PSB_PAD_DOWN:
        case PSB_BLUE:
            g_newcarstate=enBACK;
            
            break;
        
        // right
        case PSB_PAD_LEFT:
        case PSB_PINK:
            g_newcarstate=enLEFT;
            break;

        // stop
        default:
            if(g_flag == 1) // Red and green mode to judge
            {
                if(((g_PS2_LY >90 && g_PS2_LY < 140) && (g_PS2_LX >90 && g_PS2_LX < 140)) && ((g_PS2_RY >90 && g_PS2_RY < 140) && (g_PS2_RX >90 && g_PS2_RX < 140)))
                {
                    g_newcarstate=enSTOP;
                    break;
                }
            }
            else
            {
                g_newcarstate=enSTOP;
            }
    }
}

Program flow chart

Brief introduction to the function implementation process:

image-20240904112143574

Experimental phenomenon

Software code

The Handle_Control_Car.hex file generated by the project compilation is located in the OBJ folder of the Handle_Control_Car project. Find the Handle_Control_Car.hex file corresponding to the project and use the FlyMcu software to download the program into the development board.

xxxxxxxxxx
Product supporting information source code path: Attachment → Source code summary → 5.Balanced_Car_Extended → 03.Handle_Control_Car

Experimental phenomenon

After the program is started, press the KEY1 button according to the OLED prompt to start the handle remote control function of the balance car: OLED will display the speed level in real time!

The program has voltage detection. If the voltage is less than 9.6V, the low voltage alarm will be triggered and the buzzer will sound.
Common situations for triggering voltage alarms:
1. The power switch of the development board is not turned on, and only the Type-C data cable is connected for power supply
2. The battery pack voltage is lower than 9.6V and needs to be charged in time
4-channel tracking avoid
CCD tracking

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/中文