close

DEV Community

Cover image for Build Your Own Bluetooth-Controlled Car with Arduino: A Complete Step-by-Step Guide
Danieldsouza
Danieldsouza

Posted on

Build Your Own Bluetooth-Controlled Car with Arduino: A Complete Step-by-Step Guide

Introduction

The intersection of robotics and wireless communication is one of the most exciting areas for any aspiring embedded engineer or hobbyist. Whether you are looking to understand motor dynamics or explore how hardware interfaces with mobile applications, building a Bluetooth-controlled car is the quintessential "Hello World" of robotics.

In this guide, we will walk through the process of assembling a two-wheeled robotic car from scratch using an Arduino Uno, an L293D Motor Driver Shield, and an HC-05 Bluetooth module. By the end of this tutorial, you will have a fully functional vehicle that you can control directly from your Android smartphone.

The Components: Building the Brain and Body

Before we pick up the screwdriver, let’s look at the "Bill of Materials" (BOM) required for this project.

  1. Arduino Uno: The brain of our project. It’s an open-source microcontroller board based on the Microchip ATmega328P.

  2. L293D Motor Driver Shield: This is crucial because microcontrollers cannot provide enough current to drive motors directly. The shield acts as the bridge between high-current motors and low-power logic.

  3. HC-05 Bluetooth Module: This module enables Serial communication over Bluetooth, allowing us to send commands from a phone.

  4. DC Gear Motors & Wheels: We’ll use two 5V-9V DC motors for movement and a single universal (caster) wheel for balance.

  5. Acrylic Chassis: A lightweight frame to house all components.

  6. Power Source: Two 9V batteries—one to power the Arduino logic and another dedicated to the motors to prevent voltage drops.

Step 1: Mechanical Assembly

A solid build starts with a stable frame.

Mounting the Motors

Start with the acrylic chassis. Peel off any protective film. Position the DC motors on the left and right sides of the chassis. Use the provided fasteners and screws to secure them.

-Pro Tip: Ensure the motor terminals are facing inward toward the center of the chassis to make wiring cleaner later on.

Installing the Caster Wheel

The caster wheel (universal wheel) provides a third point of contact, ensuring the car remains stable while turning. Use the provided spacers to ensure the caster wheel is at the same height as the main driving wheels.

Mounting the Arduino Uno

Using M3 screws or double-sided mounting tape, secure the Arduino Uno onto the top of the chassis. Make sure the USB port and DC Jack are easily accessible.

Step 2: The Wiring & Electronics

Now, let's connect the nervous system of our robot.

1. Attaching the Motor Shield

Carefully align the pins of the L293D Motor Driver Shield with the headers on the Arduino Uno and press down firmly. This "sandwich" configuration eliminates the need for most jumper wires.

2. Motor Connections

Connect the wires from your left motor to the terminal blocks labeled M1 on the shield. Connect the right motor to M2.

  • Direction Logic: In our code, we assume the red wire is "Positive." If your car moves backward when it should move forward, simply swap the red and black wires for that specific motor terminal.

3. Bluetooth Module (HC-05) Wiring

The HC-05 uses UART (Universal Asynchronous Receiver/Transmitter) communication.

  • VCC to 5V on the shield.
  • ND to Ground.
  • TX (Transmit) to A0 on the Arduino.
  • RX (Receive) to A1 on the Arduino. Note: While the HC-05 traditionally uses pins 0 and 1, we use Analog pins A0 and A1 with the SoftwareSerial library to keep the hardware serial port free for debugging and code uploading.

Step 3: Programming the Arduino

To make the hardware "smart," we need to upload the logic. We will use two primary libraries: AFMotor.h (for the shield) and SoftwareSerial.h (for Bluetooth).
`#include

include

// Initialize Motors on M1 and M2 ports
AF_DCMotor leftMotor(1);
AF_DCMotor rightMotor(2);

// Define Bluetooth Pins (RX, TX)
SoftwareSerial bluetooth(A0, A1);

char command;

void setup() {
bluetooth.begin(9600); // Standard Baud rate for HC-05
leftMotor.setSpeed(200); // Set speed from 0 (off) to 255 (max)
rightMotor.setSpeed(200);
}

void loop() {
if (bluetooth.available() > 0) {
command = bluetooth.read();
stopMotors(); // Reset state

switch (command) {
  case 'F': forward();  break;
  case 'B': backward(); break;
  case 'L': left();     break;
  case 'R': right();    break;
  case 'S': stopMotors(); break;
}
Enter fullscreen mode Exit fullscreen mode

}
}

void forward() {
leftMotor.run(FORWARD);
rightMotor.run(FORWARD);
}

void stopMotors() {
leftMotor.run(RELEASE);
rightMotor.run(RELEASE);
}
// Additional functions for backward, left, and right follow similar logic...`

Step 4: The Mobile App Configuration

  • Pairing: Turn on your car. Go to your phone's Bluetooth settings and pair with "HC-05." The default PIN is usually 1234 or 0000.
  • Connecting: Open the app, click the "Settings" icon, and select "Connect to Car."
  • Command Mapping: Ensure the app is sending 'F' for forward, 'B' for back, etc. These match the switch-case characters in our Arduino code.

Step 5: Testing and Troubleshooting

Place the car on a flat surface and hit the "Forward" button.

  • Car goes in circles? One of your motor's wires is likely swapped.
  • Bluetooth won't connect? Check if the LED on the HC-05 is blinking rapidly (searching) or slowly (connected). Ensure the TX/RX pins aren't swapped.
  • Motors stuttering? This is usually a power issue. Ensure your motor battery is fresh. Using a Rechargeable Li-ion battery (like an 18650) often provides better current than a standard alkaline 9V.

Conclusion

Building a Bluetooth-controlled car is more than just a fun weekend project; it's an introduction to the world of Embedded Systems. You've learned how to manage power, interface with motor drivers, and establish wireless serial communication.

What's next?

  • Add an Ultrasonic Sensor for autonomous obstacle avoidance.
  • Integrate a Servo Motor to move a camera or a sensor head.
  • Upgrade to an ESP32 for Wi-Fi control and camera streaming.

Top comments (0)