HC-05 Bluetooth Arduino Library

The HC-05 Bluetooth to Serial module is a low cost widely available (search ebay or Amazon) device for creating serial data connections. When looking for the HC-05, watch carefully to make sure that the device offered is the HC-05, which is programmable as master or a slave, and not the HC-06 which can only be one or the other.

The HC-05 is a surface mount module and runs at 3.3v. Many vendors offer the module mounted on a carrier board with pins and, for some, 5v to 3.3v level translation. Of course the carrier boards add to the price, but it remains reasonable. The unit purchased for this exercise was under $11. It arrived in less than a week from New York (many of the vendors ship from China which can take up to a month to arrive).

This exercise covers an Arduino library that I put together to make it easier to to work with the HC-05. The library handles the command/data mode switching and provides blocking for write() calls if there is no connection. The HC05 library can be easily configured to work with hardware or software serial ports and includes a debug mode.

Resources

  • HC-05 Bluetooth to Serial Module
    If you buy one mounted on a carrier (recommended), make sure it has a 6 pin connector that includes the KEY and STATE signals. Keep in mind that the base HC-05 module is a 3.3v device, so if you are using a 5V Arduino (such as the UNO), then you will need to get a carrier with on-board regulator and 5v to 3v level shifters, or add those components yourself.

  • Arduino
    I used an Arduino UNO v3 while developing this library. The library was designed to work with other members of the Arduino family, it simply has not been tested with other family members.

  • A solderless breadboard with a selection of jumper wires. The colors I used were chosen somewhat arbitrarily and don't really matter. Use what you have.

  • A terminal program on a computer or smart phone that has a Bluetooth interface. I used Blue Term  on an Android phone for my testing.

Setup

The breadboard configuration is simple:
Recommended Connections
This is the recommended connection and matches the default HC05 library configuration:
  • HC05:Key to UNO:pin3
  • HC05:State to UNO:pin2
  • HC05:TX to UNO:pin1
  • HC05:RX to UNO:pin0
  • HC05:GND to UNO:Gnd
  • HC05:5V to UNO:5V
Echo example
Change Device Name
  - Highlight the baud rate changes
Configuration / Development / Debug
 
Contact me about the exercise by commenting on my Google+ post or by opening an issue at the GitHub repository for the library..
Comments