JYMCU Bluetooth Units, HC-05 and HC-06 Part 1

 
Part 2 shows setting up the Master HC05 and can be seen here.

It is important to note that although the HC05 and HC06 can be powered from 5 volts the control pins and T/Rx  pins must be 3 volts. Use a logic level converter, an example is shown later. I power the device from the 3 volt output on the logic level converter.

A Piconet is a collection of devices connected via Bluetooth technology in an ad hoc fashion. A piconet starts with two connected devices, such as a portable PC and a mobile phone. All Bluetooth devices are peer units and have identical implementations. However, when establishing a piconet, one unit will act as a master for synchonization purposes, and the other unit will be slave for the duration of the piconet connection.
The JYMCU Bluetooth units come in two varieties, one set permanently as a Slave, the HC-06  and the other that can either be a Slave or a Master, the HC-05. The two units look identical, but the Master unit is usually more expensive. Normally if you are using Bluetooth to connect to an Android device, or PC, then a Slave unit is all you need. If you want to communicate between two Arduino’s then one Adruino can use a Slave unit, but the second Aduino will have to use a Master unit. Up to eight Bluetooth units can exist in a Piconet.

The JYMC can be powered from 5volts but a Logic Level Converter must be used on the Tx/Rx pins. The Bluetooth acts as a Serial Communication device and to ensure the Arduino’s Tx and Rx (pins 0 and 1) are free to upload Sketches. I use SoftwareSerial. To test Bluetooth out I have installed BlueTerm on my Android Phone, the phone then acts as a Master unit and the Arduino acts as a slave. Data can be entered into the Serial Monitor on the Arduino and it will appear on the mobile phone, and the mobile phone or android device can switch the onboard LED on the Arduino ON or OFF. 

Upload the following sketch to an Arduino and connect Gnd and Vcc on the JYMC to Gnd and 5volts on the Arduino. Use a Logic Level Shifter (you can purchase one fromHobbytronics  here for £3. The advantage of this board is that it has a 3.3 volt 250 mA regulator) to connect Tx on the Bluetooth to the SoftwareSerial Rx pin and Rx on the Bluetooth to the SoftwareSerial Tx pin.


/*****************************************************
Simple Send/Recieve test SoftwareSerial for Bluetooth HC06
Sends data from Serial Monitor and will turn LED on pin 13
ON if the character 1 is sent
OFF if the character 0 is sent
ingnores all other data

Vcc to either 3 volts or 5 volts
Gnd to Arduino Gnd
Tx to Arduino pin 10
Rx to Arduino pin 11

Unless this has been altered the bluetooth unit will be found as 'Linvor'

***************************************************************/

#include <SoftwareSerial.h>
#define onboardLed 13

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
mySerial.begin(9600); // SoftwareSerial "com port" data rate. JY-MCU v1.05 defaults to 9600.
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, LOW); // turn off onboard LED
}

void loop()
{
// Read device output if available.
if (mySerial.available()) {
while(mySerial.available()) { // While there is more to be read, keep reading.
unsigned char charreceived = mySerial.read();
Serial.println(charreceived); // show data from bluetooth
switch(charreceived){
case 49:
digitalWrite(onboardLed, HIGH);
Serial.println("Arduino Led On");
break;
case 48:
digitalWrite(onboardLed, LOW);
Serial.println("Arduino Led Off");
break;
default:
break;
}

}
}
// Read user input if available.
if (Serial.available()){
delay(10); // The DELAY!
mySerial.write(Serial.read());
}
}// END loop()


Start the Arduino and switch to the Serial Monitor, start BlueTerm on your Mobile Phone and go to Connect Devices. Click on the Scan for Devices button, you should find the HC05 as Linvor. The red LED on the Bluetooth unit will stop flashing and light continuously. Type something into the input box on the Serial Monitor ( set to 9600 baud and send CR/LF selected) and it should appear on your mobile phone. Now type the number 1 in the BlueTerm terminal screen, the onboard LED will light, type 0 and the LED will go out. All other characters will be ignored.

If nothing seems to be working check that the Tx and Rx pins from the Bluetooth are connected correctly. If you can connect to the HC05 with your mobile phone running BlueTerm then it must be a connection problem. These units run at 9600 baud.

  

This is the basic circuit, when mounted on a baseboard additional circuitry is added such as a 3 volt regulator and a USB interface.

AT Commands:

When the HC-06 is first supplied with power the LED blinks and AT commands can be sent to it. Once the HC-06 connects to a Master Bluetooth unit it switches to communication mode. The HC 06 has a limited number of AT commands and they are described here. These commands must be sent within 1 second and should not have a CR/LF added.


Default settings of the HC-06:
Slave
9600, N, 8, 1
Name linvor
Pincode 1234

Command test:
Sent: AT
Receive: OK

Change baud rate:
Sent: AT+BAUD#
Receive: OKbaud
1: 1200
2: 2400
3: 4800
4: 9600
5: 19200
6: 38400
7: 57600
8: 115200

Example:

Sent: AT+BAUD1
Receive: OK1200

Change device name:

Sent: AT+NAMEname
Receive: OKname

Example:

Sent: AT+NAMEblue
Receive: OKblue

Change pin code:

Sent: AT+PINxxxx
Receive: OKsetpin

Example:

Sent: AT+PIN9999
Receive: OKsetpin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s