Electronics Champ
Published © GPL3+

Bluetooth Controlled Car Using HC-05 Bluetooth Module

Control an Arduino car using an Android App installed on your mobile phone using Bluetooth

IntermediateFull instructions provided2 hours2,332
Bluetooth Controlled Car Using HC-05 Bluetooth Module

Things used in this project

Story

Read more

Schematics

Schematic

Schematic for HC-05 Bluetooth Module. This was designed using Tinkercad

Code

Code

Arduino
Upload this code to your Arduino board
uint8_t rightMotorForward = 5;
uint8_t rightMotorBackward = 6;
uint8_t leftMotorForward = 10;
uint8_t leftMotorBackward = 11;
uint8_t data = 0;
uint8_t prevData = data;

void setup() {

  for (int i = 9; i < 13; i = i + 1) {
    pinMode(i, OUTPUT);
  }

  Serial.begin(9600);

}

void loop() {

  if (Serial.available()) {
    
    data = Serial.read();
    Serial.println(data);
    
  }

  if (prevData != data) {

    switch (data) {

      case 0:
        stop();
        break;
      
      case 1:
        front();
        break;

      case 2:
        back();
        break;

      case 3:
        left();
        break;

      case 4:
        right();
        break;

    }

    prevData = data;
    
  }

}

//function to move the car forward
void front() {

  analogWrite(leftMotorForward, 128);
  analogWrite(rightMotorForward, 128);
  analogWrite(leftMotorBackward, 0);
  analogWrite(rightMotorBackward, 0);
  Serial.println("Front");

}

//function to move the car backward
void back() {

  analogWrite(leftMotorForward, 0);
  analogWrite(rightMotorForward, 0);
  analogWrite(leftMotorBackward, 128);
  analogWrite(rightMotorBackward, 128);
  Serial.println("Back");

}

//function to turn the car left
void left() {

  analogWrite(leftMotorForward, 0);
  analogWrite(rightMotorForward, 128);
  analogWrite(leftMotorBackward, 128);
  analogWrite(rightMotorBackward, 0);
  Serial.println("Left");

}

//function to turn the car right
void right() {

  analogWrite(leftMotorForward, 128);
  analogWrite(rightMotorForward, 0);
  analogWrite(leftMotorBackward, 0);
  analogWrite(rightMotorBackward, 128);
  Serial.println("Right");

}

//function to stop the car
void stop() {

  digitalWrite(leftMotorForward, LOW);
  digitalWrite(rightMotorForward, LOW);
  digitalWrite(leftMotorBackward, LOW);
  digitalWrite(rightMotorBackward, LOW);
  Serial.println("Stop");

}

Credits

Electronics Champ
4 projects • 11 followers
Projects based on breadboard electronics and Arduino with clear step-by-step instructions, circuit diagrams, schematics, and source code.

Comments