This tutorial guides you through creating a Bluetooth-controlled car using an Arduino Uno and an HC-05 Bluetooth module. Inspired by Ameya Angadi's project, this car can be controlled wirelessly via a smartphone, making it a fun and educational robotics project. Original project
Note: Connect the HC-05 module after uploading the code to avoid errors.
The Arduino code receives commands from a smartphone via the HC-05 Bluetooth
module and controls the DC motors using the L298N driver. Install the SoftwareSerial
library in the Arduino IDE.
#include
// Define pins for motor driver
#define LEFT_MOTOR_FORWARD 13
#define LEFT_MOTOR_REVERSE 12
#define RIGHT_MOTOR_FORWARD 11
#define RIGHT_MOTOR_REVERSE 10
// Define pins for Bluetooth module
#define BT_RX 3
#define BT_TX 2
SoftwareSerial bluetooth(BT_RX, BT_TX); // RX, TX
char command;
void setup() {
// Set motor pins as outputs
pinMode(LEFT_MOTOR_FORWARD, OUTPUT);
pinMode(LEFT_MOTOR_REVERSE, OUTPUT);
pinMode(RIGHT_MOTOR_FORWARD, OUTPUT);
pinMode(RIGHT_MOTOR_REVERSE, OUTPUT);
// Initialize serial communications
Serial.begin(9600);
bluetooth.begin(9600);
// Ensure motors are off initially
digitalWrite(LEFT_MOTOR_FORWARD, LOW);
digitalWrite(LEFT_MOTOR_REVERSE, LOW);
digitalWrite(RIGHT_MOTOR_FORWARD, LOW);
digitalWrite(RIGHT_MOTOR_REVERSE, LOW);
}
void loop() {
if (bluetooth.available()) {
command = bluetooth.read();
Serial.println(command); // For debugging
// Stop the car
if (command == 'S') {
digitalWrite(LEFT_MOTOR_FORWARD, LOW);
digitalWrite(LEFT_MOTOR_REVERSE, LOW);
digitalWrite(RIGHT_MOTOR_FORWARD, LOW);
digitalWrite(RIGHT_MOTOR_REVERSE, LOW);
}
// Move forward
else if (command == 'F') {
digitalWrite(LEFT_MOTOR_FORWARD, HIGH);
digitalWrite(LEFT_MOTOR_REVERSE, LOW);
digitalWrite(RIGHT_MOTOR_FORWARD, HIGH);
digitalWrite(RIGHT_MOTOR_REVERSE, LOW);
}
// Move backward
else if (command == 'B') {
digitalWrite(LEFT_MOTOR_FORWARD, LOW);
digitalWrite(LEFT_MOTOR_REVERSE, HIGH);
digitalWrite(RIGHT_MOTOR_FORWARD, LOW);
digitalWrite(RIGHT_MOTOR_REVERSE, HIGH);
}
// Turn left
else if (command == 'L') {
digitalWrite(LEFT_MOTOR_FORWARD, LOW);
digitalWrite(LEFT_MOTOR_REVERSE, HIGH);
digitalWrite(RIGHT_MOTOR_FORWARD, HIGH);
digitalWrite(RIGHT_MOTOR_REVERSE, LOW);
}
// Turn right
else if (command == 'R') {
digitalWrite(LEFT_MOTOR_FORWARD, HIGH);
digitalWrite(LEFT_MOTOR_REVERSE, LOW);
digitalWrite(RIGHT_MOTOR_FORWARD, LOW);
digitalWrite(RIGHT_MOTOR_REVERSE, HIGH);
}
}
}
Upload this code to your Arduino Uno using the Arduino IDE. Ensure the HC-05 is disconnected during upload to avoid errors.
[](https://projecthub.arduino.cc/angadiameya007/876cd251-ae53-44a4-92e9-a1444153e343)Once the code is uploaded and the hardware is connected, you can control the car using a smartphone:
Ensure the HC-05 is within 10 meters of the smartphone for reliable Bluetooth communication.
You've built a Bluetooth-controlled car using an Arduino Uno and HC-05 module! Enhance it by adding speed control with PWM, incorporating sensors for obstacle avoidance, or designing a custom chassis for better aesthetics. Experiment with different apps or add LED indicators for a more dynamic experience.