I have been given HC-06 Bluetooth module and a stepper motor from the lecturer to explore. Both of them are extremely interesting and fun to play with, but I decided to write about HC-06 since this module allows me to make much more interactive projects. Now let me explain briefly what it is.
HC-06 is a very popular and inexpensive module that uses serial communication via Bluetooth. It allows us to wirelessly communicate between Arduino and any Bluetooth device, such as laptop, Android or iOS device. HC-06 can receive and send data to the device that is paired and connected. However, HC-06 can only accept a connection from outside, it cannot initiate one. It means it can only work as a SLAVE.
MASTER and SLAVE
The device that is able to initiate the connection is called MASTER. There are Bluetooth modules that can be both MASTER and SLAVE, for example HC-05. Those properties the given by the manufacturer and they cannot be changed via AT commands.
AT command mode allows you to interrogate the Bluetooth module and to change some of the settings:
- the name
- the baud rate
- operation in slave mode or master mode. (HC-05 ONLY)
It is not needed now, but is you want to read more about AT mode and the commands, see further reading section at the bottom of the site.
HC-06 can be supplied by a range of 3.6 – 6V. That means it can be connected straight to the Arduino. However, the input (RXD) and output (TXD) pins operate on 3.3V. For the output it is fine to connect it straight to the Arduino since the microcontroller will recognize 3.3V as HIGH signal. But Arduino outputs the signal of 5V, therefore it is essential to put a voltage regulator or a 1kΩ resistor to ensure that HC-06 will not be damaged.
I decided to share with you this simple project of wirelessly controlled LED lamp. It uses HC-06 to receive data from the Android device, serving as a wireless ON/OFF switch. let’s see the scheme of the circuit and let me explain it briefly:
It is a very simple setup. D13 goes to the LED with 500Ω resistor, it will be our lamp. D11 goes into the RXD (the input of the HC-06) not that I used a 1kΩ and a 2kΩ resistor to lower the voltage. D10 goes into the TXD (output), GND to GND, and 5V to power up the HC-06.
Even though physical serial ports of the Arduino are on the D0 and D1 pin, I decided to use a SoftwareSerial library to create a digital serial port for my HC-06. Otherwise, when using the original ports, I would not be able to upload my code via USB, as HC-06 would “steal” my serial connection.
As you can see, I set up the device to read the input from my Android phone. How do I do that? I just simply need any serial monitor app from the Goggle Play. You can find the one I’m using here. In order to use the app, I need first to pair my phone with the HC-06, I should be able to find it in the list of Bluetooth devices. The password to pair is commonly 1234. After that I just need to select my device in the serial monitor app.
A video of working circuit is here:
Next time I will try to combine HC-06, sound sensor and a servo in a group project with Thomas!
References and further reading: