Mastering Bluetooth Control: Arduino & HC-05 Guide

Wirelessly control devices using Bluetooth! This in-depth guide combines hardware integration, bidirectional communication, and practical applications for IoT prototypes, robotics, and home automation. Learn to configure the HC-05 module, write robust Arduino codeControlling a DC Motor with a Transistor and ArduinoControlling a DC Motor with a Transistor and ArduinoLearn how to safely control DC motors with Arduino using transistor circuits, code examples, and practical wiring diagrams for your robotics projects., and implement real-world projects from LED control to motorized systems.

Table of Contents🔗

Understanding Bluetooth and the HC-05🔗

Bluetooth is a wireless standard for short-range data exchange. The HC-05Setting up Bluetooth ModulesSetting up Bluetooth ModulesDiscover a detailed guide on setting up Bluetooth modules with Arduino, covering hardware, software, pairing, and troubleshooting for seamless connectivity. module is a Bluetooth 2.0+EDR transceiver operating at 2.4GHz, supporting both master/slave modes and serial communicationUnderstanding Arduino ComponentsUnderstanding Arduino ComponentsExplore every Arduino board component and learn expert integration tips to boost your design and troubleshooting skills in our comprehensive guide. (UART). Key features:

Theory:

The HC-05 abstracts wireless communicationWireless Communication BasicsWireless Communication BasicsDiscover key techniques and best practices for wireless modules in Arduino projects. Build robust, secure networks for home automation and remote sensing. into serial data packets, enabling seamless integration with microcontrollers. Data packets include preamble, MAC address, payload (up to 1024 bytes), and CRC error checking.

Hardware Overview & Wiring🔗

Components

ComponentDescription
Arduino BoardUno, Nano, Mega, etc.
HC-05 ModuleBluetooth transceiver
Voltage DividerFor 5V→3.3V conversion (R1=2.2kΩ, R2=3.3kΩ)
L298N DriverFor motor control (advanced project)

HC-05 Pinout

PinFunctionArduino Connection
VCC3.3V-6V Power5V (via voltage divider)
GNDGroundGND
TXTransmit DataRX (Digital Pin 0/SoftwareSerial)
RXReceive DataTX (Digital Pin 1/SoftwareSerial)
ENEnable/AT Mode3.3V (for AT mode)

Voltage DividerImplementing a Light SensorImplementing a Light SensorLearn how to set up and code an Arduino light sensor using an LDR, a voltage divider circuit, and reliable calibration techniques. Calculation:

$$ R2 = \frac{V_{in} \times R1}{V_{out} - V_{in}} \quad (\text{Example: } R1=2.2k\Omega, R2=3.3k\Omega \text{ for 5V→3.3V}) $$

Wiring Diagram (Basic Setup)

flowchart TD A[Arduino] -->|TX| B[HC-05 RX] A -->|RX| C[HC-05 TX] D[5V Power] --> B D --> C E[Ground] --> B E --> C

Circuit Setup & Configuration🔗

Step 1: WiringConnecting LCD DisplaysConnecting LCD DisplaysDiscover how to connect and program LCD displays with Arduino in this comprehensive guide. Learn wiring, coding, and troubleshooting for optimum performance.

Step 2: AT Commands for ConfigurationSetting up the Arduino EnvironmentSetting up the Arduino EnvironmentUnlock your Arduino journey with our step-by-step guide. Install, configure, and troubleshoot the IDE on Windows, macOS, and Linux for prototyping.

1. Power HC-05Setting up Bluetooth ModulesSetting up Bluetooth ModulesDiscover a detailed guide on setting up Bluetooth modules with Arduino, covering hardware, software, pairing, and troubleshooting for seamless connectivity. while holding EN high to enter AT mode.

2. Upload this code to configure settingsSetting up the Arduino EnvironmentSetting up the Arduino EnvironmentUnlock your Arduino journey with our step-by-step guide. Install, configure, and troubleshoot the IDE on Windows, macOS, and Linux for prototyping.:

#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3); // RX, TX
void setup() {
  Serial.begin(9600);
  BT.begin(38400); // HC-05 AT mode default baud rate
}
void loop() {
  if (BT.available()) Serial.write(BT.read());
  if (Serial.available()) BT.write(Serial.read());
}

Common AT CommandsSetting up Bluetooth ModulesSetting up Bluetooth ModulesDiscover a detailed guide on setting up Bluetooth modules with Arduino, covering hardware, software, pairing, and troubleshooting for seamless connectivity.:

Programming the Arduino🔗

Basic Example: LED Control

CircuitYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.: Connect LED to Pin 13 with 220Ω resistorControlling LEDs with Arduino: The BasicsControlling LEDs with Arduino: The BasicsLearn the essentials of Arduino LED control: proper wiring, coding with digitalWrite and PWM, plus troubleshooting tips to enhance your projects..

CodeYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.:

#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3);
void setup() {
  pinMode(13, OUTPUT);
  BT.begin(9600);
}
void loop() {
  if (BT.available()) {
    char cmd = BT.read();
    if (cmd == '1') digitalWrite(13, HIGH);
    if (cmd == '0') digitalWrite(13, LOW);
  }
}

TestingYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.:

1. Pair with HC-05Setting up Bluetooth ModulesSetting up Bluetooth ModulesDiscover a detailed guide on setting up Bluetooth modules with Arduino, covering hardware, software, pairing, and troubleshooting for seamless connectivity. via smartphone (PIN: 1234).

2. Use Serial Bluetooth Terminal to send 1/0.

Advanced Project: DC Motor Control

Components: L298N Driver, 12V DC Motor, 9V BatteryControlling a DC Motor with a Transistor and ArduinoControlling a DC Motor with a Transistor and ArduinoLearn how to safely control DC motors with Arduino using transistor circuits, code examples, and practical wiring diagrams for your robotics projects..

CircuitYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.:

graph LR Arduino -->|PWM Pin 5| L298N[L298N Driver] L298N --> DC_Motor HC-05 -->|TX/RX| Arduino

Code (PWM Speed ControlControlling a DC Motor with a Transistor and ArduinoControlling a DC Motor with a Transistor and ArduinoLearn how to safely control DC motors with Arduino using transistor circuits, code examples, and practical wiring diagrams for your robotics projects.):

#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#define ENA 5
#define IN1 6
#define IN2 7
void setup() {
  BT.begin(9600);
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}
void loop() {
  if (BT.available()) {
    int speed = BT.parseInt(); // Read 0-255 from app
    analogWrite(ENA, speed);
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
  }
}

MIT App Inventor SetupSetting up the Arduino EnvironmentSetting up the Arduino EnvironmentUnlock your Arduino journey with our step-by-step guide. Install, configure, and troubleshoot the IDE on Windows, macOS, and Linux for prototyping.:

1. Add a slider (0-255) and ListPicker for device selection.

2. Send slider values via Bluetooth on PositionChanged.

Bluetooth Communication Protocols🔗

The HC-05Setting up Bluetooth ModulesSetting up Bluetooth ModulesDiscover a detailed guide on setting up Bluetooth modules with Arduino, covering hardware, software, pairing, and troubleshooting for seamless connectivity. uses SPP for data transfer. Signal strength is governed by:

$$ \text{Received Power (dBm)} = P_t + G_t + G_r - 20\log_{10}\left(\frac{4\pi d}{\lambda}\right) $$

Testing & Troubleshooting🔗

IssueSolution
HC-05 not respondingCheck voltage divider on RX line
AT commands failVerify baud rate & EN pin state
Motor jittersIncrease PWM frequency

TestingYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. Steps:

1. Pair devices via smartphone Bluetooth settingsSetting up the Arduino EnvironmentSetting up the Arduino EnvironmentUnlock your Arduino journey with our step-by-step guide. Install, configure, and troubleshoot the IDE on Windows, macOS, and Linux for prototyping..

2. Use terminal apps to send/receive data.

3. Debug using Serial MonitorUsing the Serial MonitorUsing the Serial MonitorDiscover our detailed Arduino Serial Monitor guide covering setup, coding, and troubleshooting to optimize your debugging and project performance in real-time. output.

Applications & Extensions🔗

Entrepreneur Tip: Use HC-05 in low-cost MVPs before upgrading to BLE/Wi-Fi modulesConnecting Arduino to the InternetConnecting Arduino to the InternetDiscover how to connect your Arduino to the Internet with our complete guide covering hardware, protocols, coding tips, and troubleshooting for IoT projects..

Conclusion🔗

This guide equips you to build Bluetooth remote controls for diverse applications. By integrating hardware, software, and communication protocols, you can create systems ranging from simple LED controllers to complex IoT networks. Expand your projects with bidirectional communication, custom apps, or sensor integrationIntegrating Third-Party LibrariesIntegrating Third-Party LibrariesLearn to integrate third-party libraries into Arduino projects with our guide. Discover tips on selection, installation, coding, and troubleshooting. for advanced functionality.

Next Steps: Explore BLE with HM-10 modules or integrate Python for data analysis. Happy building!

Author: Marcelo V. Souza - Engenheiro de Sistemas e Entusiasta em IoT e Desenvolvimento de Software, com foco em inovação tecnológica.

References🔗

Share article

Related Articles