Apr 17, 2019

Bluetooth HC-06 ATcommand setting - Arduino code (블루투스 HC-06)

- Arduino code for HC-06 bluetooth setting and some AT commands examples in the serial monitor.
(HC-06 블루투스 모듈 세팅을 위한 아두이노 코드와 AT 명령어 사용 예시)

/////////////////////////////////////////////////////////
//main code//
/////////////////////////////////////////////////////////

#include <SoftwareSerial.h>

//4800, 9600, 19200, 38400, 57600, 115200, ...
#define baud_rate 9600

int blueTx = 2;
int blueRx = 4;

SoftwareSerial mySerial(blueTx, blueRx);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(baud_rate);
  mySerial.begin(baud_rate);

  Serial.print("Bluetooth ready");
}

void loop() {
  // put your main code here, to run repeatedly:
  if(mySerial.available()){
    Serial.write(mySerial.read());
  }
  if(Serial.available()){
    mySerial.write(Serial.read()); 
  }
}


/////////////////////////////////////////////////////////
//Serial monitor//
/////////////////////////////////////////////////////////
- Set 'No line ending' and exact 'baud rate' in the Serial monitor, and send AT commands.
(시리얼 모니터 상에서 'No line ending' 와 exact 'baud rate'을 선택해야 AT 명령어가 제대로 인식되어 전달됨)
- Baudrate and PIN number must be matched between Tx module and Rx module.
(수신기의 Baudrate과 PIN number가 발신기의 Baudrate과 PIN number가 서로 일치해야 통신이 가능)

1. Command: AT
    Output: OK

2. Command: AT+BAUD4
    Output: OK9600

    BAUDx: x=1 -> OK1200
                x=2 -> OK2400
                      ...
                x=5 -> OK19200
                x=6 -> OK38400
                x=7 -> OK57600
                x=8 -> OK115200

3. Command: AT+PIN1234
    Output: OKsetPIN

No comments:

Post a Comment