Communication with HC-06

Hey again,

I had writen here before because I had problems with the arduino HC-06 module and a rather complex code. However, I had tried a simplest situation and I still have problems.

Set up:

  • win10 computer
  • Arduino UNO board
  • HC-06 bluetooth module
  • 2.0 Arduino IDE

I have connected everything as shown in the picture. The USB cable is connected to a socket.


Also I wrote this simple codeç

void setup() {
  Serial.begin(9600);
  Serial.write("ready");
}

void loop() {
  if(Serial.read() == '1'){
    digitalWrite(13, HIGH);
    Serial.println("ON");
  }else if(Serial.read() == '0'){
    digitalWrite(13, LOW);
    Serial.println("OFF");
  }
  

}

When I write '0' or '1' in the serial monitor corresponding to the COM port of the BT module, I get the answer but the LED wouldn't blink accordingly. Screenshot here:

I tried to use it with a mobile phone and it worked (altought the led didn't bright a lot), so I don't know what happens with the pc.

Thanks!

pinMode(13,OUTPUT); perhaps....

Up of your terminal window, left from baudrate settings - you can see droplist with "Carriage return" option. Select the "Nothing" (or something like) option on it.

You are using hardware serial for both Bluetooth and Serial monitor, i.e. sharing the UART. In that situation, you cannot send from the serial monitor. If you use the phone to talk to Arduino via Bluetooth, you can observe two-way traffic on the serial monitor. No comment on the LEDs but, if you get any result at all, your code is probably kosher.

But do you really see "ready" on the screen.?

When using both PC and Bluetooth, the solution is to have Bluetooth on software serial. But there is probably no need to bother with that, you already know how to communicate with Bluetooth, and about the only time you might seriously need to use the serial monitor is when configuring the HC-06, and even that is not strictly necessary.

AND, just in case you don't already know and just got lucky, you need to disconnect Bluetooth while uploading your programme!

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