HC-02 Bluetooth serial communication module is based on the Bluetooth V2.0 Bluetooth protocol data transmission module, high stability, ultra low power consumption, industrial grade Bluetooth data transmission module.
Users do not need to care about complex wireless communication configuration and transmission algorithms. They only need to connect to devices through TTL serial port. Powered the HC-02 slave module, and can be connected to the mobile phone for data transmission. In addition, it can be used with HC-05 or HC-06 hosts (matching code, default is 1234) to connect, can replace a traditional serial line, save wiring work. It’s very flexible.
If you need to use iphone or ipad to control your project, hc-02 4.0 ble slave module with 6pin baseboard may be a good choice.Fully compatible with ios7.0 or later.Also compatible with Android 4.3 or later.
In this lesson, we will show what is HC-02 bluetooth module and how to setup communications between an your board and a Bluetooth device running serial terminal software – in this case an Android/iOS smartphone. Please note that the Bluetooth module used in this tutorial is not compatible with iOS devices.
Please note:
Model | HC-02 | Module size | 27*13mm |
Work band | 2.4G | Air rate | 2Mbps |
Communication interface | UART3.3V TTL | Antenna interface | built-in PCB antenna |
Working voltage | 3.0~3.6V | Communication current | 30mA |
Baud rate | 1200~115200bps | Receiver sensitivity | [email protected] |
Communication level | 3.3V | Working humidity | 10%~90% |
The transmitting power | 6dBm (maximum) | Storage temperature | -40 C ~+85 C |
Reference distance | 10m | Working temperatur | -25 C ~75 C |
Pin Number | Pin Name | Description |
1 | Enable / Key | This pin is used to toggle between Data Mode (set low) and AT command mode (set high). By default it is in Data mode |
2 | Vcc | Powers the module. Connect to +5V/+3.3V Supply voltage |
3 | Ground | Ground pin of module, connect to system ground. |
4 | TX – Transmitter | Transmits Serial Data. Everything received via Bluetooth will be given out by this pin as serial data. |
5 | RX – Receiver | Receive Serial Data. Every serial data given to this pin will be broadcasted via Bluetooth |
6 | State | The state pin is connected to on board LED, it can be used as a feedback to check if Bluetooth is working properly. |
7 | LED | Indicates the status of Module
|
More info about the HC-02 BLE module please check this link.
In this example, we will show how to use an smart phone to control the board on-board LED via bluetooth protocol.
Osoyoo Basic board | HC-02 |
3.3V | VCC |
GND | GND |
D10/Software RX | TXD |
D11/Software TX | RXD |
Overhere we use the Software serial port of the board, connect them as below fritzing:
After above operations are completed, connect the board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your board.
#include <SoftwareSerial.h>// import the serial library SoftwareSerial mySerial(10, 11); // RX, TX int ledpin=13; // led on D13 will show blink on / off int BluetoothData; // the data given from Computer void setup() { Serial.begin(4800); Serial.println("Type AT commands!"); // put your setup code here, to run once: mySerial.begin(9600); Serial.println("Bluetooth On please press 1 or 0 blink LED .."); pinMode(ledpin,OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (mySerial.available()) { BluetoothData=mySerial.read(); if(BluetoothData=='1') { // if number 1 pressed .... digitalWrite(ledpin,1); Serial.println("LED On D13 ON ! "); } if (BluetoothData=='0') { // if number 0 pressed .... digitalWrite(ledpin,0); Serial.println("LED On D13 Off ! "); } } delay(100);// prepare for next data ... }
Open the App and it will search for this Bluetooth module.
When the connection will be prompted for pairing, input 1234 to the column, if not, you can try 0000,
As above photo, the green box is lit to indicate the connection is successful. At the same time, the LED light of Bluetooth module has become bright all the time.
Then click the Monitoring button in the lower right, and enter the following interface:
Just input your command and press the Send button here.
Download the Bluetooth Terminal app from the APP Store.
After the above operation is completed, open the Bluetooth Terminal, and you will see the bluetooth list as below:
Choose “HC-02”, then click the connect button.
In this step, click “Select Characteristic”, you will see a scroll bar below the button, select entries with the beginning of “49535343-8841-43F4-A8D4” for your HC-02 BLE module.
Choose “ASCII”, and you can enter your command here, just press the “Send” button to send your command to the board via bluetooth.
A few seconds after the upload finishes, open the Amarino app and connect your andorid samart phone with the HC-02 module, simply type “1” or “0” to above corresponding APP column, you will see the on-board LED turn on/off,
At the same time, the output of the Serial Monitor is as below:
Note: you must choose the correct Baudrate for your serial monitor, be careful!!!
DownLoad Url osoyoo.com