Project showcase
Arduino Customized Bluetooth Controller

Arduino Customized Bluetooth Controller © GPL3+

Building a customized bluetooth controller using Arduino.

  • 1,246 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

Background

一、前言 (Preface) 在製作 Arduino 藍牙遙控器之前,我們先來了解藍牙的使用方式,以手機連接HC-06藍牙模組流程約有底下幾個步驟:

Before building a customized bluetooth controller, there are several steps we need to know about using bluetooth communication. For example, the following steps are for connecting HC-06 with a smart phone:

  • 開啟手機藍牙。 (Turn on bluetooth on a smart phone)
  • 尋找 HC-06 藍牙模組。(Scan for the nearby bluetooth devices)
  • 與 HC-06 藍牙模組配對。(Paire HC-06 with the smart phone)
  • 開啟手機藍牙App。(Open a BT application on the smart phone)
  • 使用手機藍牙App與 HC-06 藍牙模組連線。(Use the BT application to connect with HC-06)

此外在上述流程中,手機藍牙是當主控端 (Master),HC-06藍牙模組當從端 (Slave)。而我們需要將以上的流程先建立好在主控端藍牙模組 HC-05內,讓可以當主控端的 HC-05 藍牙模組在上電後就可以自動連線到 HC-06 從端藍牙模組。本文會以 Arduino Nano 藍牙小夜燈 當 Slave 端 (HC-06)與 Arduino UNO 版的雙軸按鍵搖桿當 Master 端(HC-05)。

Master and Slave

The role of smart phone is bluetooth master. The role of HC-06 is bluetooth slave. HC-05(master) have to store the bluetooth master configuration in itself. After saving the bluetooth master configuration in HC-05(master), it will connect to HC-06(slave) automatically.

此外主控端與從端的速度(baudrate)要一樣,密碼(password)也要一樣。此文所用的 baudrate為 9600,password為 1234。 The baudrate and password must be the same in BT master/slave. In this tutorial, the baudrate is 9600 and the password is 1234.

二、硬體材料(Materials)

  • Arduino Nano 板子 x 1
  • Arduino UNO 板子 x 1
  • Arduino Sensor Shield V5.0 感測器擴展板 x 1
  • NFU Dream Maker 所設計的 PCB from NUF Dream Maker x 1
  • RGB LED x 3
  • 電阻 Resistor 220 ohm x 3
  • HC-05 藍牙模組 x 1
  • HC-06 藍牙模組 x 1
  • 雙軸按鍵搖桿 Joystick  x 1
  • 母隊母杜邦線 Female to Female Jumper x 8

設定藍牙模組的電路與AT指令請參考 HC-05與HC-06藍牙模組補充說明(二):連接電路 與 HC-05與HC-06藍牙模組補充說明(三):使用Arduino設定AT命令 兩篇文章。

AT Commands

Please refer to "How to Set AT Command Mode for HC-05 Bluetooth Module" and "AT Command Mode of HC-05 and HC-06 Bluetooth Module" fro AT commands for HC-05/HC-06.

三、藍牙模組的設定(Bluetooth Module Configuration) HC-06的設定值 (For HC-06) 所需的指令如下(The AT Commands List):

  • AT
  • AT+PIN1234
  • AT+NAMEyour_name
  • AT+BAUD4

成功的結果會類似下圖(The below picture is the successful result) 紅色 1 OK 是 AT 檢查裝置指令回傳結果。(RED 1 OK is the return value of the AT command.) 藍色 2 OKsetPIN 是 AT+PIN1234 設定密碼指令回傳結果。(Blue 2 OKsetPIN is the return value of the AT+PIN1234 command.) 綠色 3 OKsetname 是 AT+NAMEPingLun 設定藍芽名稱指令回傳結果。(Green 3 OKsetname is the return value of the AT+NAMEPingLun command.) 紫色 4 OK9600 是 AT+BAUD4 設定傳輸速度指令回傳結果。(Purple 4 OK9600 is the return value of the AT+BAUD4 command.)

MAC address

接著可用 Bluetooth Scanner 來找出 HC-06 模組的位址(Address)。 Use Bluetooth Scanner to figure out the MAC address of HC-06.

