I’ve had to trawl the net to get this info about the HC-05 Bluetooth module so I’ll put as much as I’ve learned. Let me know if I’ve missed anything. Test code, schematic, photos and datasheets are at the end of this post.
About KEY and RESET on the HC-05
Putting the HC-05 into “AT” mode allows you to set parameters like baud rate and the PIN to access the Bluetooth. You can do this through Arduino or Picaxe code easily and don’t need an external reset button or serial terminal. Key is on pin 34 and Reset is on pin 11 (see datasheets). You simply enter AT mode and then send serial strings to the HC05 through software. To enter AT and check the version here are the steps:
- Pull KEY high (so on your Arduino set that pin high)
- Reset the HC05 (Pull RESET low, wait 2 sec, pull RESET high, wait 1 sec)
- Send a serial query eg: AT+VERSION?
- The serial response comes back, process it
- When finished you want to go back to normal communication mode. Pull KEY low and reset again ( Pull KEY low, Pull RESET low, wait 2 sec, pull RESET high, wait 1 sec)
Breakout Board
I was testing my HC-05 Bluetooth module on a breadboard and realised that the standard parts would be more useful on a small breakout board with headers.
- RX on the HC05 is 3.3 volts, but Arduino and Picaxe are usually 5 volts. So it needs a voltage divider to go from 5V Arduino / Picaxe to 3V3 on the Bluetooth board
- The indicator LEDs each need a resistor, these are not connected to the microchip
- Capacitor (optional) to smooth the input voltage
- Reset can do with a resistor before the microchip pin
- KEY (allows microchip to enter AT mode) needs to be pulled to ground and be available for the microchip to pull high.
- RESET needs a resistor
This was done on a small 1 inch square protoboard from Ebay.
#define Reset 9
#define LED 13
#define KEY 8
//int led = 13;
//int KEY = 8;
int inByte = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(LED, OUTPUT);
pinMode(KEY, OUTPUT);
pinMode(Reset, OUTPUT);
Serial.begin(9600);
Serial1.begin(38400);
digitalWrite(KEY, LOW);
digitalWrite(Reset, HIGH);
Serial.println("Setup");
digitalWrite(LED, HIGH);
SetupBluetooth();
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(LED, LOW);
Serial.println("state loop");
while (Serial1.available() > 0) {
digitalWrite(LED, HIGH);
inByte = Serial1.read();
Serial.write(inByte);
}
delay (1000);
}
void SetupBluetooth()
{
// Put it into AT mode
Serial.println("high");
digitalWrite(KEY, HIGH);
resetBT();
delay(1000);
Serial.println("state");
Serial1.println("AT+VERSION?");
// Put BT into normal mode
delay(1000);
Serial.println("normal");
digitalWrite(KEY, LOW);
resetBT();
}
void resetBT()
{
digitalWrite(Reset, LOW);
delay (2000);
digitalWrite(Reset, HIGH);
delay (500);
}