Creating a Bluetooth controlled object following robot gives you one of the most exciting ways to learn robotics, automation, coding, and IoT. Even better, you build a robot that switches between automatic mode and manual Bluetooth control, which helps you understand real-world robotic technologies. In this complete step-by-step guide, you explore everything, and you also test every component before you upload the final working code. As you move forward, you study sensors, motor drivers, servos, Bluetooth modules, ultrasonic ranging, and smart robot movement decisions. You also upload the full working source code that runs your Bluetooth controlled object following robot exactly as expected.
Because this project mixes manual control and automatic obstacle following, you enjoy full flexibility. You take control from your mobile app when you want, and you allow the robot to follow objects or avoid obstacles automatically when needed. That flexibility makes the Bluetooth controlled object following robot more advanced and more powerful than basic DIY bots, and you will see that clearly as you move through each section.
1. You Understand Real Robotics by Building a Complete System
When you design a Bluetooth controlled object following robot, you experience real robotics, because real robots combine sensors, logic, actuators, and communication. You do not just build a toy; instead, you build a functional robot that senses distance in real time, reacts instantly, and communicates through Bluetooth. This hands-on approach helps you understand robotics more efficiently than theory-only learning.
Furthermore, you see how the ultrasonic sensor reads the environment, and you watch how the servo rotates to scan left and right, and your robot decides the best direction to move. That gives you a complete understanding of perception and decision-making—two essential robotics concepts.
2. You Control the Robot Smoothly Through Bluetooth
The best part of creating a Bluetooth controlled object following robot comes from enjoying instant mobile control. You use any Bluetooth controller app, send commands like F, B, L, R, and S, and the robot responds immediately. This instant feedback teaches you how serial communication works and how control signals travel wirelessly.
Moreover, Bluetooth control helps you test your motors, wheels, and servo movement precisely before you enable automatic mode. When you combine smooth control with efficient response, your Bluetooth controlled object following robot operates like a mini professional platform.
3. You Learn Object Following and Obstacle Avoidance Logic
Because your robot uses an ultrasonic sensor, you create real object-following logic. You measure distance, check for obstacles, and choose forward, backward, or turning movement. This allows your Bluetooth controlled object following robot to react intelligently.
When the robot detects an obstacle at less than 15 cm, it stops immediately. Then the servo rotates left and right to analyze the environment. The robot then selects the direction with more space. This intelligent decision-making process helps you understand the fundamentals of autonomous robotics.
4. You Test All Components Before Uploading the Final Code
A professional always verifies every component before building the final system. Because of that, this guide gives you three important test codes:
✔ Ultrasonic Sensor Test
✔ Servo Motor Test
✔ Motor Driver Test (included inside the main code)
You test the ultrasonic sensor first, you verify the servo positions next, and then you use Bluetooth commands to check motor movement. These steps ensure your Bluetooth controlled object following robot works smoothly when you assemble the full system.
5. You Use Efficient Active-Voice Code That Responds Instantly
Every part of your code uses active voice. Your robot reads the sensor, checks the distance, turns the servo, decides direction, and moves with immediate action. Because you remove passive structures, the logic stays clean and straightforward. That makes your Bluetooth controlled object following robot much easier to understand, modify, and improve.
6. You Build a Robot With Two Powerful Modes
Your robot includes:
🔹 Manual Bluetooth Mode
You control the robot directly using your phone.
🔹 Automatic Object Following / Obstacle Avoidance Mode
The robot thinks and moves independently.
This dual-mode flexibility transforms your Bluetooth controlled object following robot into a much more advanced project than a simple manually driven car. Students, hobbyists, and beginners love this because it improves both learning and practical use.
7. You Follow a Step-By-Step Circuit Diagram and Wiring Explanation
Here is your complete wiring plan for the Bluetooth controlled object following robot:

