How to Build a Bluetooth-Controlled Robot Using Arduino & ATmega8

When I built my first mobile robot, it was tethered to my laptop with a bundle of wires. Every time it turned, the cables would snag, and the robot would stall. It felt like walking a dog on a very short, very fragile leash.

I knew there had to be a better way. That’s when I discovered Bluetooth.

In this guide, I will walk you through how to build a Bluetooth-controlled robot using an ATmega8 microcontroller (via an Arduino board), a dual DC motor gearbox, and a Bluetooth serial module. It’s a fantastic weekend project for beginners and a great way to understand robotics.

How to build a Bluetooth controlled robot
How to build a Bluetooth-controlled robot using Arduino and ATmega8.

The Problem with Wired Robots

In traditional robotics education, we often use RS-232 cables to connect the robot to a PC. While this works, it has major flaws:

  • Limited Mobility: The robot can only move as far as the cable allows.
  • Damage Risk: Cables break easily due to repeated bending.
  • Signal Interference: Long cables can pick up electrical noise.

By switching to Bluetooth (operating in the 2.4 GHz unlicensed ISM band), we can send serial data wirelessly. The robot can roam freely, and signals can even pass through obstacles (to a certain extent).

Hardware Requirements

To build this project, you will need the following components:

  • Microcontroller: ATmega8 (I used an Arduino board with this chip, but modern Arduino Uno boards work even better).
  • Bluetooth Module: HC-05 or HC-06 (Bluetooth Shield V2.2).
  • Motor Driver: L293D (1 Amp dual H-bridge).
  • Motors: Twin Gearbox DC motors (like the Tamiya dual gearbox).
  • Chassis: Acrylic body (for a professional look).
  • Power: 4x AA batteries or a Li-Po pack.

Step 1: Wiring the Electronics

Getting the wiring right is crucial. Here’s how I connected my components:

1. The Motor Driver (L293D)

The L293D acts as the bridge between your low-power microcontroller and high-power motors. Connect it as follows:

  • Pin M1-B (Motor 1): Connect to Arduino Digital Pin 8.
  • Pin M1-A (Motor 1): Connect to Arduino Digital Pin 9.
  • Pin M2-B (Motor 2): Connect to Arduino Digital Pin 10.
  • Pin M2-A (Motor 2): Connect to Arduino Digital Pin 11.
  • Enable Pins: Connect Enable1 to Pin 12 and Enable2 to Pin 13 (or tie them directly to VCC).

2. The Bluetooth Module

Connect the Bluetooth module (HC-05/06) to the Arduino:

  • TX (Transmit) on Bluetooth goes to RX (Receive) on Arduino.
  • RX (Receive) on Bluetooth goes to TX (Transmit) on Arduino.
  • VCC and GND to the appropriate power rails (usually 5V).

Step 2: Programming the Microcontroller

I used CodeVisionAVR (a C compiler for AVR) for this project, but if you are using the Arduino IDE, the logic remains exactly the same.

Here is the exact code I used to make the robot respond to commands typed on a keyboard:

// Declare motor pins
int motor1Pin1 = 8;
int motor1Pin2 = 9;
int enable1Pin = 12;
int motor2Pin1 = 10;
int motor2Pin2 = 11;
int enable2Pin = 13;

char val; // Variable to store serial data

void setup() {
  Serial.begin(38400); // Set baud rate to match Bluetooth module
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enable2Pin, OUTPUT);
  
  // Enable motors
  digitalWrite(enable1Pin, HIGH);
  digitalWrite(enable2Pin, HIGH);
}

void loop() {
  if (Serial.available()) {
    val = Serial.read(); // Read the incoming command
  }

  // Move Forward (W)
  if (val == 'w') {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  }
  // Move Backward (Z)
  else if (val == 'z') {
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  }
  // Turn Left (A)
  else if (val == 'a') {
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  }
  // Turn Right (D)
  else if (val == 'd') {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  }
  // Stop (S)
  else if (val == 's') {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }
}

Step 3: Connecting to a PC and Testing

To control the robot from your PC, you can use terminal emulator software like Tera Term or Putty.

  1. Pair your PC’s Bluetooth with the Bluetooth module on the robot (default password is usually 1234 or 0000).
  2. Open Tera Term and select the COM port assigned to the Bluetooth connection.
  3. Set the baud rate to 38400.
  4. Type the commands (W, A, S, D, Z) on your keyboard and watch the robot move!

Test Results & Performance

In my testing with a standard 1-meter track, the robot achieved an average speed of 0.154 meters per second. A full 360-degree turn took an average of 2.48 seconds.

If your robot moves erratically or doesn’t move at all, check your wiring, especially the TX/RX connections, and ensure your batteries have enough voltage.

What I Would Do Differently

While this project was a success, looking back, I would make three upgrades:

  • Add a Distance Sensor: An ultrasonic sensor (HC-SR04) would stop the robot from crashing into walls.
  • Upgrade the Microcontroller: The ATmega8 is great, but the ESP32 or ESP8266 are much better today because they have built-in Wi-Fi and Bluetooth.
  • Use a Better App: Instead of typing on a PC, I would build a simple mobile app using MIT App Inventor for smartphone control.

If you are looking to build a tech business around this kind of hardware, you might want to read our guide on the best project management software for remote teams to manage your development process.

Final Thoughts

Learning how to build a Bluetooth-controlled robot is a rite of passage for any hardware enthusiast. It bridges the gap between software code and physical movement. Once you get it working, the feeling is incredibly rewarding.

Have you built your own robot? What challenges did you face? Let me know in the comments below!

Tinggalkan Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Scroll to Top