How to use Bluetooth with Arduino

Photo of author

By Jackson Taylor

Home » Arduino » How to use Bluetooth with Arduino

As an Amazon Associate we earn from qualifying purchases.

When it comes to integrating wireless communication with Arduino projects, Bluetooth is a game-changer. This guide breaks down how to use Bluetooth with Arduino step by step, ensuring your project achieves seamless communication.

What is Bluetooth in Arduino Projects?

Bluetooth is a wireless technology that allows devices to communicate over short distances. By integrating Bluetooth modules like HC-05 or HC-06 with Arduino, you can create smart devices, control robots remotely, or send data between gadgets.

Bluetooth is a wireless communication protocol that enables devices to exchange data over short distances without the need for physical connections. In Arduino projects, Bluetooth acts as a bridge between the Arduino board and other devices, such as smartphones, tablets, or PCs. It’s like giving your Arduino a voice to communicate wirelessly, adding versatility and functionality to your projects.

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

How Bluetooth Works in Arduino Projects

Bluetooth uses radio waves to transmit data over a secure, low-power connection. Modules like HC-05 and HC-06 are popular choices for Arduino projects because they simplify Bluetooth integration with microcontrollers. These modules communicate with the Arduino board via serial communication (UART), making them easy to set up and use.

For example, when you pair your Bluetooth module with a smartphone, it creates a wireless communication channel. Through this channel, you can send commands to the Arduino or receive data from it. Imagine controlling a robot with your phone or monitoring sensor readings remotely all thanks to Bluetooth.

Why Use Bluetooth for Arduino Projects?

Bluetooth offers several benefits for Arduino enthusiasts:

  • Wireless Convenience: Eliminate tangled wires.
  • Energy Efficiency: Bluetooth modules are designed for low-power applications.
  • Cost-Effectiveness: Modules like HC-05 are affordable and widely available.
  • Flexibility: Ideal for IoT and mobile app integration.

Required Components for Bluetooth Integration

Before diving into the setup, gather these essentials:

  • Arduino board (e.g., Uno, Mega, or Nano)
  • Bluetooth module (HC-05 or HC-06)
  • Jumper wires
  • Breadboard
  • Power supply or USB cable
See also
How to connect Arduino to the cloud

Setting Up the Bluetooth Module

Follow these steps to set up your Bluetooth module:

Pin Connections

  1. HC-05/HC-06 Pins:
    • VCC: Connect to Arduino’s 5V pin.
    • GND: Connect to Arduino’s GND pin.
    • TXD (Transmit): Connect to Arduino RX (Pin 0).
    • RXD (Receive): Connect to Arduino TX (Pin 1) via a voltage divider to prevent damage.
  2. Arduino Connections: Ensure proper connections for seamless data transfer.

Configuring the Bluetooth Module

Use AT commands to configure your Bluetooth module if needed:

  • Default Settings: Pairing PIN is usually “1234” or “0000”.
  • Name Configuration: Use commands like AT+NAME=YourDeviceName.

Writing the Arduino Code

To communicate with the Bluetooth module, you’ll need a basic sketch.

Sample Code for Serial Communication

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX, TX

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("Bluetooth Ready");
}

void loop() {
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }
  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }
}

This code sets up communication between your computer and the Bluetooth device through Arduino.

Testing Your Bluetooth Setup

Testing ensures everything works as expected:

Pairing the Bluetooth Module

  1. Enable Bluetooth on your smartphone or PC.
  2. Search for the HC-05/HC-06 device.
  3. Pair using the default PIN.

Using a Serial Communication App

Download apps like Serial Bluetooth Terminal for Android or Bluetooth Serial Terminal for Windows. Use these to send and receive data.

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

Common Use Cases for Bluetooth with Arduino

Bluetooth-enabled Arduino projects open the door to endless possibilities:

Home Automation

Control lights, fans, and appliances via a smartphone.

Robotics

