Arduino HC-05 Bluetooth Master with AT Commands: Wiring, Code and Simulator

To build this Arduino HC-05 Bluetooth Master with AT Commands project you need an Arduino Uno and a Bluetooth HC-05, a 1 kΩ resistor and a 2 kΩ resistor. Holds KEY high to send AT+ROLE=1 and AT+CMODE=1, then connects by itself to the slave in your other tab and pings it. Make the 9 connections in the wiring table, upload the Arduino C++ code, and run the slave in another tab first. Change AT+CMODE=1 to AT+CMODE=0 and see why a master needs a BIND address then.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1Bluetooth HC-05Bluetooth serial module: VCC 5 V, GND, TXD → the board’s RX pin, RXD ← the board’s TX pin (through a 1k/2k divider on a 5 V board). Starts at 9600 baud; hold EN high at power-up for AT commands at 38400. Pair it from the Radio tab’s phone terminal, or with a master HC-05 in another circuit (open it in a second tab).
11 kΩ resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
12 kΩ resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.

Wiring

#FromTo
1Arduino Uno 5VBluetooth HC-05 VCC
2Arduino Uno GNDBluetooth HC-05 GND
3Arduino Uno pin 10Bluetooth HC-05 TXD
4Arduino Uno pin 111 kΩ resistor leg 1
51 kΩ resistor leg 2Bluetooth HC-05 RXD
62 kΩ resistor leg 1Bluetooth HC-05 RXD
7Arduino Uno GND2 kΩ resistor leg 2
8Arduino Uno pin 8Bluetooth HC-05 STATE
9Arduino Uno pin 9Bluetooth HC-05 EN

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a Bluetooth HC-05, a 1 kΩ resistor and a 2 kΩ resistor from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to Bluetooth HC-05 VCC.
  4. Wire 2. Connect Arduino Uno GND to Bluetooth HC-05 GND.
  5. Wire 3. Connect Arduino Uno pin 10 to Bluetooth HC-05 TXD.
  6. Wire 4. Connect Arduino Uno pin 11 to 1 kΩ resistor leg 1.
  7. Wire 5. Connect 1 kΩ resistor leg 2 to Bluetooth HC-05 RXD.
  8. Wire 6. Connect 2 kΩ resistor leg 1 to Bluetooth HC-05 RXD.
  9. Wire 7. Connect Arduino Uno GND to 2 kΩ resistor leg 2.
  10. Wire 8. Connect Arduino Uno pin 8 to Bluetooth HC-05 STATE.
  11. Wire 9. Connect Arduino Uno pin 9 to Bluetooth HC-05 EN.
  12. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  13. Run it. Press Run. Run the slave in another tab first. Change AT+CMODE=1 to AT+CMODE=0 and see why a master needs a BIND address then.

Arduino C++ code

// HC-05 master: sets itself up with AT commands, connects to the slave in
// your other tab ("HC-05 slave"), then sends a ping every second.
// Wiring: HC-05 VCC 5V, GND, TXD -> 10, RXD <- 11 (1k/2k divider),
// EN (KEY) <- 9, STATE -> 8.
#include <SoftwareSerial.h>

SoftwareSerial bt(10, 11);   // RX, TX
const int KEY = 9, STATE = 8;

void at(const char *cmd) {
  bt.println(cmd);
  delay(150);
  Serial.print(cmd);
  Serial.print("  -> ");
  while (bt.available()) {
    char c = bt.read();
    if (c != '\r' && c != '\n') Serial.print(c);
    else if (c == '\n') Serial.print(' ');
  }
  Serial.println();
}

void setup() {
  Serial.begin(9600);
  pinMode(STATE, INPUT);
  pinMode(KEY, OUTPUT);
  bt.begin(9600);
  digitalWrite(KEY, HIGH);   // KEY high: the module takes AT commands
  delay(100);
  at("AT");
  at("AT+NAME=Master");
  at("AT+ROLE=1");           // master: it connects to a slave by itself
  at("AT+CMODE=1");          // to any slave with the same PIN
  digitalWrite(KEY, LOW);    // back to data mode
  Serial.println("Searching for the slave...");
  while (digitalRead(STATE) == LOW) {}
  Serial.println("Connected!");
}

unsigned long n = 0;
void loop() {
  bt.print("ping ");
  bt.println(n++);
  unsigned long start = millis();
  while (millis() - start < 1000) {
    if (bt.available()) Serial.write(bt.read());
  }
}

What to try

Run the slave in another tab first. Change AT+CMODE=1 to AT+CMODE=0 and see why a master needs a BIND address then.

Frequently asked questions

How do I wire the HC-05 Bluetooth Master with AT Commands project on an Arduino Uno?

Make 9 connections: Arduino Uno 5V to Bluetooth HC-05 VCC; Arduino Uno GND to Bluetooth HC-05 GND; Arduino Uno pin 10 to Bluetooth HC-05 TXD; Arduino Uno pin 11 to 1 kΩ resistor leg 1; 1 kΩ resistor leg 2 to Bluetooth HC-05 RXD; 2 kΩ resistor leg 1 to Bluetooth HC-05 RXD; Arduino Uno GND to 2 kΩ resistor leg 2; Arduino Uno pin 8 to Bluetooth HC-05 STATE; Arduino Uno pin 9 to Bluetooth HC-05 EN.

What parts do I need for this Arduino project?

An Arduino Uno and a Bluetooth HC-05, a 1 kΩ resistor and a 2 kΩ resistor.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Holds KEY high to send AT+ROLE=1 and AT+CMODE=1, then connects by itself to the slave in your other tab and pings it.

More Arduino Uno projects