Mount HC06 BlueTooth on Arduino

Hi everyone, this is my first post on wordpress and I would like to talk you about how connect and get working a HC06 BlueTooth module with an Arduino board.

HC06 BlueTooth modules are common to find on my city’s electronic stores. So, in this topic, we are talking about on how to mount this module on the Arduino UNO board.

Before to continue, I must to say that I’m not an expert in electronic and circuits. Previous to have HC06 module working with my Arduino UNO and communicating it with my PC and my Android phone, I need to read a lot of information about circuits basics. So, I will try to make next explanations easy to understand for those non experts like me.

What you need for this tutorial:

1. One Arduino UNO board ArduinoUno_r2_front450px
2. RSF100JB-22K      One 22K Ohm resistor (check that colors order is: red, redorange and gold)
3. One 10K Ohm resistor (check that colors order is: brown, black, orange and gold).  10k-ohm-resistor-400x400
4. 1k-ohm-resistor-400x400   Two 1K Ohm resistors (check that colors order is: brown, black, red and        gold). We will using this resistors later to highlight        the         arduino          board on BlueTooth reads and writes.
5. Two Leds. We are using it to highlight the Arduino board. I recommend you different colors to make an easy difference between reads and writes. Pink5mmLED
6. bb_002 One protoboard to mount the experiment.
7. Wires to communicate the circuit components. sku_118826_2

In order to mount the circuit, this page was very useful for me: http://42bots.com/tutorials/how-to-connect-arduino-uno-to-android-phone-via-bluetooth/. The most important in this step is how to connect the circuit using the 20K Ohm and 10K Ohm resistors between HC06 RX pin and Arduino TX pin.

After you have read the link, lets go to develop the experiment step by step.

First, to safely test the BlueTooth module, mount your circuit as is shown in next picture:

ArduinoBlueToothBasicTest

After you has assembled the circuit, connect the Arduino board to your PC or Laptop using the USB cable. If all is ok, you are observing that your HC06 module leds are blinking. And, if you have your PC Bluetooth sensor on, HC06 can be discovered by your operating System. At this time, you can pair the PC and the Arduino board, but you don’t get connected. Common pairing code for BlueTooth devices is 1234, but, if is not correct for you, check your device manual to find the correct pairing code.

WindowsBluetoothDiscoveringMarked

If you can see your device, that means that you are in the right way.

Now, unplug your Arduino board to continue with the circuit assembly in a safe way. At this time we are going to put communication between the Arduino board and the HC06 module:

ArduinoBlueToothPartialAssembly_v2

In the above circuit, is very important that you use right resistors with the HC06 module, otherwise you will toast it.

The last part on assembly is put the reading and writing indicator leds:

ArduinoBlueToothFullAssemblyComments

And, here again the same circuit, clean of comments:

ArduinoBlueToothFullAssembly

In above circuit, we are lighting the green led on incoming (reading) Bluetooth data. The yellow led will light when the Arduino sends data.

Finally, the last part on Arduino side is programming it in order to have a two-way communication. This is a very important part, because, your Bluetooth module will transmit and receive data using the Arduino Serial Port (RX and TX pins). In fact, the Arduino program is a very easy routine having use of the Serial Port. You can find many examples here, here and many others.

Almost all information that I found searching on google, is focused in read and write simple integers and chars. But, for this example, a most interesting experience is be able to receive and send more complex data, encoded into strings. So, this is the right code to read and send data strings from your arduino device:

/****************************************************************
* Arduino Sketch to Read and Write full data Strings using      *
* the Serial COM Port.                                          *
*                                                               *
* Developed by Miguel Angel Gil Rios - angel.grios@gmail.com    *
****************************************************************/

const int PIN_READ_MONITOR = 2;
const int PIN_WRITE_MONITOR = 3;

void setup()
{
    pinMode (PIN_READ_MONITOR, OUTPUT);
    pinMode (PIN_WRITE_MONITOR, OUTPUT);

    Serial.begin(9600);
    digitalWrite(PIN_READ_MONITOR, LOW);
    digitalWrite(PIN_WRITE_MONITOR, LOW);
}

void loop()
{
    String data = "";
    String text = "";

    Serial.println("Arduino Device: Beginning Reading cycle...");

    while (true)
    {
        delay(1000);
        digitalWrite(PIN_WRITE_MONITOR, LOW);
        if(Serial)
        {
            data = readStringFromSerialPort();
            text = "Arduino::" + data;
            if (data.equals(""))
                digitalWrite(PIN_READ_MONITOR, LOW);
            else
            {
                digitalWrite(PIN_READ_MONITOR, HIGH);
                delay(2000);
            }
            Serial.println(text);
            digitalWrite(PIN_WRITE_MONITOR, HIGH);
        }
    }
}

/****************************************************************
* With this method, we will able to read incoming data strings  *
* instead of simple values like integers or chars               *
****************************************************************/
String readStringFromSerialPort()
{
    String data = "";

    if (Serial.available() > 0)
    {
        while (Serial.available() > 0)
            data += Serial.readString();

         return data;
     }
     else
         return String("");
}

Copy the above code and paste into your file sketch and load it into the Arduino board.

When you have programmed the Arduino board, you will see the HC06 module blinking and the write led ON all time. This is because is a very small time between writes. On nex post I will to explain how to communicate your PC or LapTop with this circuit.

Finally, I want to thank to Fritzing team because with their great software, I can to model the circuit images shown above. Thank you to this entry, for share the HC06, component for the Fritzing software.

Enjoy building your electronic experiments!

[Last Update: 2015/08/02]

All your comments and questions are welcome.

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s