Create a remote-controlled robot using a Bluetooth joystick.

IoT Applications

Transmit sensor data to mobile apps for real-time monitoring.

Troubleshooting Bluetooth-Arduino Issues

No Response from Bluetooth Module

  • Ensure proper wiring.
  • Double-check baud rates in your code.

Connection Drops Frequently

  • Reduce interference by minimizing nearby Bluetooth devices.
  • Ensure the power supply is stable.

Data Transmission Issues

  • Verify voltage levels on RX/TX pins.
  • Use a level shifter if needed.

Advanced Tips for Optimizing Bluetooth Projects

Enhance Security

Change the default pairing PIN using AT commands for better security.

See also
Arduino LED fading project

Extend Range

Consider Bluetooth modules with higher range capabilities like HC-05 (Class 1).

Integrate with Mobile Apps

Use platforms like MIT App Inventor or Blynk to build customized apps for controlling your Arduino projects.

Popular Bluetooth Modules for Arduino

Not all Bluetooth modules are created equal. Here are some top options:

HC-05

  • Operates in both master and slave modes.
  • Ideal for versatile projects.

HC-06

  • Slave mode only.
  • Budget-friendly option.

HM-10

  • Supports Bluetooth Low Energy (BLE).
  • Perfect for energy-efficient projects.

Frequently Asked Questions

Can I use multiple Bluetooth modules with one Arduino?

Yes, but it requires careful management of RX/TX pins to avoid interference.

What is the maximum range of a Bluetooth module?

Typical modules like HC-05 offer a range of up to 10 meters, depending on obstacles.

Is Bluetooth the best wireless option for Arduino?

It depends on your project. For longer ranges, consider Wi‑Fi or LoRa.

Conclusion

Using Bluetooth with Arduino unlocks a world of possibilities, from robotics to IoT applications. With the right setup and code, you can transform your projects into innovative wireless solutions. Follow the steps outlined above to master this technology and bring your creative ideas to life.

Matching the Wiring to the Sample Code

The sample sketch above uses SoftwareSerial on pins 10 and 11, so the module should be wired to those pins, not to pins 0 and 1. Pins 0 and 1 are shared with the USB serial connection. If a module is attached there, uploads can fail and the serial monitor can show garbage.

  • Module TXD goes to Arduino pin 10 (the RX pin in the sketch).
  • Module RXD goes to Arduino pin 11 (the TX pin in the sketch), through a voltage divider. The module’s data pins work at 3.3V, while an Uno outputs 5V.
  • VCC and GND go to 5V and GND as described earlier. Check your module board’s label, since some accept only 3.3V.
See also
Arduino machine learning for object detection

If you change the pin numbers in the wiring, change them in the SoftwareSerial line too. The RX and TX labels in the code are from the Arduino’s point of view, so the module’s TX always connects to the Arduino’s RX.

The Ultimate Money-Saving DIY Skill

From power tools and solar banks to your car, batteries are the most expensive part of your gear. Master the step-by-step DIY system to bring dead batteries back to life.

Get the Step-by-Step Guide

Connecting One Arduino to Another with Bluetooth

To link two boards, you need one module acting as master and one as slave. An HC-05 can be either, while an HC-06 can only be a slave. That makes an HC-05 plus an HC-06, or two HC-05 modules, the usual pairings. The general process is:

  1. Put the HC-05 in AT command mode and set its role to master. The exact steps vary between boards, so check the documentation for your module.
  2. Leave the second module as a slave.
  3. Make sure both modules use the same baud rate, then set the master to connect to the slave’s address.
  4. Power both boards. The modules should connect automatically, and the status LED usually blinks more slowly once they are paired.
  5. Use the same SoftwareSerial code on both boards. Anything one board writes to the module appears on the other board’s serial input.

If the two modules will not connect, the most common causes are mismatched baud rates, a master that is not set to the right slave address, and unstable power.

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