How to make a simple Bluetooth control car step by step

Bluetooth Controlled Arduino Car with Speed Control

In this project, we’ll build a Bluetooth-controlled car using an Arduino, where you can control the car’s movement and speed via a smartphone app. This DIY project is perfect for beginners who want to learn about Bluetooth communication, motor control, and Arduino programming.

Overview

We will use an Arduino Uno, a Bluetooth module (HC-05), and an L298N motor driver to control the car’s movement and speed. The Arduino will receive commands from the smartphone via Bluetooth and control the car’s direction and speed accordingly. This project helps you understand basic concepts of robotics, motor control, and wireless communication.

Components Needed

Pin Allocation and Functions

Below is the pin allocation for all the components connected to the Arduino Uno:

  • Arduino Uno: Main controller.
  • HC-05 Bluetooth Module:
    • VCC – 5V (from Arduino)
    • GND – GND (from Arduino)
    • TX – RX (Pin 0 on Arduino)
    • RX – TX (Pin 1 on Arduino)
  • L298N Motor Driver: Controls the DC motors.
    • ENA – Pin 3 (PWM control for motor A speed)
    • IN1 – Pin 4 (Direction control for motor A)
    • IN2 – Pin 5 (Direction control for motor A)
    • IN3 – Pin 6 (Direction control for motor B)
    • IN4 – Pin 7 (Direction control for motor B)
    • ENB – Pin 9 (PWM control for motor B speed)
    • VCC – 12V battery pack (for motor power)
    • GND – Common ground with Arduino
  • DC Motors: Connect to the motor driver outputs.
    • Motor A – Connects to OUT1 and OUT2 on L298N
    • Motor B – Connects to OUT3 and OUT4 on L298N

Wiring Diagram

Below is a basic wiring diagram for connecting your Arduino car. Follow it carefully to ensure all components are correctly connected:

Wiring Diagram

Step-by-Step Guide

  1. Connect the Components: Assemble the car chassis and mount the DC motors. Connect the motors to the L298N motor driver, then connect the motor driver to the Arduino as per the pin allocation above. Finally, connect the HC-05 Bluetooth module to the Arduino.
  2. Upload the Arduino Code: Use the code below to program your Arduino. The code receives commands via Bluetooth and controls the speed and direction of the car.

// Arduino code for Bluetooth controlled car with speed control
char command;
int speedA = 0;
int speedB = 0;

void setup() {
    pinMode(3, OUTPUT); // ENA
    pinMode(4, OUTPUT); // IN1
    pinMode(5, OUTPUT); // IN2
    pinMode(6, OUTPUT); // IN3
    pinMode(7, OUTPUT); // IN4
    pinMode(9, OUTPUT); // ENB
    Serial.begin(9600); // Set baud rate for HC-05
}

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

        // Forward
        if (command == 'F') {
            digitalWrite(4, HIGH);
            digitalWrite(5, LOW);
            digitalWrite(6, HIGH);
            digitalWrite(7, LOW);
            analogWrite(3, speedA);
            analogWrite(9, speedB);
        }
        // Backward
        else if (command == 'B') {
            digitalWrite(4, LOW);
            digitalWrite(5, HIGH);
            digitalWrite(6, LOW);
            digitalWrite(7, HIGH);
            analogWrite(3, speedA);
            analogWrite(9, speedB);
        }
        // Left
        else if (command == 'L') {
            digitalWrite(4, LOW);
            digitalWrite(5, HIGH);
            digitalWrite(6, HIGH);
            digitalWrite(7, LOW);
            analogWrite(3, speedA / 2);
            analogWrite(9, speedB);
        }
        // Right
        else if (command == 'R') {
            digitalWrite(4, HIGH);
            digitalWrite(5, LOW);
            digitalWrite(6, LOW);
            digitalWrite(7, HIGH);
            analogWrite(3, speedA);
            analogWrite(9, speedB / 2);
        }
        // Stop
        else if (command == 'S') {
            digitalWrite(4, LOW);
            digitalWrite(5, LOW);
            digitalWrite(6, LOW);
            digitalWrite(7, LOW);
        }
        // Speed control
        else if (command == '1') {
            speedA = 100;
            speedB = 100;
        }
        else if (command == '2') {
            speedA = 150;
            speedB = 150;
        }
        else if (command == '3') {
            speedA = 200;
            speedB = 200;
        }
        else if (command == '4') {
            speedA = 255;
            speedB = 255;
        }
    }
}

Tips and Best Practices

  • Make sure all connections are secure and double-check pin allocations.
  • Ensure the Bluetooth module is paired with your smartphone before starting the car.
  • Test the car’s movement in an open area to prevent collisions while adjusting speed settings.

Conclusion

Building a Bluetooth-controlled Arduino car with speed control is an exciting project that enhances your understanding of Bluetooth communication, motor control, and Arduino programming. By following this guide, you can customize the car’s speed and control it wirelessly, making it a versatile and interactive DIY project.

Troubleshooting Tips

  • Ensure that the Bluetooth module is properly paired with your smartphone and that the correct baud rate is set in the Arduino code.
  • If the car does not respond to commands, check the wiring connections between the Arduino, Bluetooth module, and motor driver.
  • Use the Serial Monitor to debug and verify that the Arduino receives commands correctly from the Bluetooth module.

Main Menu