Arduino Bluetooth Interface : HC-05 FC-114

The HC-05 and HC-06 bluetooth modules are the most popular modules used by electronic students and tinkerers due it low cost. You can pick one off eBay for as low as £2.50. We have never actually used one of them before and had only used the expensive xBee. We decided to pick a couple of these from a random Chinese supplier on eBay. This post explains how to interface bluetooth with an Arduino.

This post consist of two parts:

1. Configuring the HC-05
2. Controlling an Arduino with an Android phone using the HC-05

Configuring the HC-05

The default settings for the HC-05 are fine for most things but it is desirable to change them for optimum performance. For instance, the default baud rate for the HC-05 is 9600 and the module can go as high as 1382400 baud rate. Default settings such as the device name can be changed from ‘HC-05’ to something else, specially when two or more HC-05 are used in the same area. The pin code should also be changed from the default 1234 to increase security.

To configure the HC-05, the module is switched from transmission mode to configuration mode and AT commands are used to change the settings. We are only dealing with HC-05 that comes with the breakout board as shown in figure 1 below.

HC-05 FC-114
Figure 1: HC-05 FC-114

Parts

  • HC-05 module (with breakout board)
  • Arduino Micro
  • Wires+connectors
  • 2 resistors (1k and 2k)
  • Arduino IDE

The wiring to Arduino for AT configuration mode is shown in figure 2.

HC-05 Connections
Figure 2: HC-05 Connections

To get the HC-05 FC-114 into the AT configuration mode, follow these instructions:

  • Do the connections according to Figure 2; the 1k resistor is connected between the blue and orange wire
  • Plug the Arduino USB to power it
  • Disconnect the Vcc red wire from the Arduino 5V pin to power down the HC-05
  • Press the micro switch on the HC-05 just above the EN pin
  • Reconnect the Vcc red wire while still holding down the micro switch for a further few seconds and then release it
  • The LED on the HC-05 will start to flash on and off every 2 seconds, suggesting that it is now in AT mode

Arduino Code

Upload the following code to the Arduino. Look at for the Serial baud rate settings, they might vary for different HC-05 modules.

/*
AUTHOR: BehindTheSciences.com
*/

#include <SoftwareSerial.h>

SoftwareSerial BTS(10, 11); // RX | TX

void setup()
{
  Serial.begin(9600);
  Serial.print("Enter AT commands:");
  BTS.begin(38400);  // HC-05 FC-114 default speed in AT command more
}

void loop()
{

  // Read from HC-05 and send it to Arduino Serial Monitor
  if (BTS.available())
  {
    Serial.write(BTS.read());
  }

  // Read from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTS.write(Serial.read());
}


Once uploaded, open the Serial Monitor in the Arduino IDE and select a baudrate of 9600. Also select “Both NL & CR” for the line ending setting.

You can now send AT commands to the HC-05 FC-114 in the Serial Monitor.

Start by sending the “AT” (without quotes).

You can get “OK” in reply. If you don’t, check your wiring and/or code.

Serial Monitor AT Command
Arduino Serial Monitor: AT Command

IMPORTANT: Some commands might not work and here is how to deal with that issue
For example, the AT+NAME? command did not work and to get a reply for this command, simply hold your micro switch down while pressing ENTER/Send in your terminal/Arduino Serial Monitor.

The AT commands to configure your HC-05 module can be found in this PDF:
HC-05 AT Commands

You can change various settings of the HC-05 such as the PIN, baudrate and name, among others.

Let’s move on to controlling the Arduino from an Android phone, comment down the post if you have any questions on the configuration process.

Controlling an Arduino from an Android phone

To get the HC-05 back to transmission mode, simply disconnect the Vcc power wire of the module. We connected 3 LEDs to pin D3, D4 and D5 of the Arduino and uploaded the following code:


/*Author: BehindTheSciences.com */
#include <SoftwareSerial.h>// import the serial library

SoftwareSerial ser(10, 11); // RX, TX
int Bluetooth; // the data given from Android Phone

void setup() {
  // Run Once Setup code
  ser.begin(9600);
  Serial.begin(9600);
  pinMode(3,OUTPUT); //White LED
  pinMode(4,OUTPUT); //Blue LED
  pinMode(5,OUTPUT); //Red LED
  
}

void loop() {
  // put your main code here, to run repeatedly:
   if (ser.available()){
Bluetooth=ser.read();
Serial.println(Bluetooth);
   if(Bluetooth=='r'){   // if r is sent to HC-05
   digitalWrite(3,0);
   digitalWrite(4,0);
   digitalWrite(5,1);
   
   }
  if (Bluetooth=='b'){// if number blue pressed ....
  digitalWrite(3,0);
   digitalWrite(4,1);
   digitalWrite(5,0);
  }
  if (Bluetooth=='w'){// if number white pressed ....
  digitalWrite(3,1);
   digitalWrite(4,0);
   digitalWrite(5,0);
  }
  if (Bluetooth=='a'){// if all pressed ....
   digitalWrite(3,1);
   digitalWrite(4,1);
   digitalWrite(5,1);
  }
  if (Bluetooth=='o'){// All Off
  digitalWrite(3,0);
   digitalWrite(4,0);
   digitalWrite(5,0);
  }
}
delay(100);// Wait for 100 ms
}

We then downloaded “Arduino Bluetooth App” and installed from the Play store.

Arduino Bluetooth App
Arduino Bluetooth App

On the App, click on the “Select BT” button and the HC-05 (Make sure that bluetooth is enabled on your phone and paired with the HC-05)
Once connected, you are ready to talk to the HC-05!

Watch the demo:

Happy tinkering. Contact us at contact@behindthesciences.com if you have comments or question about this post.

Add a Comment

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

Show Buttons
Hide Buttons