You are currently viewing Building a Bluetooth-Controlled Robot Car with Arduino, HC-05, and Adafruit Motor Shield
This robot car was built using an Arduino Uno, an Adafruit Motor Shield, and an HC-05 Bluetooth module. The image shows the control app displayed on a tablet in the background.

Building a Bluetooth-Controlled Robot Car with Arduino, HC-05, and Adafruit Motor Shield

In this Arduino Bluetooth tutorial, we will build a Bluetooth-controlled car using Arduino Uno, HC-05 Bluetooth module, and the Adafruit Motor Shield. This project covers everything from assembling the car’s chassis to programming the Arduino and developing a control app for your smartphone.

"3D rendering of a mobile robot chassis with four yellow wheels and a flat, square base. The wheels are connected to the base, showing the initial assembly stage of the robot.

By the end of this guide, you’ll have a fully functional robot car that you can control wirelessly using your Android device. You can visit this tutorial on Arduino and HC-05/HC-06 Bluetooth Module to learn how to use the HC-05 module with Arduino.

Components Needed:

  • Plexiglas sheet (for the chassis)
  • 4 DC motors with gearboxes
  • Adafruit Motor Shield V1.2
  • Arduino Uno
  • HC-05 Bluetooth Module
  • 3D-printed motor mounts and Arduino holder
  • Jumper wires
  • Battery pack and batteries
  • Smartphone with MIT App Inventor installed

Step 1: Building the Chassis for Your Bluetooth-Controlled Car

To start building your Bluetooth-controlled car, we’ll create the chassis using a Plexiglas sheet. This will serve as the base to mount all the components.

  1. Cut the Plexiglas: Measure and cut the Plexiglas sheet to your desired dimensions for the chassis.
  2. Mounts: Design and print motor mounts to securely attach the DC motors to the chassis.
  3. 3D Print Arduino Holder: Design and print a holder to securely mount the Arduino Uno on the chassis.

Step 2: Mounting the Motors

Next, we’ll mount the DC motors as part of our Bluetooth-controlled car project.

  1. Attach the Motors: Use screws and nuts to secure the DC motors to the 3D-printed motor mounts.
  2. Mount the Motors on the Chassis: Attach the motor mounts to the Plexiglas chassis using screws and nuts.

Step 3: Mounting the Arduino and Motor Shield

Secure the Arduino Uno and the Adafruit Motor Shield as we progress in our Bluetooth-controlled car tutorial.

  1. Attach the Arduino Holder: Secure the 3D-printed Arduino holder to the chassis.
  2. Mount the Arduino: Place the Arduino Uno in the holder and secure it with screws.
  3. Attach the Motor Shield: Place the Adafruit Motor Shield onto the Arduino Uno, ensuring all pins are properly aligned.

Step 4: Wiring the Components

Wiring the components correctly is crucial in this Bluetooth-controlled car project. 

  1. Connect the Motors to the Shield:
    – Connect the left motors to terminals M1 and M2 on the motor shield.
    – Connect the right motors to terminals M3 and M4 on the motor shield.
  2. Connect the HC-05 Bluetooth Module:
    – VCC to 5V on the Arduino.
    – GND to GND on the Arduino.
    – TXD to RX (Pin 0) on the Arduino.
    – RXD to TX (Pin 1) on the Arduino.
Diagram of a mobile robot using four DC motors connected to a motor controller and an Arduino. The Arduino is connected to a battery pack (AAA batteries) via a switch. The diagram shows the wiring between the motors, the motor controller, and the power source.

Step 5: Powering the Bluetooth-Controlled Car

Learn how to power your Bluetooth-controlled car in this step.

  1. Connect the Battery Pack:
    – Connect the positive and negative terminals of the battery pack to the power terminals on the motor shield.
    – Ensure the ground is connected properly.

Step 6: Programming the Arduino for Bluetooth Control

Here’s the Arduino code to control the robot car using Bluetooth commands from your smartphone. For detailed guidance on programming Arduino and controlling DC motors, check out our blog on Controlling DC Motors with L298N Dual H-Bridge and Arduino Motor Shield.

/**
 * Author: Omar Draidrya
 * Date: 2024/07/03
 * This code controls the forward and backward movement of a motor using an H-bridge.
 */

#include <AFMotor.h>

