Illustration: on a terrace, a phone with arrow buttons in hand, and a robot car with an HC-05 Bluetooth module nearby.Robotics
Illustration (made with AI): roughly what the finished project looks like.

A Phone-Controlled Car (Bluetooth)

An HC-05 Bluetooth module links the car to your phone. Drive it forward and back and turn it left and right with the buttons of an Android app, and change its speed too.

Difficulty
Intermediate
Time
1 h 30 min
Age
12+
Parts
8, 8 on the site

Written by the RoboHub team. A question? Write to us.

Variations

Choose a variation and the parts list updates.

Instructions

  1. Build the car

    Wire the chassis, motors, L298N and power the same way as in “A Car That Avoids Obstacles”: ENA 5, IN1 7, IN2 8, ENB 6, IN3 4, IN4 2.

    RX and TX by board: 10 and 11 on the Uno R3, 0 and 1 on the Uno R4, 19 and 18 on the Mega (RX1, TX1). D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • L298N driver OUT1 → Left motor 1
    • L298N driver OUT2 → Left motor 2
    • L298N driver OUT3 → Right motor 1
    • L298N driver OUT4 → Right motor 2
    • L298N driver ENA → Arduino D5
    • L298N driver IN1 → Arduino D7
    • L298N driver IN2 → Arduino D8
    • L298N driver ENB → Arduino D6
    • L298N driver IN3 → Arduino D4
    • L298N driver IN4 → Arduino D2
    • L298N driver 12V → Holder, 2 × 18650 +
    • Holder, 2 × 18650 + → Arduino VIN
    • L298N driver GND → Holder, 2 × 18650 −
    • Holder, 2 × 18650 − → Arduino GND
  2. Bluetooth module

    Connect the HC-05's VCC to 5V and GND to ground. The module's TX goes to the board's RX, and the module's RX to the board's TX through a voltage divider: a 1 kΩ resistor from the board's pin to the HC-05's RX, and a 2 kΩ from there to ground. That way the module gets about 3.3 V instead of 5 V.

    RX and TX by board: 10 and 11 on the Uno R3, 0 and 1 on the Uno R4, 19 and 18 on the Mega (RX1, TX1). D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • HC-05 Bluetooth VCC → Arduino 5V
    • HC-05 Bluetooth GND → Arduino GND
    • HC-05 Bluetooth TX → Arduino RX
    • 1 kΩ resistor 1 → Arduino TX
    • HC-05 Bluetooth RX → 1 kΩ resistor 2
    • HC-05 Bluetooth RX → 2 kΩ resistor 1
    • 2 kΩ resistor 2 → Arduino GND
  3. Which pins

    On the Uno R3 the board's RX is pin 10 and TX pin 11; on the Uno R4 RX is pin 0 and TX pin 1; on the Mega RX1 is pin 19 and TX1 pin 18. The code recognises the board by itself. The HC-05 sends a 3.3 V signal: enough for the Uno R3 and the Mega, but the Uno R4 may not read it. If no commands arrive on the R4, put a logic level shifter between the HC-05's TX and pin 0. No 2 kΩ resistor in your kit? Use two 1 kΩ in series.

  4. Upload the code

    Commands are single letters: F forward, B back, L left, R right, S stop, and the digits 0 to 9 set the speed.

    Arduino C++
    // A car driven from an Android app through an HC-05 Bluetooth module.
    #if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_AVR_MEGA2560)
      #define BT Serial1                   // a spare hardware port: pins 0/1 on the R4, 19/18 on the Mega
    #else
      #include <SoftwareSerial.h>
      SoftwareSerial BT(10, 11);           // Uno R3: RX = 10, TX = 11
    #endif
    
    // L298N: take the jumpers off ENA and ENB and wire them to PWM pins
    const int ENA = 5, IN1 = 7, IN2 = 8;   // left motor
    const int ENB = 6, IN3 = 4, IN4 = 2;   // right motor
    int speed = 200;                       // 0-255
    
    void drive(int left, int right) {      // -255..255 for each side
      digitalWrite(IN1, left > 0 ? HIGH : LOW);
      digitalWrite(IN2, left < 0 ? HIGH : LOW);
      digitalWrite(IN3, right > 0 ? HIGH : LOW);
      digitalWrite(IN4, right < 0 ? HIGH : LOW);
      analogWrite(ENA, abs(left));
      analogWrite(ENB, abs(right));
    }
    
    void setup() {
      int pins[] = {ENA, IN1, IN2, ENB, IN3, IN4};
      for (int pin : pins) pinMode(pin, OUTPUT);
      BT.begin(9600);                      // the HC-05's factory speed
    }
    
    void loop() {
      if (!BT.available()) return;
      char c = BT.read();
      int slow = speed / 3;
      switch (c) {
        case 'F': drive(speed, speed); break;      // forward
        case 'B': drive(-speed, -speed); break;    // back
        case 'L': drive(-speed, speed); break;     // spin left
        case 'R': drive(speed, -speed); break;     // spin right
        case 'G': drive(slow, speed); break;       // forward left
        case 'I': drive(speed, slow); break;       // forward right
        case 'H': drive(-slow, -speed); break;     // back left
        case 'J': drive(-speed, -slow); break;     // back right
        case 'S': drive(0, 0); break;              // stop
        case 'q': speed = 255; break;              // full speed
        default:
          if (c >= '0' && c <= '9') speed = 100 + (c - '0') * 15;   // 100..235
      }
    }
  5. Pair your phone

    Turn on Bluetooth in Android's settings and add HC-05; the PIN is 1234 or 0000. Install a Bluetooth car control app from Google Play, for example “Arduino Bluetooth RC Car”, and choose HC-05 in it. An iPhone can't see the HC-05: it needs a BLE module (HM-10).

    Illustration: a robot car with an HC-05 Bluetooth module, beside a phone with control buttons.

    Illustration, made with AI

  • Robotics
    Intermediate2 h12+

    A Car That Avoids Obstacles

    A two-motor robot car drives forward, spots a wall from afar with its ultrasonic “eye”, stops, looks left and right and turns where the way is clear.

    8/8 parts on the site
  • Robotics
    Intermediate1 h 30 min12+

    A Line-Following Car

    Two infrared sensors see a black line on the floor and the car follows it on its own, round the bends too. On a wide black strip it stops, as if at a finish line.

    7/7 parts on the site
  • NewRobotics
    Advanced4 h12+

    A PID Line Follower Robot

    Five infrared sensors measure how far the robot has drifted off the line, and a PID controller corrects the motors smoothly and fast. Built for competitions: the track, the sensor bar, the code and how to tune it.

    8/8 parts on the site