Bluetooth Controlled Robot using Arduino

Bluetooth Controlled Robot using Arduino and HC-05

Difficulty Level: Intermediate

In this project, you'll learn how to control a simple robot using an Android smartphone or tablet via Bluetooth communication with the HC-05 module. The robot will move forward, backward, left, and right based on commands sent over Bluetooth. This is an excellent project for learning about Bluetooth communication, motor control, and robotics integration using Arduino.

Components Required

System Overview

The HC-05 Bluetooth module acts as the communication interface between the robot and an Android device. Commands are sent via a Bluetooth app, and the Arduino processes these commands to control the robot's motors through the L298N motor driver. The motor driver supplies power and direction control to the DC motors, enabling the robot to move as per the received commands.

Features

Wiring the Components

Follow these steps to wire your robot:

  1. Attach the Motors: Secure the motors to the robot chassis according to the manufacturer's guidelines. Ensure they are properly fixed to avoid disconnection during operation.
  2. Connect the Motor Driver to the Arduino: Wire the L298N motor driver to the Arduino using these connections:
    • IN1 to digital pin 8
    • IN2 to digital pin 9
    • IN3 to digital pin 10
    • IN4 to digital pin 11
  3. Connect the Motors to the Motor Driver: Attach the motor output terminals to the L298Nā€™s output pins:
    • Motor 1 ā†’ OUT1 and OUT2
    • Motor 2 ā†’ OUT3 and OUT4
  4. Connect the Bluetooth Module: Wire the HC-05 Bluetooth module as follows:
    • TX (module) to RX (Arduino pin 0)
    • RX (module) to TX (Arduino pin 1)
  5. Power the Components:
    • Connect the 9V battery to the L298N motor driver (positive to VIN and negative to GND).
    • Power the Arduino using USB or an external power supply if required.

Arduino Code

The following code controls the robot based on Bluetooth commands:


#include <AFMotor.h>

AF_DCMotor motor1(1);  // Motor 1 on M1
AF_DCMotor motor2(2);  // Motor 2 on M2

char command; // Store received command

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud rate
  motor1.setSpeed(255);  // Set speed to max (255)
  motor2.setSpeed(255);
}

void loop() {
  if (Serial.available() > 0) {
    command = Serial.read();  // Read the incoming command
    
    if (command == 'F') {  // Forward
      motor1.run(FORWARD);
      motor2.run(FORWARD);
    } 
    else if (command == 'B') {  // Backward
      motor1.run(BACKWARD);
      motor2.run(BACKWARD);
    } 
    else if (command == 'L') {  // Left turn
      motor1.run(BACKWARD);
      motor2.run(FORWARD);
    } 
    else if (command == 'R') {  // Right turn
      motor1.run(FORWARD);
      motor2.run(BACKWARD);
    } 
    else if (command == 'S') {  // Stop
      motor1.run(RELEASE);
      motor2.run(RELEASE);
    }
  }
}
        

Tips for Customization

Android App Setup

To control the robot, you can use popular apps like:

Ensure your smartphone is paired with the HC-05 module and use the apps to send commands ('F', 'B', 'L', 'R', 'S').

Upload and Test

  1. Upload the provided code to your Arduino using the Arduino IDE.
  2. Pair your Android device with the HC-05 module (default PIN: 1234 or 0000).
  3. Open your chosen Bluetooth app and connect it to the HC-05 module.
  4. Send control commands to move the robot in the desired direction.

Common Issues and Troubleshooting

Conclusion

Congratulations! You've successfully built a Bluetooth-controlled robot. This project is a stepping stone to more advanced robotics projects. Try adding sensors, improving the control interface, or expanding its capabilities with custom software and hardware upgrades.