I learned this from TechBitar. http://www.techbitar.com/modify-the-hc-05-bluetooth-module-defaults-using-at-commands.html
My deep thanks to him.
I’m gonna put this here ‘cos nobody ever reads this stuff until AFTER they’ve made a mistake. So no excuses:
BEFORE YOU START…..
1) When you upload the sketch, ensure the Arduino and BT are not connected (via their RX’s and TX’s) – or I guess, just make sure there’s no power to the BT (disconnect BT from 5V)
2) Don’t power the BT module until everything’s ready.
If you see “Enter AT commands” the AT COMMANDS AND KEYWORDS MUST ALL BE IN CAPITAL LETTERS..
3) Ensure the Serial Monitor program is started afresh after the BT module is powered up.
4) Ensure that the Baud rate in Serial monitor is 9600
5) Ensure that the option “Both NL and CR” is selected in the Terminal Monitor program. (NL = New line and CR = Carriage Return (‘pressing Enter’). Otherwise things won’t work.
If It’s not working….
A) Check your Arduino is plugged into the computer and you see the ‘Power On’ LED on your Arduino board.
B) Check the Arduino is installed in Windows properly…. Press the ‘Windows button’ and then ‘X’ at the same time. Select Device Manager. Look under Ports. Your Arduino should be there and port number shown. Remember this port number otr write it down. Then, go into your Arduino IDE window and then open the ‘Tools’ menu. Make sure you have the right Arduino board selected and that the port number is correct. Then upload the sketch.
If its still not working…
i) Close the Serial Monitor and reopen it from the sketch (having of course previously uploaded the sketch!)
And if after all that it’s STILL NOT WORKING!!!
ii) Check to see if you have a BT module with a little button on it near the pin called KEY (or EN (for ‘enable’) pin). This button (if it exists) must be held down on the BT module when it powers up. You have to keep it held downwhen you send AT commands to it (you can let go when no commmand are being sent to it). This is tedious, yes, and sometimes it’s hard to press the tiny button in, but you are unlikely to program the BT module often, so bear with it. Remember. you must have the button pressed in for any INPUT or OUTPUT command.
If it’s still not working after that…
iii) Check to make sure you’ve put the jumpers in the right places. MANY problems are because the wiring is not correct like a jumper has been plugged into the wrong hole, or a jumper has been left off.
The wiring / circuit diagram (modified from TechBitar’s site):
(Click to enlarge)
The Sketch: (direct from TechBitar’s site):
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
And now, examples HC-05 AT Commands (from TechBitar’s site):
You can send AT Commands to the HC-05 from the Arduino IDE Serial Monitor while the Arduino is running the attached Arduino program.
I have listed a few popular AT commands that will change the HC-05 device name, pass code, and speed. You will find a full set of AT commands from the attached HC-05 reference PDF file.
(remove double quotes from AT command)
To return HC-05 to mfg. default settings: “AT+ORGL”
To get version of your HC-05 enter: “AT+VERSION?”
To change device name from the default HC-05 to let’s say MYBLUE enter: “AT+NAME=MYBLUE”
To change default security code from 1234 to 2987 enter: “AT+PSWD=2987”
To change HC-05 baud rate from default 9600 to 115200, 1 stop bit, 0 parity enter: “AT+UART=115200,1,0”
Essentially I’m reproducing what he wrote but I’m adding a little bit extra. E.g. I modify his diagram so that you are less likely to BURN OUT YOUR BT MODULE. I use a voltage divider that I learned from GreatSciott with his control an RGB LED with BT and a Smartphone (Android).