본문 바로가기

메이커 이야기/아두이노

[아두이노] HC-06 블루투스 이름 변경 (AT Command)

반응형

아두이노의 꽃이라고 할 수 있는 블루투스 입니다.

오늘은 HC-06 블루투스 모듈의 이름과 PIN을 변경하는 방법에 대해 포스팅해드립니다.

블루투스의 셋팅을 변경하기 위해서는 AT Command Mode에 진입을 하셔야 하는데요~

 

HC-05와 HC-06은 Command에 진입하는 방법이 다릅니다.

우선 회로는 아래와 같이 연결해주시구요 
회로상에는 HC-05이지만 HC-06도 똑같이 구성해주시면 됩니다~! 
(HC-06 부품 찾기가 귀찮아서 ^^;)

 

코드는 아래와 같이 작성해주세요.

여기서 알아야할 것은

HC-05의 경우 기분 BAUD RATE는 38400이지만,
HC-06은 9600 입니다 ~! 

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3);   //bluetooth module Tx:Digital 2 Rx:Digital 3

void setup() {

  Serial.begin(9600);
  BTSerial.begin(9600);
}

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



이제 업로드 완료 해주시고

AT Command 명령어른 통해 블루투스 이름을 변경해주시면 됩니다.
AT : AT모드 진입 확인
AT+NAMExxxxx ( xxxxx라는 이름으로 Bluetooth 모듈 설정)
AT+PINxxxx (xxxx PinNumber) 설정

자세한 내용은 블루투스 AT Command 명령어를 찾아보시면 좋습니다 ^^

<내용>

AT Commands

Replies do not contain end of line characters. This means when using a serial monitor everything appears on a single line. See the above screen shot.

Some of the basic AT commands are:

AT – connection test command. Returns OK

AT+BAUD AT+BAUD1 – sets the baud rate to 1200 and returns OK1200
AT+BAUD2 – sets the baud rate to 2400 and returns OK2400

Other possible baud rates are
1——— 1200
2——— 2400
3——— 4800
4——— 9600
5——— 19200
6——— 38400
7——— 57600
8——— 115200
9——— 230400
A——— 460800
B——— 921600
C——— 1382400
Be careful with speeds over 115200 when using a Windows computer.

AT+NAME Sets the name of the module. This is the name that is broadcast to other devices. Maximum length is 20 characters.
AT+NAMEmyBluetooth sets the name to myBluetooth, returns OKsetname

AT+PIN Changes the PIN/password.
AT+PIN9999 – changes the PIN to 9999, returns OKsetPIN

AT+VERSION
returns the firmware version – hc01.comV2.0

 

 

 

 

그럼 블루투스를 활용해서 LED를 제어해보면 좋을 것 같습니다.

 

개요는

 

1) 핸드폰에서 안드로이드(BlueTerm)어플을 다운

2) HC-06(Bluetooth) 연결

3) a,b 문자열 전송

4) 아두이노 시리얼로 데이터를 받아 Swith 문을 이용하여 LED 제어

 

아래의 예제 통해 확인해보세요~!

 

https://kgu0724.tistory.com/150

 

[블루투스모듈] HC-06 Bluetooth On/Off

Bluetooth를 통해서 LED를 제어해보도록 하겠습니다. >>제어방식은 아래처럼 할 예정입니다! 1) 핸드폰에서 안드로이드(BlueTerm)어플을 다운 2) HC-06(Bluetooth) 연결 3) a,b 문자열 전송 4) 아두이노 시리얼로..

kgu0724.tistory.com

 

반응형