How to Use The HC-05 Bluetooth Module

The HC-05 Bluetooth Module Specifications

HC-05 Serial Bluetooth Module_2-1000x750
  1. STATE : Is used to check if the bluetooth module is connected or not.
  2. RX : Is for Receiving the data.
  3. TX : Is for Transmitting the data.
  4. GND and Vcc to power the module from 3.6v to 6v.
  5. EN : Allows us to toggling between the AT Command Mode and Data Mode.

How To Change The Name And The Password Of The HC-05 Bluetooth Module

Data Mode

Data Mode is the normal mode in which the HC-05 Bluetooth Module sends and receives serial data. Later on, we will be using the Bluetooth of a smartphone and the HC-05 Bluetooth Module to make the Arduino communicate with an android application.

AT Command Mode

AT Command Mode is the mode where we can change the default settings of the HC-05 Bluetooth Module like the name and the password.
To enter the AT Command mode, Firstly you need to upload an empty sketch to your Arduino board. Secondly, Make the connections between the Bluetooth module and the Arduino as it is shown in the schematic below. After that, Plug in your Arduino to your computer and now you should see a diode on the Bluetooth module blinking every 2 seconds which means you are now on the AT Command Mode.

Once you entered the AT Command Mode open Arduino IDE then open the serial monitor and change the baud rate to 38400bps. The default baud speed of the HC-05 Bluetooth Module in the AT Command Mode is 38400bps.

  • To know the current name of the HC-05 Bluetooth Module type in the top bar
    AT+NAME? and press enter (You will get the default name of the Bluetooth module followed by an “OK” message).
  • To change the name type
    AT+NAME= and type the name that you like and press enter (You will get an “OK” message confirming that your name has been changed). To check back if the name was changed or not, type agin AT+NAME? and press enter.
  • To know the current password type
    AT+PSWD?
  • To change the password type
    AT+PSWD=” and type your desired password between two quotations marks .
Serial-Monitor-HC-05-Bluetooth-Module

HC-05 AT Command Set

AT+NAME to know the name of the Bluetooth module.
AT+PSWD to know the password of the Bluetooth module.
AT+UART to know the baud speed of the Bluetooth Module in the Data Mode.
AT+ROLE to know the role of the Bluetooth module whether it is master or slave(master = 1, slave = 0).
AT+CMOD to know how many devices your Bluetooth module can pair with (connected to only one device = 0, connected to many devices = 1).
AT+ADDR to know the address of the Bluetooth module.
AT+RESET to rest the Bluetooth module
AT+ORGL to restore default settings of Bluetooth module

Control A Car Using A Smartphone

To control a Robot Car using a smartphone, we will be using an android application called Arduino-Bluetooth-RC-Car.

This application has a control panel that allows us to move the car forward and backward, left and right, control the speed, turn ON and OFF the lights, the horn, and the emergency triangle of the car. So all of that is done by sending a special character according to each button pressed, This character will be captured by the Bluetooth module and used by the Arduino to control the Robot car.

Schematic

Sketch

int ENA=11;
int IN1=10;
int IN2=9;
int IN3=8;
int IN4=7;
int ENB=6;
int F=5;
int B=4;
int F2=3;
int B2=2;
char x;
int SPEED=0;
void setup() {
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(F2, OUTPUT);
  pinMode(B2, OUTPUT);
  Serial.begin(9600);
}
void backward()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}
void forward()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}
void right()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}
void left()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}
void loop() {
if(Serial.available()>0){
    x=Serial.read();
    Serial.println(x); 
  }
  if (x=='0')
  {
    SPEED=0;
  } else if (x=='1')
  {
    SPEED=10;
  } else if (x=='2')
  {
    SPEED=25;
  } else if (x=='3')
  {
    SPEED=50;
  } else if (x=='4')
  {
    SPEED=75;
  } else if (x=='5')
  {
    SPEED=100;
  } else if (x=='6')
  {
    SPEED=125;
  } else if (x=='7')
  {
    SPEED=150;
  } else if (x=='8')
  {
    SPEED=175;
  } else if (x=='9')
  {
    SPEED=200;
  } else if (x=='q')
  {
    SPEED=230;
  } else if (x=='D')
  {
    SPEED=255;
  }
  if (x=='S')
  { 
    digitalWrite(B, LOW);
    digitalWrite(B2, LOW);   
    analogWrite(ENA, 0);
    analogWrite(ENB, 0);
    forward();
  }
  if (x=='F')
  {
    analogWrite(ENA, SPEED);
    analogWrite(ENB, SPEED);
    forward();
  }
    if (x=='B')
  {
    digitalWrite(B, HIGH);
    digitalWrite(B2, HIGH);     
    analogWrite(ENA, SPEED);
    analogWrite(ENB, SPEED);
    backward();
  }
    if (x=='R')
  {
    analogWrite(ENA, SPEED);
    analogWrite(ENB, SPEED);
    right();
  }
  if (x=='L')
  {
    analogWrite(ENA, SPEED);
    analogWrite(ENB, SPEED);
    left();
  }
  if (x=='W')
  {
    digitalWrite(F, HIGH);
    digitalWrite(F2, HIGH); 
  }
  if (x=='w')
  {
    digitalWrite(F, LOW);
    digitalWrite(F2, LOW); 
  }
  if (x=='U')
  {
    digitalWrite(B, HIGH);
    digitalWrite(B2, HIGH); 
  }
  if (x=='u')
  {
    digitalWrite(B, LOW);
    digitalWrite(B2, LOW); 
  }
}						

I hope you learned something, If you have any questions feel free to write them in the comments section down below.

FAQ

You can connect the EN pin of the HC-05 Bluetooth Module with the 3.3v of the Arduino to enter the AT Command mode OR you can just click and hold the Button on board of the Module while plugging in the Arduino to your computer.
You will see a diode on the module blinking every 2 seconds which means you are successfully entered the AT Command Mode.

  1. Check out the baud rate, it should be at 38400 bps.
  2. If you could not enter the AT Command Mode then you should connect the RX pin of the Bluetooth Module to the RX pin of the Arduino through a voltage divider like it shown in the schematic down below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top