How to make bt control car

Bluetooth-controlled car with an Arduino and a BTS 7960 motor driver for speed control, here’s a step-by-step guide:

Components

  1. Arduino Uno( microcontroller)
  2. HC-05 Bluetooth module
  3. BTS7960 Motor Driver
  4. DC Motors Johnson 12V motors )
  5. Power Supply (12V battery for motors, Arduino power)
  6. Smartphone (Arduino Bluetooth Controller) (App)

Wiring

  1. HC-05 Bluetooth Module:
  • VCC to 5V on Arduino.
  • GND to GND on Arduino.
  • TX to RX on Arduino (SHOULD I ADD potential voltage divider for 3.3V logic ).
  • RX to TX on Arduino.
  1. BTS7960 Motor Driver:
  • RPWM and LPWM to two PWM pins on Arduino (e.g., D5 and D6 for speed control).
  • R_EN and L_EN to 5V on Arduino (for enabling motor control).
  • VCC to motor power supply (+12V).
  • GND to common ground.
  • Motor terminals connect to the output terminals of the BTS7960.
  1. Power Supply: Connect a 12V battery to the BTS7960's power input. I have a common ground between the Arduino and BTS7960 module.

This code reads commands from the Bluetooth module to control the car’s direction and speed:

#include <SoftwareSerial.h>

#define RPWM 5    // Connect to BTS7960 RPWM
#define LPWM 6    // Connect to BTS7960 LPWM

SoftwareSerial Bluetooth(2, 3);  // Bluetooth TX to D2, RX to D3

int speedValue = 0;

void setup() {
  Serial.begin(9600);
  Bluetooth.begin(9600);

  pinMode(RPWM, OUTPUT);
  pinMode(LPWM, OUTPUT);

  Serial.println("Bluetooth Car Ready");
}

void loop() {
  if (Bluetooth.available()) {
    char command = Bluetooth.read();
    
    switch (command) {
      case 'F':  // Forward
        analogWrite(RPWM, speedValue);
        analogWrite(LPWM, 0);
        break;

      case 'B':  // Backward
        analogWrite(RPWM, 0);
        analogWrite(LPWM, speedValue);
        break;

      case 'L':  // Left turn
        analogWrite(RPWM, speedValue / 2);
        analogWrite(LPWM, speedValue);
        break;

      case 'R':  // Right turn
        analogWrite(RPWM, speedValue);
        analogWrite(LPWM, speedValue / 2);
        break;

      case 'S':  // Stop
        analogWrite(RPWM, 0);
        analogWrite(LPWM, 0);
        break;

      default:  // Adjust speed
        if (command >= '0' && command <= '9') {
          speedValue = map(command - '0', 0, 9, 0, 255);
          Serial.print("Speed set to ");
          Serial.println(speedValue);
        }
        break;
    }
  }
}

Control

  1. F - Move Forward
  2. B - Move Backward
  3. L - Turn Left
  4. R - Turn Right
  5. S - Stop
  6. 0-9 - (0 for stop, 9 for full speed)`

I am going to make this ! Will it work ?
PLEASE HELP
Anything is appreciated!!
Thanks in advance!!

It looks clever and it seems to work in a simulation (without bluetooth).

  • Enter a number from 0 to 9 for speed (mapped 0 to 255)
  • Enter F, B, R, L, S
  • B and F are broken because it only uses PWM on both sides and not polarity... so F spins one direction and B spins the other direction.

This is your code without bluetooth, using Hardware Serial to enter the values...

#define RPWM 5    // Connect to BTS7960 RPWM
#define LPWM 6    // Connect to BTS7960 LPWM

int speedValue = 0;

void setup() {
  Serial.begin(9600);

  pinMode(RPWM, OUTPUT);
  pinMode(LPWM, OUTPUT);

  Serial.println("Bluetooth Car Ready");
}

void loop() {
  if (Serial.available()) {
    char command = Serial.read();

    switch (command) {
      case 'F':  // Forward
        Serial.print(command);
        analogWrite(RPWM, speedValue);
        analogWrite(LPWM, 0);
        break;

      case 'B':  // Backward
        Serial.print(command);
        analogWrite(RPWM, 0);
        analogWrite(LPWM, speedValue);
        break;

      case 'L':  // Left turn
        Serial.print(command);
        analogWrite(RPWM, speedValue / 2);
        analogWrite(LPWM, speedValue);
        break;

      case 'R':  // Right turn
        Serial.print(command);
        analogWrite(RPWM, speedValue);
        analogWrite(LPWM, speedValue / 2);
        break;

      case 'S':  // Stop
        Serial.print(command);
        analogWrite(RPWM, 0);
        analogWrite(LPWM, 0);
        break;

      default:  // Adjust speed
        Serial.print(command);
        if (command >= '0' && command <= '9') {
          speedValue = map(command - '0', 0, 9, 0, 255);
          Serial.print("Speed set to ");
          Serial.println(speedValue);
        }
        break;
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.