Smart car project


This blog is mainly a summary of notes to design and manufacture a toy car. This car system can have the following functions: ultrasonic distance measurement, obstacle avoidance, motor speed control, Bluetooth control and other functions. Two modes are set for obstacle avoidance mode and follow. Mode, you can make another tracking mode, but if there is no place for bad debugging, there is no writing, but the principle is similar to the first two modes. The module also uses infrared modules, which can be 2 or 4 channels, and the difference is not big.

Module debugging part

1. Ultrasonic ranging module

Principle introduction and code realization of HC-SR04 ultrasonic ranging module

2. Motor speed control module

Principle introduction and code realization of pwm motor speed regulation

3. Motor drive module

Wiring usage and code realization of L298N motor drive module

4. Bluetooth control module

The problems encountered by the HC-05 Bluetooth module and the solutions and the realization of communication with mobile phones

5. Liquid crystal display module

LED1602 LCD module introduction and its programming use

6. Synthetic voice broadcast module

TTS voice broadcast

Mode debugging part

1. Follow mode
//红外跟随模块
void InfraredFollow_Module(void)
{
    
    
  //设置小车速度,中档起步
 // Motor_SpeedSet(60000,0.8,0.8);
  
  while(1){
    
    
     
    //前面有障碍物,向前走
    while(Infrared_StraightMod == 0){
    
      
        Motor_GoForward();
        delay_ms(5);
    }
    
    //左边有障碍,向左转
    while(Infrared_LeftMod == 0){
    
      
        Motor_TurnLeft();       //左转      
        delay_ms(5);
    }
    
    //右边有障碍,向右转
    while(Infrared_RightMod == 0){
    
     
        Motor_TurnRight();      //右转
        delay_ms(5);
    }  
    Motor_BeParking();
  }
}
2. Obstacle avoidance mode
//红外避障模块
void InfraredAvoidance_Module(void)
{
    
    
    //设置小车速度,中档起步
 // Motor_SpeedSet(60000,0.8,0.8);
  
  while(1){
    
    
     Motor_GoForward();
     //左边有障碍
    while(Infrared_LeftMod == 0){
    
      
        Motor_BeParking();      //停车
        delay_ms(1000);
        Motor_TurnRight();      //右转
        delay_ms(1000);
    }
    
    //右边有障碍
    while(Infrared_RightMod == 0){
    
     
        Motor_BeParking();      //停车
        delay_ms(1000);
        Motor_TurnLeft();       //左转
        delay_ms(1000);
    }   
    
    //前面有障碍物,思路是先后退一点点,然后右转躲避
    //还可以设置一个标志为,一次右转,一次左转;或者两到三次右转,然后一次左转
    while(Infrared_StraightMod == 0){
    
      
        Motor_BeParking();      //停车
        delay_ms(1000);
        Motor_GetBack();        //后退
        delay_ms(1000);
        Motor_BeParking();      //停车
        delay_ms(1000);
        Motor_TurnRight();      //右转
        delay_ms(1000);
    }
  }
}

Physical map

Insert picture description here

Project code

stm8 intelligent follow obstacle avoidance car

Guess you like

Origin blog.csdn.net/weixin_44751294/article/details/111566666