AF_DCMotor motor1(1);  // Create motor #1 using M1 connector
AF_DCMotor motor2(2);  // Create motor #2 using M2 connector
AF_DCMotor motor3(3);  // Create motor #3 using M3 connector
AF_DCMotor motor4(4);  // Create motor #4 using M4 connector

char command;

void setup() {
    Serial.begin(9600);  // Start serial communication at 9600 baud rate
    motor1.setSpeed(255);  // Set initial motor speeds
    motor2.setSpeed(255);
    motor3.setSpeed(255);
    motor4.setSpeed(255);
}

void loop() {
    if (Serial.available() > 0) {
        command = Serial.read();  // Read the incoming command

        if (command == 'F') {
            forward();
        } else if (command == 'B') {
            backward();
        } else if (command == 'L') {
            turnLeft();
        } else if (command == 'R') {
            turnRight();
        } else if (command == 'S') {
            stop();
        }
    }
}

void forward() {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
}

void backward() {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);
}

void turnLeft() {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
}

void turnRight() {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);
}

void stop() {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
    motor3.run(RELEASE);
    motor4.run(RELEASE);
}
    

Description:

This code controls a robot with four DC motors using serial Bluetooth communication. The Arduino receives commands from a smartphone and executes corresponding movements:

  1. Motor Initialization: The motors are configured using the Adafruit Motor Shield library (<AFMotor.h>) with connectors M1 to M4. Each motor is initially set to full speed.
  2. Serial Communication: The Arduino waits for serial data from the smartphone. When a command is received, it is read and stored in the variable command.
  3. Command Execution: Depending on the received command (F for forward, B for backward, L for left, R for right, S for stop), the corresponding function is called to control the motors.
  4. Movement Functions:
    forward(): All motors move forward.
    backward(): All motors move backward.
    turnLeft(): Left motors move backward, right motors move forward.
    turnRight(): Left motors move forward, right motors move backward.
    stop(): All motors stop.

Step 7: Developing the Android App for Bluetooth Control

We’ll use MIT App Inventor to create an app that will send commands to the robot via Bluetooth. To understand the basics of Arduino programming, refer to our Basics of Arduino Programming tutorial.

  1. Register and Log In:
    Go to MIT App Inventor and log in with your Google account.
  2. Create a New Project:
    Click on “Start New Project” and name it “RobotCarControl”.
  3. Design the User Interface:
    Add a ListPicker and set the text to “Select Bluetooth Device”.
    Add a BluetoothClient component from the Connectivity palette (non-visible component).
    Add four buttons for control: Forward, Backward, Left, Right, and set their colors accordingly.
  4. Program the Blocks:
    Add the following blocks to manage Bluetooth connection and send control commands.
when ListPicker1.BeforePicking
  set ListPicker1.Elements to BluetoothClient1.AddressesAndNames

when ListPicker1.AfterPicking
  if call BluetoothClient1.Connect address ListPicker1.Selection
    then set Label1.Text to "Connected"
    else set Label1.Text to "Not Connected"

when ButtonForward.TouchDown
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "F"

when ButtonBackward.TouchDown
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "B"

when ButtonLeft.TouchDown
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "L"

when ButtonRight.TouchDown
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "R"

when ButtonForward.TouchUp
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "S"

when ButtonBackward.TouchUp
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "S"

when ButtonLeft.TouchUp
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "S"

when ButtonRight.TouchUp
  if BluetoothClient1.IsConnected
    call BluetoothClient1.SendText text "S"

    

Step 8: Connecting and Testing the Robot

  1. Pair the Bluetooth Device:
    Turn on Bluetooth on your smartphone and pair with the HC-05 module (default password is 1234).
  2. Connect via App:
    Use the app to connect to the Bluetooth module.
    Use the directional buttons to control the robot.

Conclusion

Building a Bluetooth-controlled robot car is an exciting project that combines various aspects of robotics, including motor control, Bluetooth communication, and mobile app development. By following this comprehensive guide, you can create a fully functional robot car that responds to commands from your smartphone. This project not only enhances your understanding of Arduino and Bluetooth modules but also provides a solid foundation for more advanced robotics projects.

Feel free to ask any questions in the comments section below and check out my other Arduino projects for more inspiration.

omartronics

Welcome to OmArTronics, the hub for technology enthusiasts and creative minds! I'm Omar, the founder of this website and YouTube channel, and a passionate engineer with a background in electrical and mechanical engineering. I'm currently pursuing my master's in mechatronics in Germany.

Leave a Reply