注:上圖中的位址需轉為 98D3,31,FB5396  的格式,才能給 AT 指令用,此部分可的說明請參考 藍牙模組補充說明(四):無線連結兩個Arduino控制板一文中的藍芽裝置位址一節。 PS: the MAC address must be the 98D3,31,FB5396 for AT command.

Command Mode

HC-05的設定值(For HC-05) 要用AT指令讓HC-05主控端連上HC-06從端時,需將HC-05切換到指令模式,這需要在上電前壓住按鈕(如下圖用夾子夾住),注意 HC-05在 指令模式下的速度為 38400

Hold the reset button on the HC-05 before power on. This will enable HC-05 in command mode. A plastic peg could hold the reset button for you.

所需的指令如下:(The AT Command List)

  • AT+RMAAD 清除已配對的藍牙模組 (Clear the paired BT devices)
  • AT+ROLE=1 設定為 Master (Set the role to Master)
  • AT+BIND=98D3,31,FB5396 (Binding with the MAC address: 98D3,31,FB5396)

有回應OK才算成功。下圖的 ERROR 就是沒成功的例子,此時再下指令直到出現 OK。 Execute every command until it succeeds, got a OK response. The ERROR:(0) response say: "the command need to execute again".

Success

藍牙模組互聯連線成功影片(注意燈號閃爍的速度): The successful connection video (notice the onboard LED blinking speed).

尚未連線前:HC-06 與 HC-05 的指示燈會快速閃爍。 Before connection: the HC-06 and HC-05 onboard LED blink fast. 連線成功後:HC-06 的指示燈會恆亮;HC-05 的指示燈每兩秒快速閃爍兩次。 After connection: the HC-06 onboard will turn on, not blinking; the HC-05 will blink twice every two seconds.

Troubleshooting

If you have any problem to pair HC-05 with HC-06, please refer to this tutorial: "How to Configure HC-05 Bluetooth Module As Master and Slave Via AT Command".

四、HC-06 從端藍牙小夜燈程式 (The Code for HC-06 and Nano)

此部分的程式和 Arduino Nano 藍牙小夜燈相同。The code for Arduino Nano with HC-06 is the same with Control a Lamp from Android Phone.

五、HC-05 主控端藍牙搖桿程式(The Code for HC-05 and UNO) 搖桿的控制方式如下圖,箭頭的方向代表增加該顏色的亮度,例如紅線為X軸方向,向右會增加紅色燈的亮度,向左會減少紅色燈的亮度。黑色線為控制三種顏色的亮度。 This diagram shows the mechanism of LED lightness. For example, the red line means the RED lightness will increase from left to right(X Coordinate); the blue line mean the BLUE lightness will increase from top to bottom(Y Coordinate).

將HC-06藍牙小夜燈 與 HC-05藍牙搖桿兩程式分別燒錄好後,就可以用搖桿來控制小夜燈了。 After uploading the Nano(HC-06) and UNO(HC-05), the bluetooth lamp could be controlled remotely by a bluetooth joystick.

參考資料: [1] HC-05與HC-06藍牙模組補充說明(一) [2] HC-05與HC-06藍牙模組補充說明(二):連接電路 [3] HC-05與HC-06藍牙模組補充說明(三):使用Arduino設定AT命令 [4] 藍牙模組補充說明(四):無線連結兩個Arduino控制板 [5] Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link

Code

Gist
https://gist.github.com/pinglunliao/4836352b0a056b9c0069a0e7044183f0.js
Gist
https://gist.github.com/pinglunliao/70721a54c09d49271d369d639b119959.js

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 479,895 views
  • 49 comments
  • 284 respects

Attiny85/84 with Bluetooth

by Robin

  • 12,632 views
  • 0 comments
  • 54 respects

Otto DIY+ Arduino Bluetooth Robot Easy to 3D Print

Project tutorial by Team Otto builders

  • 48,265 views
  • 117 comments
  • 162 respects

Bluetooth Mini Car

Project showcase by Hesham

  • 8,138 views
  • 2 comments
  • 29 respects

Bluetooth Controlled Car

Project in progress by samanfern

  • 4,137 views
  • 16 comments
  • 31 respects

Bluetooth Boat in doubleA

Project showcase by joeydream

  • 2,726 views
  • 1 comment
  • 8 respects
Add projectSign up / Login