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.
By the end of this guide, youāll have a fully functional robot car that you can control wirelessly using your Android device.
Ā
Components Needed:
Ā
Plexiglas sheet (for the chassis)4 DC motors with gearboxes - BUY NOW
Adafruit Motor Shield V1.2Arduino Uno - BUY NOW
HC-05 Bluetooth Module3D
printed motor mounts andĀ
Arduino holder
Jumper wires- BUY NOW
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.
Cut the Plexiglas: Measure and cut the Plexiglas sheet to your desired dimensions for the chassis.Mounts: Design and print motor mounts to securely attach the DC motors to the chassis.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.
Attach the Motors: Use screws and nuts to secure the DC motors to the 3D-printed motor mounts.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.
Attach the Arduino Holder: Secure the 3D-printed Arduino holder to the chassis.Mount the Arduino: Place the Arduino Uno in the holder and secure it with screws.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.Ā
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.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.

Ā
Step 5: Powering the Bluetooth-Controlled Car
Learn how to power your Bluetooth-controlled car in this step.
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.
Ā
Ā
Ā * This code controls the forward and backward movement of a motor using an H-bridge.
Ā */
#include
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:
Motor Initialization: The motors are configured using the Adafruit Motor Shield library () with connectors M1 to M4. Each motor is initially set to full speed.
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.
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.
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.Ā
Ā
Register and Log In:
Go to MIT App Inventor and log in with your Google account.
Create a New Project:
Click on āStart New Projectā and name it āRobotCarControlā.
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.
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
Pair the Bluetooth Device:
Turn on Bluetooth on your smartphone and pair with the HC-05 module (default password is 1234).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.
