Using HC-05 module

Hello all, arduino beginer here,

I have a question about using a HC-05 module on a Arduino Medga 2560. Im using it for a project to connect to a digital ruler. I need it to read the measurments and print them onto the Serial monitor. Since the ruler functions as a BT keyboard i dont think its a problem to print the measurments onto the Serial monitor. Also the Ruler acts as a master and can't be configured.

I was wondering if i can use the AT commands to connect the module to the ruler. If yes whats the command AT command and how do i get the module to write back to me through the Serial Monitor?

Here's the code i've been using:

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN

void setup() 
{
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("Enter AT commands:");
}

void loop()
{
  if (Serial.available()){
    Serial.write(Serial.read());
  }
  if (BTSerial.available()){
    Serial.write(BTSerial.read());
  }
  if (Serial.available()){
    BTSerial.write(Serial.read());
  }
}

Any help is appreciated. Thanks.

Hi, @grammko
Welcome to the forum.

It will show you how to post your code so it is a scrolling window.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Set the HC-05 module to command mode using AT commands.
Find out the Bluetooth address of your digital ruler.
Connect the HC-05 module to the ruler using the Bluetooth address.
Once connected, you can read the measurements sent by the ruler and print them onto the Serial Monitor.

You can modify your code like this:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // Connect BT RX pin to Arduino pin 11, and BT TX pin to Arduino pin 10

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("Enter AT commands:");

  // Set HC-05 to command mode
  BTSerial.print("AT+CMODE=0\r\n"); // Set to connect to any address
  delay(500);
  BTSerial.print("AT+ROLE=1\r\n");  // Set to master mode
  delay(500);
  BTSerial.print("AT+INIT\r\n");    // Initialize SPP profile
  delay(500);
  BTSerial.print("AT+INQM=1,9,48\r\n"); // Set inquiry mode
  delay(500);
}

void loop() {
  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.