Skip to main content

80. Interfacing the HC-06 Bluetooth module with Arduino

 Hello everyone

Today I am going to give you a tutorial about interfacing the HC-06 Bluetooth module with Arduino. In this tutorial, you will be learning about the module - the basic introduction. You will also learn how to set up the module, connect and interface it.

HC-06 Bluetooth module

HC-06 is a Bluetooth module designed for establishing short range wireless data communication (<100 meters). It is very easy to interface and communicate. It can be interfaced with almost all microcontrollers or processors as it uses UART interface. 
This module has the ability to transmit files at speed up to 2.1Mbps and works on Bluetooth 2.0 communication protocol. Unlike the HC-05 Bluetooth module, this module can only act as a slave device.
  • Operating Voltage: 3.3V - 6V
  • Operating Frequency range: 2.402 GHz - 2.480 GHz

Pinout

You will only be needing the four pins in the HC-06 Bluetooth module.
  • RXD: Serial Data Receive Pin. Used for serial input. 3.3V logic
  • TXD: Serial Data Transmit Pin. Used for serial output. 3.3V logic
  • GND: Ground
  • VCC: +5V

Setting up the HC-06 Bluetooth module

To set up your HC-06 Bluetooth module, you will be needing the USB-TTL Serial Converter module. Connect your USB-TTL Serial converter module with your Bluetooth module. The connections are as follows:
  • RXD ---> TX
  • TXD ---> RX
  • GND ---> GND
  • VCC ---> 5V
Now, plug in the USB-TTL Serial converter module to your Laptop/ PC. The LED on the converter module should light up if it's working properly. The HC-06 Bluetooth module is permanently configured to be slave and is always in AT mode when not paired to any other device.
Open Arduino IDE and go to Tools, then Serial Monitor. 
Set the Baud rate to 9600 and the 'line ending' to 'Both NL and CR'.
Type in 'AT' without the quotes and click send. If the Serial Monitor displays "OK", the module is in AT mode and you are good to go.
Use these AT commands for the corresponding functions:
  • AT : Check the connection
  • AT+NAME: To check the default name of the module
  • AT+VERSION: To obtain the version
  • AT+BAUD: To check the default baud rate of the Bluetooth module
  • AT+PIN: To obtain the password of the module
  • AT+NAME'DESIRED NAME': Changes the default name of the module to the DESIRED NAME
To change the baud rate of the HC-06 Bluetooth module, type in AT+BAUDx, where x has range from 1 - 9, inclusive. 
  • 1: 1200 baud
  • 2: 2400 baud
  • 3: 4800 baud
  • 4: 9600 baud (default)
  • 5: 19200 baud
  • 6: 38400 baud
  • 7: 57600 baud
  • 8: 115200 baud
Sending AT+BAUD3 will change the baud rate from 9600 baud to 4800 baud.

Connecting the HC-06 Bluetooth module with Arduino development board

Hardware components

  • Arduino Nano - You could use any other development board if you wish
  • HC-06 Bluetooth module
  • Resistors - 1kΩ and 2kΩ ( I didn't have a 2kΩ resistor with me so I used 2 1kΩ resistors instead)
  • Male-to-Male Jumper wires
  • Male-to-Female Jumper wires

Software

  • Arduino IDE
Refer to the schematic to see how the Bluetooth module should be connected with the Arduino development Board.
The Arduino boards have a serial port at D0 and D1 and it communicates with these pins as well as the computer via USB. We are using the Serial functions so we cannot use these pins. Therefore, we will be using the D2 and D3 pins for communication with the HC-06 Bluetooth module. D2 pin will be connected to TXD pin of the HC-06 module whereas the D3 pin will be connected to the RXD pin.
The module is connected to +5V standard regulated power supply and the voltage divider is used for converting the 5V logic signal sent by Arduino D3 pin to 3.3V logic signals which is suitable for the module. If you do not understand the voltage divider principle, please refer to the YouTube video in the last section of this post.
If separate power sources are used for the Bluetooth module and Arduino development board, their ground must be connected for voltage reference.

Code

For this project, you will be needing the Software Serial library. This is an in-built library and does not need to be installed. The library has been developed to allow serial communication on other digital pins of the Arduino and this is why we require the library to be used for this project as we want to enable D2 and D3 pins for Serial communication.
I obtained the codes from this website: http://www.martyncurrey.com/arduino-and-hc-06-zs-040/
Compile and upload the sketch to your Arduino development board. 

Testing the Bluetooth Communication

Now that you have successfully set up the Bluetooth module, let's test the communication between this module and another device. If you have an Android device, such as phone or tablet, go to PlayStore and install 'Bluetooth Terminal' app from Qwerty.
Make sure you have turned on Bluetooth on your device.
Open the menu icon on the top right corner of the screen and tap on 'Connect a device - secure'. As we have not paired the Bluetooth module with the device, tap on 'Scan for devices'. You will see the Name of your Bluetooth module. To pair with your module, the device will ask for the password. After you provide the correct password, you will see that the device and the module are connected. The LED on the Bluetooth module will flash every 2 seconds. 
Open the Serial monitor in the Arduino IDE and set the correct baud rate. Send a message from the Bluetooth terminal app and you will see the message displayed on the Serial monitor. Try sending a message from the Serial monitor. If the connection is successful, the message will be received by your Android device.

Summary video

If you have any questions or suggestions, please feel free to comment below.

Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu