1

I'm trying to get a HC-05 connected as master to a Bluetooth ELM327 OBD scanner.

The HC-05 is accepting AT commands, no problem. This is the sequence I use:

AT+RMAAD    (Clear any paired devices)
AT+ORGL     (Set factory defaults)
AT+ROLE=1   (Set role to master)
AT+RESET    (reset needed after role change)

AT+CMODE=0  (allows connection to any device)
AT+INQM=0,5,9   (set inquiry to search for up to 5 devices for 9 seconds)
AT+INIT     (Inits BT)
AT+INQ      (searches for BT devices)

AT+PAIR=1D,A5,68988A,9  (Pairs to the address of the ELM327, timeout in 9 secs)
AT+BIND=1D,A5,68988A    (Binds the address)
AT+CMODE=1      (HC-05 will now only connect with the paired device)
AT+LINK=1D,A5,68988A    (Connect to device)

Everything is fine, until the last step: AT+LINK. What happens is:

>at+link=1D,A5,68988A
FAIL
+INQ:1D:A5:68988A,1F00,7FFF
OK

So it fails the AT+LINK, then for some reason, it starts inquiry mode. I saw a guide which had CMODE=1/0 swapped. I have tried both, anyway, doesn't make any difference to the result. I should be in full AT command mode, I connected 3.3v to pin 34. The password for the ELM327 is 1234, and the default password for the HC-05 is 1234.

If I skip the link stage, then re-power the HC-05 in comms mode, then the ELM327 flashes its green LED which means its transmitting. The HC-05 flashes rapidly, then slowly, then rapidly, then slowly, and so on. But I get nothing in the serial monitor, not even garbled text.

This is the OBD reader I have

This is the HC-05 I have

So I don't know what the problem is, I have connected the HC-05 to my phone as a slave, and can send messages to and from it though the serial monitor. So its working. And the ELM327 is working fine when connected to my phone. So both are working fine.

So my guess is, either I'm missing something, like, maybe the outgoing password/pin is set with a different AT Command other than AT+PSWD? Or, maybe this particular HC-05 for some reason isn't capable of master mode? Or maybe the ELM327 I have for some reason will never accept a connection from something other than an android phone?

I just wondered if anyone has some experience with this, and can advise, before I go off and buy another HC-05 and another ELM327. Thanks in advance for any help.

Just for more information, I'm using an ESP32, which I know has bluetooth and I wanted to use it, but I couldn't find how to enter it's AT Commands (at least, not easily), it was just easier to buy a HC-05. So since the ESP32 has 3.3v outputs I don't use a voltage divider. I use the 5V out for the VCC on the HC-05, and I use the 3.3v out to go directly to pin 34. Here's the sketch I use to enter AT Commands:

#include "HardwareSerial.h"
#define RXD2 16                //Arduino pin connected to Tx of HC-05
#define TXD2 17                //Arduino pin connected to Rx of HC-05

HardwareSerial BTSerial(2);

char c=' ';
boolean NL = true;

void setup()
{
  // initialize the 2 serial ports:
  Serial.begin(38400);  //For the arduino to communicate with the PC
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");

  BTSerial.begin(38400, SERIAL_8N1, RXD2, TXD2); //-> HC-05 AT mode baud rate is 38400
  Serial.println("BTserial started at 38400");
  Serial.println(" ");  
} 

void loop() {

  // Read from the Bluetooth module and send to the Arduino Serial Monitor
  if (BTSerial.available()) {
    c = BTSerial.read();
    Serial.write(c);
   }

  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available()) {
    c = Serial.read();
    BTSerial.write(c);

    // Echo the user input to the main window. The ">" character indicates the user entered text.
    if (NL) { Serial.print(">");  NL = false; }
    Serial.write(c);
    if (c==10) { NL = true; }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.