HC05 BLUETOOTH PAIRING

Photo of author

By Jackson Taylor

Home » Hardware » HC05 BLUETOOTH PAIRING

As an Amazon Associate we earn from qualifying purchases.

The HC-05 is a low-cost Bluetooth module that adds a wireless serial link to Arduino and other microcontroller projects. Pairing it with a phone, a PC or a second module is the first step before you can send any data. The video below shows the pairing process, and the sections after it explain each step in writing so you can follow along or troubleshoot.

What the HC-05 does

The HC-05 uses classic Bluetooth with the Serial Port Profile (SPP). To your microcontroller it looks like a normal UART serial connection: whatever you write to the TX pin is sent over the air, and incoming data comes out on the RX pin.

Unlike the cheaper HC-06, which can only act as a slave, the HC-05 can work as either a master or a slave. A slave waits for another device to connect to it. A master starts the connection. This is why the HC-05 is the usual choice when you want two modules to talk to each other without a phone.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

What you need

Wiring the HC-05 to an Arduino

Most HC-05 breakout boards have an onboard regulator, so they can be powered from 5 V. The data pins are different: the module’s RX pin expects 3.3 V logic, while a 5 V Arduino sends 5 V signals. A simple voltage divider on the line from the Arduino TX pin to the HC-05 RX pin protects the module. The HC-05 TX output is fine to connect directly to an Arduino input.

  1. HC-05 VCC to the Arduino 5 V pin
  2. HC-05 GND to Arduino GND
  3. HC-05 TX to the Arduino RX pin (or a SoftwareSerial RX pin)
  4. HC-05 RX to the Arduino TX pin (or a SoftwareSerial TX pin) through a voltage divider
See also
Arduino ,bluetooth/pc and triac based speed control of ac home fan

If you use the Arduino’s hardware serial pins, disconnect the module while uploading sketches, since the USB connection uses the same pins. SoftwareSerial on two other pins avoids this problem. For more on this, see our guide on how to use Bluetooth with Arduino.

Understanding the status LED

The blinking LED tells you what state the module is in:

  • Fast blinking: powered on and in data mode, but not paired with anything.
  • Slow blinking (about every two seconds): the module is in AT command mode.
  • Two quick blinks followed by a pause: the module is paired and connected.

The exact pattern can vary slightly between board versions, but the fast and slow blink difference is a reliable way to tell which mode you are in.

Pairing the HC-05 with a phone or PC

This is the simplest case, with the HC-05 acting as a slave.

  1. Power the module and check that the LED is blinking fast.
  2. Open the Bluetooth settings on your Android phone or Windows PC and scan for devices.
  3. Select the device named HC-05.
  4. Enter the PIN when asked. The usual default is 1234, and some modules use 0000.
  5. Once the pairing succeeds, open a Bluetooth serial terminal app or a PC terminal program and connect to the module.

On a PC, pairing creates a virtual COM port. Check the Bluetooth settings for the outgoing port number and select that port in your terminal program. The default data baud rate is normally 9600, and your sketch should use the same setting.

Note that iPhones and iPads do not support classic Bluetooth SPP devices like the HC-05, so they usually cannot connect to it. For iOS you would need a BLE module instead.

Entering AT command mode

To change the name, PIN, baud rate or role, you need AT command mode.

  1. Disconnect power from the module.
  2. Press and hold the small button on the board (or hold the KEY/EN pin high).
  3. Power the module while holding the button, then release it. The LED should blink slowly.
  4. Open the Arduino Serial Monitor, or another terminal, at 38400 baud, which is the usual AT mode speed.
  5. Set the line ending to Both NL & CR.

Type AT and you should get OK back. If you get nothing, check the wiring, the baud rate and the line ending setting.

See also
EMBEDDED MAIN PROJECTS

Useful AT commands

  • AT+NAME? and AT+NAME=MyModule read or change the device name.
  • AT+PSWD? and AT+PSWD=”1234″ read or change the PIN. Some firmware versions want the value in quotes, others do not.
  • AT+UART? and AT+UART=9600,0,0 read or set the data baud rate, stop bits and parity.
  • AT+ROLE? and AT+ROLE=1 read or set the role (0 is slave, 1 is master).
  • AT+ADDR? shows the module’s Bluetooth address.
  • AT+VERSION? shows the firmware version.

Command syntax can differ slightly between firmware versions, so if one command returns an error, check the version and try the variant without quotes.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

Pairing two HC-05 modules together

To link two modules, set one as the master and the other as the slave. First, put the slave in AT mode and read its address with AT+ADDR?. The address is shown with colons, but you enter it with commas in the bind command.

  1. On the slave, keep the default role (AT+ROLE=0).
  2. On the master, enter AT mode and set AT+ROLE=1.
  3. Set AT+CMODE=0 so the master connects only to a specific address.
  4. Set AT+BIND= followed by the slave’s address, using commas instead of colons.
  5. Make sure both modules use the same PIN and baud rate.
  6. Power both modules normally, without the button held. They should connect automatically and the LEDs will change to the paired pattern.

Once they are linked, anything sent into one module appears at the other. We cover a full example in Arduino-to-Arduino Bluetooth communication.

Common problems and fixes

  • The module does not show up in the scan. Check the power supply and wiring. A weak supply can stop the module from starting properly.
  • Pairing fails with the PIN. Try 1234, then 0000. If you changed it in AT mode, use the new value.
  • Garbled text in the terminal. The baud rate in your sketch or terminal does not match the module setting.
  • AT commands give no reply. Confirm that the LED blinks slowly, the baud rate is 38400 and the line ending is set to both NL and CR.
  • Two modules will not connect. Check that the roles, the bound address, the PIN and the baud rates all match.
See also
HOME AUTOMATION USING ANDROID MOBILE / BLUETOOTH

What to build next

Once the pairing works, you can use the link for many projects. A phone-controlled Bluetooth controlled robot is a common first project, and the same idea works for home automation with an Android phone. If you want to compare other radios, our wireless module guides cover GSM, XBee, RFID and WiFi.

FAQ

What is the default PIN of the HC-05?

It is usually 1234, though some modules ship with 0000. You can read or change it in AT command mode.

What baud rate does the HC-05 use?

In normal data mode the default is typically 9600. In AT command mode via the button, it is usually 38400.

What is the difference between the HC-05 and the HC-06?

The HC-05 can be configured as master or slave, while the HC-06 works only as a slave. For linking two modules directly, the HC-05 is the better option.

Can I connect the HC-05 to an iPhone?

Usually not. iOS does not support the classic Bluetooth serial profile that the HC-05 uses, so Android phones and PCs are the easier choice.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works