ArduinoIntermediate

Smartphone Control via Bluetooth (HC-05)

Control your Arduino projects wirelessly from your Android smartphone using the HC-05 Bluetooth module.

20 April 202613 min read

Introduction

The HC-05 is a popular Bluetooth module that allows for serial communication between Arduino and other devices like smartphones.

Wiring

HC-05 PinArduino Pin
VCC5V
GNDGND
TXPin 2 (RX)
RXPin 3 (TX)

Note: Use a voltage divider (2kΩ and 1kΩ) on the HC-05 RX pin as it expects 3.3V logic.

The Code

#include <SoftwareSerial.h>

SoftwareSerial bt(2, 3); // RX, TX

void setup() {
  bt.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  if (bt.available()) {
    char data = bt.read();
    if (data == '1') digitalWrite(13, HIGH);
    else if (data == '0') digitalWrite(13, LOW);
  }
}
Tags:ArduinoBluetoothWirelessUART