2

This is a basic question, but I really have tried my best to find a solution on the internet to no avail.

I have a fairly normal setup. HC05 module connected to an Arduino. The HC05 is also connected to my Mac's Bluetooth (fairly sure of this bc I used AT Commands to confirm). However, when I select the HC05 port in the Arduino IDE, nothing is printed in that port's serial monitor. Am I fundamentally misunderstanding something?

How do I make the Arduino print on my Mac's Arduino IDE through Bluetooth?

Here's my code:

#include <SoftwareSerial.h>

SoftwareSerial MegaloDon(10, 11);

bool isConnected = false; 

void setup() {
  pinMode(9, HIGH); //this pin is connected to "EN" on the HC05 and enables AT commands
  Serial.begin(9600); 
  MegaloDon.begin(9600); //
  connectBluetooth();
}

void connectBluetooth() {
    digitalWrite(9, HIGH);
    MegaloDon.println("AT"); //AT command 
    if (MegaloDon.find("OK")){
      MegaloDon.println("Bluetooth ON");
      digitalWrite(9, LOW);
      Serial.println("Connected");
    } else {
      Serial.println("Attempting to reconnect...");
      delay(2000); // wait 2 seconds before trying again
    }
  }


void loop() {
  if (isConneced()) {
    Serial.println("conneced?");
    **//I'd like to transmit data to my mac's serial monitor on the Arduino IDE here**

  } else {
    Serial.println("not conneced");
    connectBluetooth(); // Attempt to reconnect
  }
}

bool isConneced(){
  Serial.println("is it conneced?");
  digitalWrite(9, HIGH);
  MegaloDon.println("AT");
    if (MegaloDon.find("OK")){
      isConnected = true;
    }
    else{
      isConnected = false;
    }
    digitalWrite(9, LOW);
}
 



0

1 Answer 1

1

I see two problems:

  1. Your AT commands don't actually confirm, that the HC05's bluetooth is connected to anything. You are only ever sending "AT", which sets the HC05 to AT mode for a specific amount of time. So basically you are only testing the Serial connection between the Arduino and the HC05. If you want to get other information from the HC05, you need to get into AT mode and then use other AT commands (so commands with the "AT" at the start but other information following that) to check the connection.

    So the question is: Is the HC05 really connected to the Mac? The HC05 can be either in device or master mode for bluetooth. When in device mode, the Mac will be able to initiate the connection (like with any other bluetooth device like a headset). When it is in master mode, it itself has to initiate the connection (then the Mac would need to be the device), which would need to be done with AT commands. How exactly do you know, that the HC05 is connected to the Mac and that you are looking at the correct port in the Arduino IDE? Does the port vanish and reappear, when you turn the Arduino/HC05 combo off and a little bit later on again?

  2. In your code you are only sending data through the MegaloDon interface at one point:

     MegaloDon.println("Bluetooth ON");
    

    All the other calls to MegaloDon are the "AT" command. And this line is executed directly after sending "AT" to the HC05 and getting "OK" back. Do you remember what I wrote above? The "AT" command will set the HC05 to AT mode for a limited amount of time (typically 1 or 2 seconds). The firmware on the HC05 will then try to interpret all data send in this time as AT commands. It will not send this data through the bluetooth interface! So, if you want to send that data to the Mac, then you should wait with sending it for a bit, so that the HC05 is no longer in AT mode.

2
  • 1. Thank you for the response! I see where I sent wrong. I understand now that because I am using the HC05 as the master, I would need to connect to my Mac from the HC05 itself with AT commands. Do you happen to know where I could find the AT commands/tutorials necessary for this? Also, I am fairly sure there is a connection(except HC05 is slave) because the port is called smthg like "DSDTECH HC05" and as you said, disappears/reappears when I power on/off the module. 2. Ohhhh, thank you. I'll make sure to add a delay. Thank you so much again!
    – iceninja21
    Commented Apr 16, 2023 at 20:59
  • Would the relevant AT commands be AT+LINK=mac address and AT+STATE?
    – iceninja21
    Commented Apr 16, 2023 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.