| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Bluetooth Special

Page history last edited by David S 8 years, 7 months ago

Bluetooth Special

 

Bluetooth is a wireless protocol for sending data over distances up to about 10 meters (unobstructed) in the 2.4 GHz radio band.

 

1. The HC-05 Breakout Board

 

We’re using an inexpensive HC-05 type breakout board to send serial data between a PC and an Arduino. You could also send serial data between 2 Arduinos, although you’d need 2 HC-05 boards for that. The specifications for the board are here. 

 

   

 

The Bluetooth protocol has gone through several versions, each with different data rates and power needs. Our device implements the “V2.0+EDR” version.

 

2. Wire the HC-05

 

Connect the HC-05 to your Arduino as described below. Pins not listed should be left unconnected.

 

HC-05  
Arduino
RXD --> (1:2) voltage divider to Pin 11 & GND*
TXD --> Pin 10
3.3 --> 3V (or 3.3V power rail)
GND --> GND

 

*The 1:2 voltage divider should run from RXD through a resistor (such as 1K) to Arduino Pin 11. RXD should also run through a resistor (such as 2K) to GND. Any resistors with a 1:2 ratio above 1K will do. We are using Pin 11 and Pin 10 to receive and send data. Ask the TAs for a reference board if you feel confused. 

 

 

 

When you plug your Arduino into USB, the red LED on your HC-05 should flash quickly (about 3Hz).

 

3. Pair your PC with the HC-05

 

We’ve given each of the HC-05 boards a unique name, in the form HC-05-##. Your 2-digit number is written on the electrostatic bag that the HC-05 came in.

 

To pair on OSX, open the Bluetooth preference pane, enable Bluetooth, and look for the device named HC-05-##. When you see it, click the Pair button. If pairing fails, click on Options to change the code to 1234.

 

To pair on Windows, open the Control Panel, select Add a Device, and follow the instructions to add and connect to a Bluetooth device. Look for the device named HC-05-## and enter the code 1234.

 

Once successfully paired, the red LED on the HC-05 should flash slowly (about 0.5Hz).

 

4. Install & Setup CoolTerm

 

To communicate with the HC-05 from your PC, we’ll use a serial terminal program. We recommend CoolTerm, which works on both Windows and OSX. You can download it here.

 

Open CoolTerm and then click the Options button on the top menu bar.

 

 

On the Serial Port menu pane that appears is a Port pulldown list. Select HC-05-{number}-DevB.

 

 

You can also increase the Baudrate from 9600 to 115200 (the fastest that the Arduino allows), although for the example sketch, you won’t notice a difference. Then click OK. In the example we use, we 

 

5. Flash the BTArduino Sketch

 

This is (just about) the last step! Download the BTArduino sketch from here, then open the file and look at how it works.

 

The sketch uses a software serial port to communicate over pins 10 and 11 (set as software RX and TX). When the connection is established, you should be able to see "Bluetooth Ready" shown on your CoolTerm window. When you press 0, the led at pin 13 would be turned off. If you press  

 

When you’re ready, upload the sketch.

 

6. Communicate Wirelessly

 

Return to the CoolTerm window and click the Connect button on the top menubar. The interface should indicate (by little green lights) that it’s connected to your HC-05 board.

 

 

Now you can type a 0, 1 or 2 into the window, and the Arduino’s LED should obey your commands.

 

Hey! That doesn’t look any different than Lab #2. We know, but you are communicating wirelessly. Want proof? Pair your PC with a classmate’s HC-05 instead (and remember to select the new port name in CoolTerm and re-connect).

 

Alternatively, you can power your Arduino from a battery (either a 9V or 5V step-up) and disconnect the USB cable. To do so, connect the battery’s positive lead to the Arduino’s Vin pin (which handles up to 20V), and connect the grounds.

 


 

7. Using Bluetooth in the Future

 

a. For Your MP3 Player…

You can now use this same routine to send play/pause, forward/backward and volume commands to your MP3 players. Just write a function for each command you want (you’ll see how in Lab #6) and call that instead of lighting the LED.

 

b. To Bypass CoolTerm…

We’ve written a simple PC control interface using the Processing platform instead of CoolTerm. Processing is a programming environment (and community, much like Arduino) for prototyping graphical interfaces. In the same way that Arduino is mostly C++, Processing is mostly Java.

 

You can download Processing here, and the control interface here. Unzip and open BTProcessing, then click the run button in the top left corner. You might receive an error, but that's expected at this point. Look for the list of available ports at the bottom of the interface window. Find the port that's connected to your HC-05 and enter its index instead of 0 for portNames[0] on line 27.

 

Hover your mouse over the black rectangle to light the LED at a low PWM, and click on the (now) green rectangle to light the LED at a high PWM.

 

c. To Change HC-05 Settings…

You can change many of the settings for your HC-05, including its name, security (pairing) code and communication speed. To do so, disconnect power from your board (typically through USB), connect the following pins, then re-power your board.

 

HC-05  
Arduino
KEY --> 3V

 

The red LED on the HC-05 should flash slowly (about 0.5Hz). Next, download our Arduino sketch here, then compile and upload the program.

 

This sketch allows you to send AT commands (as they're called) to the HC-05. Just open the Arduino's serial monitor, set it to "Both NL & CR" at the bottom right, type in a command, and press return the return key. If your command is accepted, you'll see OK as a response in the serial monitor.

 

To make sure it's working, type AT, then the return key, and the response should be OK. Here are a few sample settings:

 

  Check Current Change to New Value
Name AT+NAME?  AT+NAME={new name} (without the braces) i.e - AT+NAME=BLUETOOTH
Security (Pairing) Code  AT+PSWD?  AT+PSWD={new code} 
Communication Speed  AT+UART?  AT+UART={new speed, 1, 0) 

 

For AT+UART setting shown above, the 1 is to set a stop bit and the 0 is to set the parity.

 

A detailed datasheet of all of the AT commands is available here.

Comments (0)

You don't have permission to comment on this page.