Skip to content

Latest commit

 

History

History
176 lines (141 loc) · 7.73 KB

File metadata and controls

176 lines (141 loc) · 7.73 KB

🚗 Arduino Bluetooth Tank – A Fun DIY Project

Control a toy tank from any Android phone via Bluetooth. Built with Arduino, an HC‑05 module, and a DRV8833 motor driver. Perfect for beginners who want to learn about wireless communication, motor control, and embedded programming.


📖 Table of Contents

  1. Overview
  2. Features
  3. Hardware Requirements
  4. Software Requirements
  5. Wiring Diagram
  6. Installation & Build
  7. Usage
  8. How It Works
  9. Troubleshooting
  10. License
  11. Credits

Overview

This project turns a simple 2‑motor tracked chassis into a Bluetooth‑controlled tank.
Send commands from a joystick‑style Android app and watch the tank move forward, backward, left, or right.
The firmware uses PWM for smooth speed control and flashes the built‑in LED to indicate activity.

Features

  • ✅ Bluetooth serial communication (HC‑05)
  • ✅ Proportional speed control via PWM (DRV8833)
  • ✅ Simple command set: 1 = forward, 2 = left, 3 = right, 4 = backward
  • ✅ LED feedback on pin 13
  • ✅ PlatformIO ready (also works with the Arduino IDE)
  • ✅ Uses the lightweight advancedSerial library for debug prints

Hardware Requirements

Part Quantity Notes
Arduino Uno / Nano / Any 5V Arduino-compatible board 1 5V logic required
HC‑05 Bluetooth module 1 Pre‑configured to 9600 baud (default)
DRV8833 dual motor driver carrier 1 Alternatively use L298N (see Branches below)
Two DC gear motors (with suitable wheels/tracks) 2 6‑12 V, current < 1 A per motor
External battery pack (6‑12 V) 1 Powers the motors; Arduino can be powered via USB or VIN
Breadboard & jumper wires – For prototyping
Optional: 10 µF electrolytic capacitor across motor supply 1 Helps suppress voltage spikes

You can find many “Bluetooth Arduino Tank Control” apps on the Play Store – see the Android Application section.


Software Requirements

  • PlatformIO Core (CLI) or VS Code with PlatformIO extension
    or the classic Arduino IDE (≥1.8.0)
  • advancedSerial library (included as a Git submodule)
  • Optional: a serial monitor (e.g., PlatformIO’s built‑in monitor, Arduino Serial Monitor, or a Bluetooth serial terminal app)

Wiring Diagram

Arduino   HC-05        DRV8833         Motors
------   -----        --------        ------
5V  --------> VCC          VCC   --------> Motor A VCC
GND  --------> GND          GND   --------> Motor A GND
D2 (RX) <------ TX
D1 (TX) ------> RX
D4 --------> IN1 (Motor A1)
D5 --------> IN2 (Motor A2)
D6 --------> IN3 (Motor B1)
D9 --------> IN4 (Motor B2)
  • Connect Motor A to OUT1/OUT2 of the DRV8833, Motor B to OUT3/OUT4.
  • If your driver has separate ENABLE pins, tie them to VCC (they are internally tied on many breakout boards).
  • Power the motor supply (VM) from your external battery pack; keep the Arduino’s VIN or USB separate unless you have a common ground.

Wiring Example
(Add your own diagram or photo here.)


Installation & Build

1️⃣ Clone the repository (with submodule)

git clone --recurse-submodules https://github.com/yourname/ArduinoBluetoothTank.git
cd ArduinoBluetoothTank

If you already cloned without --recurse-submodules:

git submodule update --init --recursive

2️⃣ Build with PlatformIO

# Install PlatformIO if you don't have it
pip install -U platformio   # or follow https://docs.platformio.org/en/latest/core/install.html

# Compile the firmware
pio run

# Upload to your Arduino (make sure the correct port is selected in platformio.ini)
pio run --target upload

3️⃣ Using the Arduino IDE (alternative)

  1. Open ArduinoBlueToothTank/ArduinoBlueToothTank.ino.
  2. Sketch → Include Library → Add .ZIP Library… → select the lib/advancedSerial folder.
  3. Choose your board and port, then click Upload.

Usage

  1. Power the tank (connect the external battery to the motor driver, and power the Arduino via USB or VIN).
  2. Pair your phone with the HC‑05 (default PIN: 1234 or 0000).
  3. Launch a Bluetooth joystick app (e.g., Bluetooth Arduino Tank Control).
  4. Push the joystick:
    • Up → sends ASCII '1' → tank moves forward
    • Left → sends '2' → turns left
    • Right → sends '3' → turns right
    • Down → sends '4' → moves backward
    • Release or any other key → tank stops (see code).
  5. The onboard LED (pin 13) flashes while a command is being executed.

How It Works

The firmware is intentionally simple yet illustrative:

  1. Bluetooth Serial – We use SoftwareSerial on pins 2 (RX) and 1 (TX) to talk to the HC‑05 at 9600 baud.
  2. Command Parsing – Each received byte is stored in state. The ASCII characters '1'‑'4' trigger specific motor patterns. Any other byte resets state to 0 (stop).
  3. Motor Control – The DRV8833 expects PWM on its input pins to control speed. We use analogWrite(pin, motorSpeed) where motorSpeed is set to 150 (≈ 60 % duty). For turning, we drive one motor forward and the other backward (or vice‑versa).
  4. Safety Stop – After each movement command we call stop(), which briefly sets all inputs LOW and adds a delay(100) to prevent drifting.
  5. Debug Output – The advancedSerial library lets us print the received byte and action names to the Arduino Serial Monitor (helpful while developing).

Code Highlights

SoftwareSerial mySerial(2, 1); // RX, TX
// ...
if (mySerial.available() > 0) {
    state = mySerial.read();    // get command
    Serial.println(state);      // debug
    // act on state …
}

The advancedSerial instance aSerial is declared in the library and used for optional verbose logging (currently unused but ready).


Troubleshooting

Symptom Likely Cause Fix
No response from tank HC‑05 not paired or wrong baud Re‑pair phone; ensure HC‑05 is set to 9600 baud (AT+UART=9600,0,0)
Motors jitter or don’t turn Insufficient motor supply or common ground missing Use a adequate battery (≥ 6 V, ≥ 2 A) and connect Arduino GND to motor supply GND
LED never flashes Serial not receiving data Check wiring: TX of HC‑05 → Arduino RX (pin 2), RX ←→ TX (pin 1). Verify with Serial Monitor.
Compilation error: advancedSerial.h not found Submodule not initialized Run git submodule update --init --recursive
Upload fails Wrong port or board selected in platformio.ini Edit [env] section to match your Arduino model and port

License

This project is released under the MIT License – see the LICENSE file in the advancedSerial submodule for details. Feel free to fork, modify, and share!


Credits

  • advancedSerial library – https://github.com/klenov/advancedSerial
  • HC‑05 Bluetooth module – ubiquitous cheap BT serial bridge
  • DRV8833 motor driver – TI’s compact dual‑H‑bridge
  • Android App – “Bluetooth Arduino Tank Control” by Garylcyhk (Play Store)
  • You – for building and having fun!

Happy hacking! 🚀
If you make improvements, consider opening a pull request or sharing your build photos. Let’s keep the tank rolling!