Arduino+TB6612+HC08 Bluetooth module drives motor, Bluetooth smart car control

Arduino+TB6612+HC08 Bluetooth module drives motor, Bluetooth smart car control

Material list:

Arduino control board
TB6612 motor drive module
HC08 Bluetooth module
DC motor (usually two, used to drive the left and right wheels of the car)

For wiring, please refer to the previous blog

When connecting HC08 to arduino, connect the TX pin on the Arduino control board to the RX pin of the HC08 Bluetooth module, and connect the RX pin to the TX pin

Next, we will use Arduino code to control the motor. Here is a detailed example code:

int pwma = 3;
int ain1 = 9;
int ain2 = 8;
int stby = 10;
int pwmb = 5;
int bin1 = 6;
int bin2 = 7;
int led = 13;

void Stop(){
    
    
  digitalWrite(ain1,LOW);
  digitalWrite(ain2,LOW);
  digitalWrite(bin1,LOW);
  digitalWrite(bin2,LOW);
}
void up(){
    
    
  digitalWrite(ain1,HIGH);
  digitalWrite(ain2,LOW);
  digitalWrite(bin1,HIGH);
  digitalWrite(bin2,LOW);
}
void back(){
    
    
  digitalWrite(ain1,LOW);
  digitalWrite(ain2,HIGH);
  digitalWrite(bin1,HIGH);
  digitalWrite(bin2,LOW);
  delay(2000);
}
void setup() {
    
    
  // put your setup code here, to run once:
  pinMode(pwma,OUTPUT);
  pinMode(ain1,OUTPUT);
  pinMode(ain2,OUTPUT);
  pinMode(pwmb,OUTPUT);
  pinMode(bin1,OUTPUT);
  pinMode(bin2,OUTPUT);
  pinMode(stby,OUTPUT);
  pinMode(led,OUTPUT);
  digitalWrite(stby,HIGH);
  analogWrite(pwma,255);
  analogWrite(pwmb,255);
  Serial.begin(9600);//初始化串口,设置串口波特率为9600
}
void loop() {
    
    
  // put your main code here, to run repeatedly:
  if(Serial.available()>0){
    
    
    char command = Serial.read();  // 读取蓝牙串口数据
    Serial.println(command);
    switch (command){
    
    
      case 'u':
      up();
      delay(2000);
      break;

      case 's':
      Stop();
      break;
      
      case 'b':
      back();
      delay(2000);
      break;
    }
	}
}

We connect the Bluetooth module through the mobile phone and send data to the serial port to control the car. Download the Bluetooth debugging assistant from the app store
Insert image description here
Insert image description here
and send commands to the serial port to control the car via Bluetooth.

Guess you like

Origin blog.csdn.net/m0_63715549/article/details/131020672