🔌 Ultrasonic Sensor Wiring
Trig → A1
Echo → A0
VCC → 5V
GND → GND
🔌 Servo Motor Wiring
Signal → Pin 10
VCC → 5V
GND → GND
🔌 Motor Driver (Adafruit Motor Shield)
M1 → Front Left Motor
M2 → Front Right Motor
M3 → Back Left Motor
M4 → Back Right Motor
Power → External Battery (7.4–12V recommended)
🔌 Bluetooth Module HC-05 / HC-06
TX → RX (Pin 0)
RX → TX (Pin 1)
VCC → 5V
GND → GND
These connections complete the electrical backbone of your Bluetooth controlled object following robot.
8. You Upload and Test the Ultrasonic Sensor Code First
Before assembling everything, run this ultrasonic sensor test:
// Ultrasonic Sensor Test Code
// Measures distance and displays it on Serial Monitor
// Pin definitions
#define Echo A0
#define Trig A1
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
Serial.println("Ultrasonic Sensor Test");
Serial.println("-----------------------");
delay(1000);
}
// Function to measure distance
long getDistance() {
// Send trigger pulse
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
// Measure echo pulse duration
long duration = pulseIn(Echo, HIGH);
// Convert to distance in cm
// Speed of sound = 340 m/s = 0.034 cm/microsecond
// Distance = (time * speed)/2 (for round trip)
// Distance = (duration * 0.034)/2 = duration * 0.017
// Or simpler: duration / 58.2
long distance = duration / 58;
return distance;
}
void loop() {
// Get distance measurement
long distance = getDistance();
// Display results
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" cm");
// Add visual indicator
Serial.print(" [");
for (int i = 0; i < 50; i++) {
if (i < distance && distance <= 50) {
Serial.print("=");
} else {
Serial.print(" ");
}
}
Serial.print("]");
// Add warning if obstacle is close
if (distance < 5) {
Serial.print(" VERY CLOSE!");
} else if (distance < 15) {
Serial.print(" Close!");
} else if (distance > 200) {
Serial.print(" Out of range");
}
Serial.println(); // New line
// Add different test scenarios
if (distance < 10) {
Serial.println("*** WARNING: Object very close! ***");
} else if (distance < 30) {
Serial.println("Object detected nearby");
} else if (distance > 400) {
Serial.println("No object detected within range");
}
// Wait before next measurement
delay(500); // Measure twice per second
}This code ensures your robot senses the world accurately. A Bluetooth controlled object following robot relies heavily on distance measurement, so this step matters.
9. You Upload the Servo Motor Test Next
// Servo Motor Test Code
// Tests full range of motion and various positions
#include <Servo.h>
#define SERVO_PIN 10 // Connect servo signal wire to pin 10
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(SERVO_PIN);
Serial.println("=================================");
Serial.println(" SERVO MOTOR TEST CODE");
Serial.println("=================================");
delay(1000);
}
void loop() {
Serial.println("\n=== Testing Full Range ===");
// Test 1: Sweep from 0 to 180 degrees
Serial.println("Sweeping from 0° to 180°...");
for (int pos = 0; pos <= 180; pos += 5) {
myServo.write(pos);
Serial.print("Position: ");
Serial.print(pos);
Serial.println("°");
delay(50); // Faster sweep for test
}
delay(1000);
// Test 2: Center position
Serial.println("\nMoving to center (90°)...");
myServo.write(90);
delay(1000);
// Test 3: Specific positions
Serial.println("\n=== Testing Specific Positions ===");
int testPositions[] = {0, 30, 60, 90, 120, 150, 180};
for (int i = 0; i < 7; i++) {
Serial.print("Moving to ");
Serial.print(testPositions[i]);
Serial.println("°");
myServo.write(testPositions[i]);
delay(1000);
}
// Test 4: Return to center
Serial.println("\nReturning to center...");
myServo.write(90);
delay(1000);
Serial.println("\nTest complete! Restarting...");
delay(2000);
}After this step, your servo moves correctly, which helps your Bluetooth controlled object following robot scan left and right efficiently.
Add library : https://github.com/adafruit/Adafruit-Motor-Shield-library
: https://eleobo.com/fix-afmotor-h-no-such-file-or-directory-and-newping-h/
Download Bluetooth Controller app (BlueBot Controller)
10. You Upload the Final Full Working Code
Now upload your complete project code:
#include <AFMotor.h>
#include <Servo.h>
#define Echo A0
#define Trig A1
#define SERVO_PIN 10
#define MOTOR_SPEED 200
#define TURN_DURATION 500 // Reduced for more precise turns
// Motor Definitions
AF_DCMotor M1(1);
AF_DCMotor M2(2);
AF_DCMotor M3(3);
AF_DCMotor M4(4);
Servo servo;
bool automaticModeEnabled = false;
// Scan result structure
struct ScanResult {
long leftDist;
long centerDist;
long rightDist;
};
void setup() {
Serial.begin(9600);
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
servo.attach(SERVO_PIN);
servo.write(90);
// Initialize motors
M1.setSpeed(MOTOR_SPEED);
M2.setSpeed(MOTOR_SPEED);
M3.setSpeed(MOTOR_SPEED);
M4.setSpeed(MOTOR_SPEED);
Serial.println("Bluetooth control ready!");
}
long getDistance() {
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
long duration = pulseIn(Echo, HIGH, 30000); // 30ms timeout
if (duration == 0) return 400; // No echo = far away
return duration / 58;
}
void moveForward() {
M1.run(FORWARD);
M2.run(FORWARD);
M3.run(FORWARD);
M4.run(FORWARD);
}
void moveBackward() {
M1.run(BACKWARD);
M2.run(BACKWARD);
M3.run(BACKWARD);
M4.run(BACKWARD);
}
void turnLeft() {
M1.run(FORWARD);
M3.run(FORWARD);
M2.run(BACKWARD);
M4.run(BACKWARD);
}
void turnRight() {
M1.run(BACKWARD);
M3.run(BACKWARD);
M2.run(FORWARD);
M4.run(FORWARD);
}
void stopMotors() {
M1.run(RELEASE);
M2.run(RELEASE);
M3.run(RELEASE);
M4.run(RELEASE);
}
// Scan surroundings and find best path
ScanResult scanArea() {
ScanResult result;
// Look left
servo.write(20);
delay(400);
result.leftDist = getDistance();
Serial.print("Left: "); Serial.println(result.leftDist);
// Look center
servo.write(90);
delay(400);
result.centerDist = getDistance();
Serial.print("Center: "); Serial.println(result.centerDist);
// Look right
servo.write(160);
delay(400);
result.rightDist = getDistance();
Serial.print("Right: "); Serial.println(result.rightDist);
// Return to center
servo.write(90);
delay(300);
return result;
}
// Enhanced automatic obstacle avoidance
void automaticMode() {
long frontDistance = getDistance();
// Emergency backup if too close (<10cm)
if (frontDistance < 10) {
Serial.println("Too close! Emergency backup");
stopMotors();
delay(200);
moveBackward();
delay(800);
stopMotors();
delay(300);
// Quick scan to decide turn direction
servo.write(20);
delay(300);
long leftQuick = getDistance();
servo.write(160);
delay(300);
long rightQuick = getDistance();
servo.write(90);
delay(300);
// Turn based on which side is more open
if (leftQuick > rightQuick) {
Serial.println("Turning left after backup");
turnLeft();
delay(1300);
} else {
Serial.println("Turning right after backup");
turnRight();
delay(1300);
}
stopMotors();
delay(200);
return;
}
// If path is clear (>50cm), move forward
if (frontDistance > 50) {
Serial.println("Path clear - Moving forward");
moveForward();
delay(200);
return;
}
// Obstacle detected - stop and analyze
Serial.println("Obstacle detected!");
stopMotors();
delay(300);
// Scan surroundings
ScanResult scan = scanArea();
// Check if any direction has >50cm clearance
if (scan.leftDist > 50) {
Serial.println("Turning left to clear path");
turnLeft();
delay(1600);
stopMotors();
delay(200);
}
else if (scan.rightDist > 50) {
Serial.println("Turning right to clear path");
turnRight();
delay(1600);
stopMotors();
delay(200);
}
else if (scan.centerDist > 50) {
// Center cleared up, move forward
moveForward();
delay(200);
}
else {
// All directions blocked or <50cm - back up
Serial.println("All paths blocked - Backing up");
moveBackward();
delay(1000);
stopMotors();
delay(300);
// After backing up, check again for >40cm clearance
frontDistance = getDistance();
if (frontDistance > 40) {
// Now we have some space, scan again
Serial.println("Space gained - Rescanning");
scan = scanArea();
// Choose best direction
if (scan.leftDist > scan.rightDist && scan.leftDist > 40) {
Serial.println("Turning left after backup");
turnLeft();
delay(1600);
} else if (scan.rightDist > 40) {
Serial.println("Turning right after backup");
turnRight();
delay(1600);
} else {
// Still blocked, turn around completely
Serial.println("Turning around");
turnRight();
delay(2600); // 180 degree turn (1300 * 2)
}
stopMotors();
delay(200);
} else {
// Still not enough space, back up more
moveBackward();
delay(800);
stopMotors();
delay(200);
}
}
}
void loop() {
// Run automatic mode if enabled
if (automaticModeEnabled) {
automaticMode();
}
// Check for Bluetooth commands
if (Serial.available()) {
char command = Serial.read();
if (!automaticModeEnabled) {
// Manual control commands
switch(command) {
case 'F': // Forward
moveForward();
break;
case 'B': // Backward
moveBackward();
break;
case 'L': // Left
turnLeft();
delay(TURN_DURATION);
stopMotors();
break;
case 'R': // Right
turnRight();
delay(TURN_DURATION);
stopMotors();
break;
case 'S': // Stop
stopMotors();
break;
}
}
// Mode switching commands (work in both modes)
if (command == 'A') {
automaticModeEnabled = true;
Serial.println("Automatic Mode ON");
} else if (command == 'M') {
automaticModeEnabled = false;
stopMotors();
Serial.println("Manual Mode ON");
}
}
delay(50);
}This complete code turns your build into a fully functional Bluetooth controlled object following robot.
Final Thoughts
When you complete this build, you gain full knowledge of motors, sensors, distance logic, servo scanning, Bluetooth communication, and dual-mode robotics. Your final Bluetooth controlled object following robot becomes a strong portfolio project and an impressive demonstration of practical robotics.