How To Connect Bluetooth Module HC-06 With Arduino Uno

How To Connect Bluetooth Module HC-06 With Arduino Uno

How To Connect Bluetooth Module HC-06 With Arduino Uno

The Bluetooth module HC-06 allows the serial and UART communication between your Arduino Uno or any microcontroller with  a PC or a Smartphone equipped with a Bluetooth facility. Connecting the Bluetooth module HC-06 with Arduino Uno have numerous application like controlling home lights using Bluetooth module, driving a RC car, controlling robot using mobile application etc.

The HC-06 Bluetooth module contains four pins-

  • TXD – Serial output of the module used for the transmission of data
  • RXD- Serial output of the module for receiving the data,
  • VCC- It is in the range of 3.3-6V.
  • GND- Ground.

Specification Of Bluetooth Module HC-06

  • Bluetooth number: HC-06
  • Operating Voltage: 3.3 – 6 volts
  • Default baud rate: 9600 bps
  • Default pin: 1234
  • Signal Coverage: 30ft
  • Default Password: 1234

The Arduino pins 0 and 1 are specified for Universal Asynchronous Receiver/Transmitter (UART) that control the interface with its attached serial devices. Pin connection of Arduino Uno with Bluetooth Module HC-06

HC-06                         Arduino

TX                   –           RX (pin 0)

RX                   –           TX (pin 1)

VCC                –           3.3 volt supply from Arduino

GND               –           Arduino ground

Arduino Uno and HC-06 (Bluetooth Module) Connections

Arduino Uno and HC-06 (Bluetooth Module) Connections

Upload the Sketch in Arduino IDE

The Arduino IDE is the software environment used to create the programs, called “sketches,” that will be executed by the Arduino hardware. The below Arduino sketch will allow to communicate with the Bluetooth module with your Arduino Uno and read the string sent by smartphone. Although we’ve already discussed how to send strings from Mobile phone to Bluetooth module HC-06.

For the communication between the Arduino and the PC connected with a USB cable with serial connection you’ll need a library called “SoftwareSerial.h“. This library allows you to setup serial communication on (almost any) digital pin of the Arduino Uno.

#include<SoftwareSerial.h>
SoftwareSerial mySerial(4, 2); // RX, TX
String command = ""; // Stores response of the HC-06 Bluetooth device

void setup() {
// Open serial communications:
Serial.begin(9600);
Serial.println("Type AT commands!");

// The HC-06 defaults to 9600 according to the datasheet.
mySerial.begin(9600);
}

void loop() {
// Read device output if available.
if (mySerial.available()) {
while(mySerial.available()) { // While there is more to be read, keep reading.
command += (char)mySerial.read();
}

Serial.println(command);
command = ""; // No repeats
}

// Read user input if available.
if (Serial.available()){
delay(10); // The delay is necessary to get this working!
mySerial.write(Serial.read());
}
}

Configuring HC-06 Using AT Commands

  1. Test communication

Send: AT (please send it every second)

Back: OK

  1. Reset the Bluetooth serial baud rate

Send: AT+BAUD1

Back: OK1200

Send: AT+BAUD2

Back: OK2400

……

1———1200

2———2400

3———4800

4———9600 (default)

5———19200

6———38400

7———57600

8———115200

A———460800

B———921600

C———1382400

PC can’t support the baud rate lager than 115200. The solution is: make the MCU have higher baud rate (lager than 115200) through programming, and reset the baud rate to low level through the AT command.

The baud rate reset by the AT command can be kept for the next time even though the power is cut off.

  1. Reset the Bluetooth name

Send: AT+NAMEname

Back: OKname

  1. Change Bluetooth Module Pair Password/Pin

Sent : AT+PINxxxx

receive : OKsetpin

(xxxx is the pin code you set)

Pin code can be save even power down.

Example:

Send: AT+PIN1111

Back: OKsetpin

By this step password is changed to 1111, whereas the default is 1234.

This parameter can be kept even though the power is cut off.

Note: More AT Commands can be easily found in the datasheet.

If you still have any doubts feel free to ask. Suggestions are welcomed. Thank you for reading.