Step 2: The Arduino Code for HC-05 Command Mode
This Arduino program (HC_05.ino) does two things. It takes the AT commands you enter from the Arduino IDE Serial Monitor and sends those commands to the HC-05. The program then reads the output of the HC-05 and displays it on the Arduino IDE Serial Monitor. You can also use a terminal emulator such as Tera Term instead of the Arduino Serial Monitor.
The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via the Serial Monitor.
AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)
SoftwareSerial BTSerial(10, 11); // RX | TX
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
// Keep reading from HC-05 and send to Arduino Serial Monitor
// Keep reading from Arduino Serial Monitor and send to HC-05