0
0
Arduinoprogramming~15 mins

Bluetooth with HC-05/HC-06 module in Arduino - Deep Dive

Choose your learning style9 modes available
Overview - Bluetooth with HC-05/HC-06 module
What is it?
Bluetooth with HC-05/HC-06 module means using small wireless devices to send and receive data between an Arduino and another Bluetooth device like a phone or computer. The HC-05 and HC-06 are popular modules that make this wireless connection easy. They let your Arduino talk without wires, using Bluetooth signals. This helps build projects like remote controls, wireless sensors, or data loggers.
Why it matters
Without Bluetooth modules like HC-05 or HC-06, connecting devices wirelessly would be much harder and more expensive. These modules solve the problem of short-range wireless communication simply and cheaply. They let hobbyists and beginners add wireless features to their projects, making devices more flexible and user-friendly. Imagine having to use cables everywhere — Bluetooth frees you from that mess.
Where it fits
Before learning this, you should know basic Arduino programming and how to use serial communication. After mastering Bluetooth with HC-05/HC-06, you can explore advanced wireless protocols like Wi-Fi or BLE, or build complex IoT projects that connect many devices.
Mental Model
Core Idea
The HC-05/HC-06 module acts like a wireless serial cable, letting your Arduino send and receive data over Bluetooth as if it were connected by wires.
Think of it like...
It's like having a walkie-talkie between two friends instead of shouting across a room. The HC-05/HC-06 modules are the walkie-talkies that let your Arduino and phone talk without wires.
Arduino ──TX/RX──> HC-05/HC-06 Module ──Bluetooth──> Phone/PC

