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
- 1 x Arduino Uno
- 1 x Bluetooth Module HC-05
- 1 x L298N Motor Driver
- 2 x DC Motors with Wheels
- 1 x Robot Chassis
- 1 x 9V Battery
- 1 x Power Switch (optional for easy control)
- Jumper wires and breadboard
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
- Wireless control using Bluetooth communication.
- Basic directional movement: forward, backward, left, right, and stop.
- Customizable commands and speed control options.
- Expandable to include sensors for additional functionality.
Wiring the Components
Follow these steps to wire your robot:
- 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.
-
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
-
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
-
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)
-
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
- Speed Control: Use the
setSpeed()
function of theAFMotor
library to adjust motor speeds for finer control. - Additional Features: Add ultrasonic sensors for obstacle detection, enabling autonomous navigation.
- App Development: Develop a custom Android app to add a graphical interface for controlling your robot.
- Advanced Commands: Add more commands to trigger specific actions like dancing or spinning.
Android App Setup
To control the robot, you can use popular apps like:
- Bluetooth Terminal: Send commands using a simple text-based interface.
- Arduino Bluetooth Controller: A dedicated app for robot control with customizable buttons.
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
- Upload the provided code to your Arduino using the Arduino IDE.
- Pair your Android device with the HC-05 module (default PIN: 1234 or 0000).
- Open your chosen Bluetooth app and connect it to the HC-05 module.
- Send control commands to move the robot in the desired direction.
Common Issues and Troubleshooting
- Connection Problems: Ensure the HC-05 module is correctly powered and the pairing process is successful.
- Motor Not Moving: Check motor driver connections and power supply voltage.
- Incorrect Movement: Verify the wiring of the motors to the motor driver and the motor driver's input pins to the Arduino.
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.