When HC-05 is not HC-05

Over 3 months i purchased three identical 6 pin HC-05 Bluetooth boards, so i thought :astonished:
Looking at these boards they are identical & that's where the similarity ends :*

Techbitar wrote a nice article on using the HC-05 and how to enter AT mode, this article covers all 3 devices, except not all AT Commands work for all 3 devices.

There are 3 implementations of firmware, HC05, BTM5 & EGBT5 =(

If your struggling just getting an OK in serial console, go to the bottom of the arduino console and choose "Both NL & CR" New line & Carriage Return.

See attatchments :smiley:

/*
AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)
*/
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
BTSerial.write(Serial.read());
}

low2high
Unplug the 5v to the Bluetooth device, putting it back while your arduino is connected will bring it back to AT mode, if the module is blinking off & on every 2 seconds your in AT mode :slight_smile:

Key mode can either be low2high or high2low

high2low
While connected remove the key wire.

*Note; My 3 bt devices have 5v & 3.3v pins , therefore i am using the 5v pin.

BTM5_AT_COMMAND_User_Guide.pdf (494 KB)

EGBT-045MS-046S Bluetooth Module Manual rev 1r0.pdf (369 KB)

HC-Serial-Bluetooth-Products-201104.pdf (938 KB)

If your using Ardudroid & you have the device setup from Techbitar guide and you want something basic, which only uses the "send data" portion of ardudroid, then use the following;

#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11

int led = 13;

SoftwareSerial blueToothSerial(RxD,TxD); 

void setup() 
{ 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  blueToothSerial.begin(38400);
  delay(500);
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
 
} 
 
void loop() 
{ 
  char recvChar;
  
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();
      
        if(recvChar == '1')
          digitalWrite(led,HIGH);  
       
        else 
        
        if(recvChar == '2')
          digitalWrite(led,LOW); 
  }
}

Tested on Attiny85,45,2313, ProMini 5v, Uno etc etc.

And quick edit to grab some arbitrary value for "GET DATA"

#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11

int led = 13;
float someValue = 1234.56;

SoftwareSerial blueToothSerial(RxD,TxD); 

void setup() 
{ 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  blueToothSerial.begin(38400);
  delay(500);
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);

} 

void loop() 
{ 
  char recvChar;
  char theString[8];
  dtostrf(someValue,4,2,theString);

  if(blueToothSerial.available()){

    recvChar = blueToothSerial.read();

    if(recvChar == '1'){
      digitalWrite(led,HIGH);

      blueToothSerial.write(theString);
      someValue = someValue + 1;
      blueToothSerial.flush();      
    }
    else 

      if(recvChar == '2')
      digitalWrite(led,LOW); 
  }
}