[Arduino] <──TX/RX── [HC-05/HC-06 Module] <──Bluetooth──> [Phone/PC]
Build-Up - 7 Steps
1
FoundationUnderstanding Bluetooth Serial Communication
🤔
Concept: Bluetooth modules like HC-05/HC-06 use serial communication to send data wirelessly.
Serial communication means sending data one bit at a time over a wire or wireless link. The HC-05/HC-06 modules connect to Arduino's serial pins (TX and RX) and convert serial data into Bluetooth signals and back. This lets Arduino communicate with other Bluetooth devices as if they were connected by a cable.
Result
You can send text or numbers from Arduino to a phone or computer wirelessly using Bluetooth.
Understanding serial communication is key because Bluetooth modules just replace the cable with wireless signals but keep the same data format.
2
FoundationWiring HC-05/HC-06 to Arduino Correctly
🤔
Concept: Proper wiring connects Arduino's serial pins to the Bluetooth module's pins to enable communication.
Connect Arduino TX (pin 1) to HC-05 RX, and Arduino RX (pin 0) to HC-05 TX. Also connect power (5V or 3.3V depending on module) and ground. Some modules need voltage level shifting on RX pin because Arduino uses 5V signals but HC-05 RX expects 3.3V. Use a voltage divider or level shifter to protect the module.
Result
The module powers on and is ready to send and receive Bluetooth data with Arduino.
Correct wiring prevents damage and ensures data flows properly between Arduino and the Bluetooth module.
3
IntermediateUsing SoftwareSerial for Flexible Pins
🤔Before reading on: do you think you must always use Arduino pins 0 and 1 for Bluetooth communication? Commit to your answer.
Concept: SoftwareSerial library lets you use other digital pins for serial communication, freeing pins 0 and 1 for USB debugging.
Arduino has only one hardware serial port on pins 0 and 1, which is also used for uploading code and debugging. SoftwareSerial creates a serial port on other pins, like 10 and 11. You can connect HC-05 RX and TX to these pins and communicate without interfering with USB.
Result
You can upload code and debug while using Bluetooth communication on different pins.
Knowing SoftwareSerial avoids conflicts and makes your project easier to develop and debug.
4
IntermediatePairing and Connecting Bluetooth Devices
🤔Before reading on: do you think the HC-05 module automatically connects to any Bluetooth device nearby? Commit to your answer.
Concept: Bluetooth devices must be paired and connected before exchanging data securely.
The HC-05 module can be set as master or slave. Slave waits for connections, master initiates them. You pair your phone or PC with the module using a PIN code (default is usually '1234'). Once paired, devices connect and can send data. You can use apps like Serial Bluetooth Terminal to test communication.
Result
Your Arduino and phone can exchange data wirelessly after pairing and connecting.
Understanding pairing prevents confusion about why devices don't communicate immediately.
5
IntermediateSending and Receiving Data in Arduino Code
🤔Before reading on: do you think sending data over Bluetooth requires special commands different from serial print? Commit to your answer.
Concept: You use normal serial commands in Arduino code to send and receive data through the Bluetooth module.
In your Arduino sketch, use Serial.print() or Serial.write() to send data to the HC-05 module. Use Serial.read() to receive data from the module. If using SoftwareSerial, replace Serial with your SoftwareSerial object. This makes Bluetooth communication simple and similar to wired serial communication.
Result
Data sent from Arduino appears on the connected device, and data from the device can control Arduino.
Knowing that Bluetooth uses normal serial commands simplifies programming and debugging.
6
AdvancedConfiguring HC-05 with AT Commands
🤔Before reading on: do you think the HC-05 module settings can be changed after purchase? Commit to your answer.
Concept: HC-05 modules can be configured using special AT commands to change name, PIN, role, and baud rate.
By entering AT command mode (usually by holding a button while powering the module), you can send text commands like 'AT+NAME=MyDevice' to rename the module or 'AT+ROLE=1' to set it as master. This lets you customize behavior for your project needs. Commands are sent via serial interface and responses confirm changes.
Result
Your Bluetooth module behaves exactly as you want, with custom name, security, and connection settings.
Understanding AT commands unlocks full control over the module, enabling advanced and reliable projects.
7
ExpertHandling Bluetooth Communication Reliability
🤔Before reading on: do you think Bluetooth communication with HC-05 is always error-free? Commit to your answer.
Concept: Bluetooth communication can have errors or delays; handling these properly is key for robust projects.
Wireless signals can be interrupted by obstacles or interference. Your Arduino code should check if data is available before reading, use timeouts, and confirm commands with acknowledgments. Also, managing connection states and reconnecting automatically improves reliability. Buffer sizes and baud rates affect performance and must be tuned.
Result
Your project maintains stable Bluetooth communication even in noisy or changing environments.
Knowing how to handle errors and connection issues prevents frustrating bugs and improves user experience.
Under the Hood
The HC-05/HC-06 module contains a Bluetooth radio and a microcontroller that converts serial data from Arduino into Bluetooth signals and vice versa. It uses the Bluetooth Serial Port Profile (SPP) to create a wireless serial link. The module handles pairing, connection, and data transmission protocols internally, presenting a simple serial interface to Arduino. Data is sent in packets over the 2.4 GHz band, with error checking and retransmission managed by the Bluetooth stack.
Why designed this way?
The modules were designed to simplify adding Bluetooth to microcontrollers without complex Bluetooth stacks or hardware. By exposing a serial interface, they leverage existing Arduino serial programming skills. This design trades off some flexibility for ease of use and low cost, making Bluetooth accessible to hobbyists and beginners. Alternatives like BLE require more complex code and hardware.
┌───────────────┐      Serial      ┌───────────────┐      Bluetooth      ┌───────────────┐
│   Arduino     │ <──────────────> │ HC-05/HC-06   │ <────────────────> │ Phone/Computer│
│ (Microcontroller)│                │ (Bluetooth    │                   │ (Bluetooth    │
│                 │                │  Module)      │                   │  Device)      │
└───────────────┘                └───────────────┘                   └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Do you think HC-05 and HC-06 modules are exactly the same? Commit to yes or no before reading on.
Common Belief:HC-05 and HC-06 are identical Bluetooth modules and can be used interchangeably.
Tap to reveal reality
Reality:HC-05 can act as master or slave and supports AT commands for configuration; HC-06 is slave-only and has limited configurability.
Why it matters:Using HC-06 when master mode or configuration is needed will cause project failure or inability to connect as intended.
Quick: Do you think you can connect multiple devices to one HC-05 module at the same time? Commit to yes or no before reading on.
Common Belief:One HC-05 module can connect to many devices simultaneously like Wi-Fi routers.
Tap to reveal reality
Reality:HC-05 supports only one active Bluetooth connection at a time.
Why it matters:Trying to connect multiple devices causes connection drops and confusion, limiting project design.
Quick: Do you think you can power the HC-05 module directly from Arduino 5V without any precautions? Commit to yes or no before reading on.
Common Belief:HC-05 modules always work fine powered directly from Arduino 5V pins without extra components.
Tap to reveal reality
Reality:Some HC-05 modules require 3.3V logic levels on RX pin; feeding 5V signals without level shifting can damage the module.
Why it matters:Ignoring voltage requirements can permanently damage the Bluetooth module, wasting time and money.
Quick: Do you think Bluetooth communication is always instant and error-free? Commit to yes or no before reading on.
Common Belief:Bluetooth data sent from Arduino always arrives immediately and without errors on the other device.
Tap to reveal reality
Reality:Bluetooth can have delays, interference, and occasional data loss; code must handle these gracefully.
Why it matters:Assuming perfect communication leads to bugs and unreliable projects in real-world environments.
Expert Zone
1
The HC-05 module's baud rate can be changed via AT commands to optimize speed and reliability for different applications.
2
Using hardware serial pins (0 and 1) for Bluetooth can interfere with uploading code and debugging, so SoftwareSerial or other serial ports are preferred in complex projects.
3
The Bluetooth Serial Port Profile (SPP) used by HC-05 is a classic Bluetooth profile, which differs significantly from Bluetooth Low Energy (BLE) used in newer devices.
When NOT to use
Avoid using HC-05/HC-06 modules when you need low power consumption or multiple simultaneous connections; instead, use BLE modules like the HM-10 or Wi-Fi modules for internet connectivity.
Production Patterns
In real projects, HC-05 modules are often paired with SoftwareSerial to free hardware serial for debugging, configured with custom AT commands for security, and combined with state machines in code to handle connection and data flow robustly.
Connections
Serial Communication
Bluetooth modules extend serial communication wirelessly.
Understanding serial communication fundamentals helps grasp how Bluetooth modules transmit data without wires.
Wireless Networking
Bluetooth is a short-range wireless networking technology.
Knowing Bluetooth's place in wireless networking clarifies its strengths and limits compared to Wi-Fi or cellular.
Walkie-Talkie Communication
Bluetooth communication mimics walkie-talkie style half-duplex talk and listen.
Recognizing Bluetooth as a wireless two-way radio helps understand connection setup, pairing, and data exchange.
Common Pitfalls
#1Connecting HC-05 RX pin directly to Arduino 5V TX pin without level shifting.
Wrong approach:Arduino TX (5V) ──> HC-05 RX (3.3V) directly
Correct approach:Arduino TX (5V) ──> Voltage Divider ──> HC-05 RX (3.3V)
Root cause:Misunderstanding voltage levels causes damage to the Bluetooth module.
#2Using hardware serial pins (0 and 1) for Bluetooth and trying to upload code simultaneously.
Wrong approach:Connect HC-05 TX/RX to Arduino pins 0 and 1 and upload code without disconnecting.
Correct approach:Use SoftwareSerial on other pins for HC-05 and keep pins 0 and 1 free for uploading and debugging.
Root cause:Not realizing hardware serial pins are shared with USB programming interface.
#3Assuming HC-06 can be configured as master device.
Wrong approach:Trying to set HC-06 to master mode via AT commands.
Correct approach:Use HC-05 module if master mode or configuration is needed.
Root cause:Confusing differences between HC-05 and HC-06 modules.
Key Takeaways
HC-05 and HC-06 modules let Arduino communicate wirelessly over Bluetooth using serial data.
Proper wiring and voltage level shifting protect the module and ensure reliable communication.
SoftwareSerial allows flexible pin choices and avoids conflicts with USB programming.
Pairing and connecting devices is necessary before data exchange can happen.
Advanced use includes configuring modules with AT commands and handling communication errors for robust projects.