Connecting Bluetooth Module HC-05/HC-06 to Arduino

How to properly connect the HC-05 module to the Arduino board, make control from a smartphone and receive data from sensors.

Connecting Bluetooth Module HC-05/HC-06 to Arduino
Connecting Bluetooth Module HC-05/HC-06 to Arduino

Very often in your projects there is a need for remote control or data transfer from your phone gadgets. One of the most popular and common methods of data exchange via Bluetooth.Today we will look at simple examples of how you can connect a Bluetooth module to Arduino and set up remote control from your phone.

Bluetooth connection diagram for Arduino:

Arduino Bluetooth
Pin 1 (TX) RXD
Pin 0 (RX) TXD

Be careful, you need to connect TX -> RXD, RX -> TXD

Now you need to write a test program code:

When uploading the sketch, it is necessary that the Bluetooth module is disconnected from the arduino microcontroller. Otherwise, the sketch will not be written, because communication with the Bluetooth module occurs on the same RX and TX port as USB.

hc-05 bluetooth module arduino

int val;
int LED = 13;

void setup()

 pinMode(LED, OUTPUT);
 digitalWrite(LED, HIGH);
void loop()
 if (Serial.available())
 val =;

 // При символе "1" включаем светодиод
 if (val == '1')
 digitalWrite(LED, HIGH);

 // При символе "0" выключаем светодиод
 if ( val == '0')
 digitalWrite(LED, LOW);


Once the sketch is written and the Bluetooth module is connected to the Arduino, you can move on to the next step.

Bluetooth connection to a smartphone

  • Turn on Bluetooth on your phone and look for new devices
  • We find in the list of disorders "HC-06" and connect to it.
  • The phone will ask for a pin code. you must enter "1234" or "0000"
  • Hooray. The device is connected.

Now you need to download the bluetooth terminal on your phone. We will look at the example of the Android platform. There are plenty of such terminals in the play store.

You can install different bluetooth terminals, as a rule they differ only in different designs, the functionality does not change from this. You can also find a terminal for ios products.

After we have installed the terminal, we launch it, select our bluetooth module HC-06 and connect to it.

It's time to try the project in action. We write the number "0" in the terminal and send. The L LED next to pin 13 on the arduino board should turn off. Now we will send the number “1” through the terminal and the LED L should light up.

An example of using data from a DHT11 temperature sensor

dht11 and bluetooth module arduino

Let's upload a sketch to the Arduino board (see below) - receiving humidity and temperature data from the DHT11 sensor and outputting data to the serial port (hardware) through the HC05 module on the Android device.

// подключение библиотеки DHT
#include "DHT.h"
// константы
#define DHTPIN 8           // пин подключения контакта DATA
#define DHTTYPE DHT11      // датчик DHT 11
#define INTERVAL_GET_DATA 2000  // интервала измерений, мс
// создание экземпляра объекта DHT
// переменная для интервала измерений
unsigned long millis_int1=0;
int pos=0;
//  подключение библиотеки SoftwareSerial.h
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // указываем пины rx и tx соответственно

void setup() {
   Serial.begin(9600);  // запуск последовательного порта
   dht.begin();         // запуск DHT
   Serial.println("start prg");

void loop() {
   if(millis()-millis_int1 >= INTERVAL_GET_DATA) {
      if(pos==0)  {
        // получение данных влажности c DHT11
        int humidity = dht.readHumidity();
        // вывод в монитор последовательного порта
      else  {
        // получение данных влажности c DHT11
        int temp = dht.readTemperature();
        // вывод в монитор последовательного порта
      // старт интервала отсчета

Let's check on the Android device to receive data sent by the Arduino via the HC05 bluetooth module. On the Android device, install the Bluetooth Terminal program. Let's establish a connection with the HC05 module in the program:

Our website is for sale! The domain and website has been running for more than 3 years, but it's time to part with it. There is no price, so I consider any offer. Contact us if you are interested in buying in the feedback form, we will discuss options, price and details for transferring the site. (script, database and everything else for the site to work).