Connecting bluetooth hc 05 to arduino. Arduino lessons: controlling devices from a smartphone for dummies. Connect from a smartphone using Bluetooth Terminal

Bluetooth whistle for computer: http://ali.pub/2jfj3y

First, let's figure out what bluetooth is.

Bluetooth(from the English words blue - blue and tooth - tooth; pronounced /bluːtuːθ/), bluetooth- wireless personal area network manufacturing specification ( Wireless personal area network, WPAN). Bluetooth enables the exchange of information between devices such as personal computers(desktop, pocket, laptops), Cell phones, printers, digital cameras, mice, keyboards, joysticks, headphones, headsets on a reliable, free, universally available radio frequency for short-range communication. Bluetooth allows these devices to communicate when they are within a radius of up to 10 m from each other (range varies greatly depending on obstacles and interference), even in different rooms.

Now knowing that bluetooth is used to build networks and exchange data between devices, we will use it to connect a CNC (CNC) machine and a computer or a phone or a tablet and a laptop.

Since I use the grbl firmware on the arduino platform to control the CNC, we will connect a bluetooth module suitable for arduino to the machine, namely the HC-06 bluetooth module.

Before connecting the Bluetooth module to the Arduino, you need to make sure that the Bluetooth module and Arduino operate at the same speed of the COM port.

If you are using grbl 0.8 firmware, then you do not need to change anything, but if grbl 0.9 and higher, then the speed of the Arduino COM port will become 115200, and the default speed on the module is 9600.

So we need to change the port speed on the Bluetooth module itself.

To configure Bluetooth modules, there are special AT commands, with which we can set the necessary module parameters.

Using AT commands we can change the speed of the COM port or change the name Bluetooth devices or find out or change the PIN code for pairing.

In order to connect the Bluetooth module to the computer to enter AT commands, we will need an FTDI programmer (link to it at the beginning of the article). I think the connection diagram is unnecessary here. You need to connect gnd to gnd, 5v to 5v, rx to tx and tx to rx.

After connecting, we will need the HMComAssistant program to enter AT commands and program our module. Download: https://yadi.sk/d/eVzPmnh63Wab5R

Well, here I will give some AT commands for changing the settings of the Bluetooth module:

AT command Module response A comment
AT OK Used to test communications, as a rule, before performing any operations, this command is first used to test communications.
AT+BAUD1 OK or OK1200 Sets the data transfer rate to 1200 baud
AT+BAUD2 OK or OK2400 Sets the baud rate to 2400 baud
AT+BAUD3 OK or OK4800 Sets the baud rate to 4800 baud
AT+BAUD4 OK or OK9600 Sets the baud rate to 9600 baud
AT+BAUD5 OK or OK19200 Sets the baud rate to 19200 baud
AT+BAUD6 OK or OK38400 Sets the baud rate to 38400 baud
AT+BAUD7 OK or OK57600 Sets the baud rate to 57600 baud
AT+BAUD8 OK or OK115200 Sets the baud rate to 115200 baud
AT+BAUD9 OK or OK230400 Sets the baud rate to 230400 baud
AT+BAUDA OK or OK460800 Sets the baud rate to 460800 baud
AT+BAUDB OK or OK921600 Sets the baud rate to 921600 baud
AT+BAUDC OK or OK1382400 Sets the baud rate to 1382400 baud
AT+NAME +NAME=test Returns the current module name
AT+NAMEiarduino_BLU +NAME=test OK Sets a new module name “test“
AT+PIN +PIN=000000 Returns the current password, in this case the password is “000000”
AT+PIN123456 +PIN=123456 OK Set a new password, in this case the password is “123456”
AT+VERSION +VERSION=Firmware V3.0.6,Bluetooth V4.0 LE Returns the firmware version, in this case the password is “Firmware V3.0.6,Bluetooth V4.0 LE”
AT+RESET +RESET OK
AT+HELP ——– Returns a list of all available AT commands

After changing the speed of the com port and setting the PIN code for pairing. (the default pin code for pairing is “1234”, let’s connect the module to the Arduino.

And since I use CNC shield v 3.0. I’ll also provide a connection diagram for it.

I will not create my own diagram, but will take it from one article. May its creator forgive me.

The diagram is certainly not very smooth, but in my opinion it is quite understandable.

So why are resistors used in a circuit? Arduino has 5-volt logic, which means that the Arduino sends a voltage of 5V to all its outputs. But the module says LEVEL 3.3v, which means that Bluetooth requires 3.3V, but not 5V. Therefore, resistors are connected to lower the voltage and prevent failure of the Bluetooth module.

But I decided to use it directly without resistors, let's see how long the module will last, we'll do some kind of crash test.

To control the CNC (CNC) machine from a phone or tablet, I used the “Grbl controller” program, it is free and quite multifunctional. In the video below I briefly showed how the machine is controlled from this program.

But if you connect from a computer, then there is a nuance; when pairing the connection with the module, two new COM port. For me it is COM6 and COM7. So one of them is used to send data, and the other is used to receive. Therefore, there is no need to be scared and just try to connect to one; if nothing happens, then connect to another.

But if something is not clear, I showed it clearly in the video:

Very often in your projects there is a need for remote control or data transfer from your telephone gadgets.

One of the most popular and widespread methods of data exchange via Bluetooth .

Today we will look simple examples how to connect bluetooth module to Arduino and configure remote control from the phone.

We will need:

  • Set of MALE-MAMA wires
  • HC-06 Bluetooth

Connect Bluetooth The module to the Arduino microcontroller is most convenient using MALE-MAMALE wiring.

Arduino Bluetooth
Pin 1 (TX) RXD
Pin 0 (RX) TXD
GND GND
5V VCC

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

Now you need to write down the test code of the program:

When loading the sketch, it is necessary that the Bluetooth module is disconnected from the arduino microcontroller. Otherwise, the sketch will not be recorded because the connection with Bluetooth The module communicates via the same RX and TX ports as USB.

Int val; int LED = 13; void setup() ( Serial.begin(9600); pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); ) void loop() ( if (Serial.available()) ( val = Serial.read(); / / When the character is "1", turn on the LED if (val == "1") ( digitalWrite(LED, HIGH); ) // When the character is "0", turn off the LED if (val == "0") ( digitalWrite(LED, LOW ); ) ) )

After the sketch is recorded and Bluetooth The module is connected to the Arduino, you can move on to the next step.

Connecting Bluetooth to your phone

It is advisable to use not USB as a power source for arduino, but an external 9 V power supply.

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

Now you need to download the bluetooth terminal to your phone. We will look at the example of the Android platform.



You can install different bluetooth terminals, as a rule they differ only in different designs, the functionality does not change. 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. LED L which is located on the arduino board next to pin 13 should go out. Now we send the number “1” through the terminal and the L LED should light up.

Demonstration of work:


Homework:

  • Change the sketch so that the LED lights up and goes out using the same command, for example “G”.
  • Complete the sketch and teach it to convert text data coming via bluetooth into digital data and implement a dimer, light an LED using PWM, at a given brightness from 0 to 254 coming via bluetooth.

Today we will get acquainted with an inexpensive module for wireless data transmission via Bluetooth.

Bluetooth is an industry specification for wireless personal area networks that enables the wireless transmission of data between many devices.

Our module is called HC-05. This is one of the representatives of the line of similar modules HC-03 - HC-09.

These modules allow you to transfer data wirelessly, without thinking about how the Bluetooth protocol generally works, about its fields and other subtleties. These modules are correct settings provide data transfer in such a way that the programmer writing the code writes the algorithm as if he were working with a wired UART interface. Therefore, writing code becomes as convenient as possible and that is why this line of modules has gained such enormous popularity among novice programmers and not only.

So you and I, let’s also not lag behind them and take a little break from network protocols and study such a module. There were also a lot of personal requests, as well as in public chats, so that I would not bypass such modules and write any lessons using them.

The modules have the following main characteristics:

  • Bluetooth chip – BC417143 production CSR company,
  • data transfer protocol - Bluetooth 2.0+EDR,
  • class 2, which corresponds to data transmission within a radius of up to 10 m,
  • Serial Port Profile support ( SPP), which ensures compatibility with all devices that support this profile,
  • non-volatile flash memory with a capacity of 8 MB,
  • radio channel with a frequency of 2.4 - 2.4835 MHz,
  • USB Host 1.1/2.0 interface,
  • UART interface with adjustable baud rate.

Also, along with these characteristics, it is worth noting that the module has a lot of legs on board, which allows it to be used in a wider range. Let's look at the module pinout diagram

We see here the GPIO, SPI, USB, PCM pins.

True, for now we will only work with the USART interface, with the help of which we will not only transfer some useful data, but also configure our module.

We will do this, firstly, because our modules will be of the same type (I have as many as 4 of them!), in which the HC-05 module is soldered onto another board, on which only 6 contacts are routed outward. This is how I have them all (top view and bottom view)

The purpose of the legs is indicated on the bottom of the board; we will figure them out when we connect the module.

Secondly, we will not work with the rest of the numerous contacts because not every firmware allows you to do this.

In general, the choice fell on the HC-05 also because this module Perfectly configurable for both master and slave operation.

The module is configured for further work with data using AT commands. I think we are all more or less familiar with what these commands are; we got to know them a little when we worked with the Wi-Fi module. Of course, these commands are different for all devices and therefore I will attach a document with a complete list of commands at the bottom of the page. It’s also easy to find resources on the Internet where the description of these commands is translated into Russian, and there are even some examples of their use. We will not engage in complete translation of commands here; we will study only those commands that we will have to use. For now, their list will not be so wide, but later we will return to these modules, I hope, more than once, and then we will expand our horizons in knowledge of this module. In the meantime, we will only give a short tour of the module. Of course, we will try it at work, not without it.

For now, let's connect our module to the TTL-USB adapter, which in turn we will connect to the PC.

We will connect according to the following diagram

TTL-USB adapter Module HC-05

VCC VCC

GND GND

TXD RXD

RXD TXD

In practice it will look something like this

Let’s connect the adapter to the computer; I won’t tell you how to work with adapters of this type, we already work with them all the time. Let's launch a terminal program, I will use the CoolTerm program, since it has more flexible settings for transmitting data from the keyboard, and to enter commands, we need each line during transmission to end with a line feed and carriage return code.

Let's go to the program settings and first configure the port

This speed of 38400 was chosen because the module operates at exactly this speed when receiving AT commands.

Now select the item on the left Receive and switch one button there and turn on the other

The first button is for ending transmitted commands with line feed and carriage return characters, and the second is so that we can also see our entered commands after entering them in the receiving terminal window.

Let's save the settings and try to connect. If everything is successful, then we disconnect, since now our module is in data transfer mode, and if it has not yet been configured, then most likely we do not even know its address or its settings. About finding the module in this mode This is indicated by rapid blinking of the blue LED. Therefore, we need to somehow put the module into the state of transmitting AT commands.

To do this, we will now disconnect the adapter from the USB port and connect the wire to the leg of the HC-05 module KEY. For some it may have a different name, but I don’t think you can confuse it. Let's connect the wire like this and like this

Let's connect this wire to the power positive (with the VCC leg)

And, without releasing the contact, connect the adapter to USB port computer and after a while (in a second or two) we disconnect our KEY contact from the VCC contact by removing the wire. The module will have to switch to the mode of receiving AT commands, which will be indicated by a very slow blinking speed of the LED.

Let's go to the terminal program, connect to the port and try to send a command AT, to which the module must answer us "OK"

The module responded, which means everything is correct.

In order not to get confused with the settings that were once made by someone, let’s collect all the settings by entering the command “ AT+ORGL". The settings will need to reset to the following parameters:

  • Device type: 0
  • Inquire code: 0x009e8b33
  • Module work mode: Slave Mode
  • Connection mode: Connect to the Bluetooth device specified
  • Serial parameter: Baud rate: 38400 bits/s; Stop bit: 1 bit; Parity bit: None.
  • Passkey: “1234”
  • Device name: “H-C-2010-06-01”

Only the settings will not be applied immediately. You need to reload the module. It is convenient to do this by entering the command " AT+RESET“, in response to which the module will reboot and go back to data transfer mode and will not be able to receive commands for now. In order for it to accept them, we will perform the same actions as above so that the module again switches to the mode of receiving AT commands. There is another way, but we won’t use it for now.

Let's now check some parameters of our module.

To find out the firmware version, enter the command “ AT+VERSION?", to which the module will have to respond something like this

If the firmware is not lower than this version, then we can be sure that this module with such firmware is capable of working in master mode.

Find out the device address using the command “ AT+ADDR?«

We will use this address to identify our device on the master device. We will take the most ordinary smartphone as the master device, but that will come a little later. We still need to play well with the teams.

Let's also request the device name using the command " AT+NAME?“, to which many modules, including mine, respond only if there is a high level on the KEY leg, that is, when the wire is connected. Let's do that

Let's try to change this name as well, since it is not very convenient; to do this, enter the command “AT+NAME: Desired_name”. This command can be entered without a high level on the KEY pin

Let's check that the name has changed, just don't forget about the high level on the KEY leg

The name is well applied.

Let's check the password with the command " AT+ PSWD?«

In the same way as the name, you can change the password.

Now we find out the type of device (slave or master) using the command “ AT+ ROLE?«

0 means slave. The type can also be changed at any time. But we don’t need this for now, since we will work with the device as a slave.

Reset the paired devices with the command “ AT+RMAAD«

Now let's find out the USART interface settings with the command " AT+ UART?«

These settings mean: 38400 kbps, 1 stop bit and no parity.

This table contains possible options USART settings

Let's change, for example, the transmission speed with the command " AT+UART=115200,0,0«

Only these settings will take effect after the module is rebooted and will be relevant only for the data transmission mode; for the mode of transmitting AT commands to the module, the same settings will remain at a speed of 38400.

Let's reload the module with the command " AT+RESET“, after which the module will switch to data transfer mode.

Let's configure the port in the terminal program to given speed and connect with him

Let's try to enter a command, to which our module will not respond, since the mode is not the same

But let's not despair. It turns out that in order to send commands to the module, it is not necessary to put it in this mode. You can enable support for transmitting AT commands in data mode. For a short time (less than a second is enough), we touch the wire that is connected to the KEY contact of the positive bus of the module and the module will switch to AT-command support mode. True, we cannot determine this by the nature of the LED blinking; it will blink just as quickly. Also, in the we command support mode, the master device will not be able to connect to us. But nevertheless, we do not need to constantly remove the wire from USB connector and reconfigure the port in the terminal program. This is already good. Let's perform this action and make sure that the module will also accept commands, as in the command receiving mode

To remove this support and for the module to be able to connect, just reboot it with the command “ AT+RESET". Let's do that

Great! We already know something. Basically, we have configured the module to transmit data in master mode.

Now the smartphone that we have today will act as a master device. Anyone with an Android will do, as long as they have some kind of terminal program for Bluetooth. I installed this one. I found it comfortable

Firstly, it is free, does not require creating a connection in advance, and also has several buttons with strings we have saved in advance.

Let's download and install the program and run it. Press the SCAN button and our module should appear in the list of found devices

Let's choose this device and we will be taken to the pair creation dialog, in which you will need to enter a password (we have “1234”) and agree by clicking the “OK” button

Ever thought about managing any electronic devices using a smartphone? Agree, it would be very cool to control a robot or any other devices from your smartphone. We offer a simple lesson for beginners and dummies on how to control a smartphone using Arduino via Bluetooth. If after this lesson you want to get to know Arduino better, you can find books about it.

Step 1. What we need

Devices

Module - Bluetooth Module HC 05/06
Board - Arduino
Light Emitting Diode (LED)
Resistor - 220Ω
Android device

Software

Arduino IDE
Android Studio (actually not necessary, because you will find the Android application below)

Step 2. How it works

Usually we do this step at the end, but so that you understand what we have to achieve, look at the result at this intermediate step. We have also published a step-by-step video tutorial below.

Step 3. We begin to assemble the circuit

The circuit in our tutorial is so simple and small that we only need to make a few connections:

Arduino Pins___________Bluetooth Module Pins
RX (Pin 0)___________________________TX
TX (Pin 1)___________________________RX
5V__________________________VCC
GND_______________________GND

Connect the negative of the LED to GND on the Arduino, and the positive to pin 13 through a resistance of 220 Ohm - 1 kOhm. In general, in our figure below everything is quite clear.

Do not connect RX to RX and TX to TX Bluetooth outputs to Arduino outputs, you will not receive any data, here TX means transmit, RX means receive.

Step 4: Uploading the Program to Arduino

Now we need to write a program and upload it to our Arduino. If you don’t know how to do this yet, download books. The code below is exactly what we need to load into the Arduino.

/* Bluetooh Basic: LED ON OFF * Coder - Mayoogh Girish * Website - http://bit.do/Avishkar * Download the App: https://github.com/Mayoogh/Arduino-Bluetooth-Basic * This program lets you to control a LED on pin 13 of arduino using a bluetooth module */ char data = 0; //Variable for storing received data void setup() ( Serial.begin(9600); //Sets the baud for serial data transmission pinMode(13, OUTPUT); //Sets digital pin 13 as output pin ) void loop() ( if(Serial.available() > 0) // Send data only when you receive data: ( data = Serial.read(); //Read the incoming data and store it into variable data Serial.print(data); // Print Value inside data in Serial monitor Serial.print("\n"); //New line if(data == "1") // Checks whether value of data is equal to 1 digitalWrite(13, HIGH); // If value is 1 then LED turns ON else if(data == "0") // Checks whether value of data is equal to 0 digitalWrite(13, LOW); //If value is 0 then LED turns OFF ) )

Step 5. How the process works

The HC 05/06 module operates via a serial communication channel. The Android app sends data sequentially to the Bluetooth module when you press a specific key. The Bluetooth on the other end receives the data and sends it to the Arduino via the Bluetooth module's TX connection (Arduino RX connection).

The code loaded into the Arduino checks the received data and compares it. If a "1" is received, the LED turns on and turns off when a "0" is received. Open the serial port monitor and observe the received data.

Step 6. Application for Android devices

In this tutorial we will not touch on creating applications for Android devices. You can download the application on GitHub.

How to use the application?

After we have connected via Bluetooth, we need to download and install an application that, using a smartphone :) will control our LED from a distance. You can download the application for free on Amazon.com. We connect the smartphone to the Bluetooth module HC 05/06:

  1. Turn on the HC 05/0 module
  2. Looking for a device
  3. We connect to HC 05/06 by entering the default password “1234” or “0000” (four zeros).

After that we install the application on our smartphone. Let's open it. Select a device - select the Bluetooth module from the list (HC 05/06). After successful connection, press the ON button to turn on the LED and the OFF button to turn off the LED. Then you can click the “Disconnect” button to disconnect from the Bluetooth module.

This was a guide for dummies and beginners on how to connect a Bluetooth module with Arduino. This project can be improved and taken to a higher level for, for example, home automation through smartphone control, controlled robot and much more.

Review of Bluetooth module HC-05

The Arduino controller does not support wireless communication, and often this is simply necessary. For example, remote control robot on Arduino, sending data from the weather station to Arudino to the Internet or to home server, communication of several devices with each other. Here, to help device developers, there are many external modules for organizing various technologies. wireless communication: WiFi modules, GSM/GPRS, IR, Bluetooth, radio modules for operation in various frequency ranges.

Bluetooth technology is used to transfer data between two devices that are in close proximity to each other, without requiring direct line of sight. Bluetooth technology provides good resistance to broadband interference, allowing multiple devices in the same location to communicate simultaneously without interfering with each other. Very wide this technology used in phones, tablets, laptops.

One of best solutions to organize two-way Bluetooth communication between your Arduino device and a tablet, laptop or other Bluetooth device - Bluetooth module HC-05, which can work as both a master (search for Bluetooth devices and initiate communication) and a slave (slave device) ).

Technical characteristics of the HC05 module

  • Bluetooth chip: HC-05(BC417143)
  • Radio frequency range: 2.4 - 2.48 GHz
  • Transmit power: 0.25–2.5 mW
  • Sensitivity: –80 dBm
  • Supply voltage: 3.3–5 V
  • Current consumption: 50 mA
  • Range: up to 10 meters
  • Interface: serial port
  • Modes: master, slave
  • Storage temperature: –40…85 °C
  • Operating temperature range: –25…75 °C
  • Dimensions: 27 x 13 x 2.2 mm

Connection

The sensor has 6 2.54 mm standard pins:

  • VCC - (power supply 3.6 – 6 V);
  • GND - (ground).
  • TXD, RXD - UART interface;
  • STATE - status indicator;
  • KEY - contact for entering programming mode.

The module is configured in programming mode by sending AT commands via serial port. To enter the programming mode, you must apply a high level signal to the KEY contact. On some modules there is no KEY pin, and instead there is an EN pin:

  • EN - turn on/off the module;


In this case, to enter the programming mode, you must apply a high level signal to pin 34:


For module k Arduino board we will use the serial port from the side Arduino software UART. Connection diagram in the figure:


You should get something like the following:


Programming the Bluetooth HC05 module

The module is configured in programming mode by sending AT commands via the serial port. Let's connect the HC05 module to the Arduino board according to the connection diagram in Figure 5. Apply 3.3V to the KEY pin of the module (or pin 34 of the board). We will send AT commands from the Arduino IDE serial port monitor. Let's upload the sketch from Listing 1 to Arduino. We will need the Arduino SoftwareSerial library. The speed of the UART module in programming mode is 38400 baud, but it may differ, in this case it should be selected.

Include SoftwareSerial mySerial(2, 3); // specify the rx and tx pins respectively void setup() ( pinMode(2,INPUT); pinMode(3,OUTPUT); Serial.begin(9600); mySerial.begin(38400); Serial.println("start prg") ; ) void loop() ( if (mySerial.available()) ( char c = mySerial.read(); // read from the software port Serial.print(c); // write to the hardware port ) if (Serial .available()) ( char c = Serial.read(); // read from the hardware port mySerial.write(c); // write to the software port ) )

After downloading the sketch, open the Arduino IDE serial port monitor and start sending AT commands:


List of basic AT commands:

  • AT - test command.

There are no parameters.

Module response: OK

  • AT+VERSION? - get the module firmware version.

There are no parameters.

Module response: +VERSION:

Where Bluetooth module firmware version.

  • AT+RESET - reset settings.

There are no parameters.

Module response: OK

  • AT+ORGL - setting custom module settings.

There are no parameters.

Module response: OK

  • AT+ADDR? - get the module address.

There are no parameters.

Module response: +ADDR:

Where Bluetooth module address NAP: UAP: LAP.

  • AT+NAME? - get the module name.

There are no parameters.

Module response: +NAME:

Where Bluetooth module name.

  • AT+NAME= Set a new module name.

Parameter: Bluetooth module name.

Module response: +NAME:

OK (or FAIL)

  • AT+PSWD? - get a PIN code for access to the Bluetooth module.

There are no parameters.

Module response: + PSWD:

Where Pin. Default is 1234.

  • AT+PSWD= Set the access code for the Bluetooth module.

Parameter: Module access code.

Module response: OK (or FAIL)

  • AT+CLASS= Set the operating mode of the Bluetooth module.

Parameter: Class. The module documentation does not provide possible values this parameter. By default it is set to 0. If you intend to use the module in master mode, the value does not need to be changed. If you use the module in slave mode, with the parameter value equal to 0, it is invisible to devices with operating Android system. For visibility, you must set the parameter value to 7936.

Module response: OK

  • AT+CLASS? - get the module class.

There are no parameters.

Module response: +CLASS:

Where Module class.

  • AT+IAC - get the access code to the GIAC (General Inquire Access Code) request.

The different physical communication channels used in the connection establishment process have different channel access codes. In polling channels, with the exception of dedicated ones, the same general query access code is used for all devices.

There are no parameters.

Module response: + IAC:

Where Request access code.

  • AT+IAC= Set the request access code.

Parameter: Request access code. The default value is 9e8b33.

Module response: OK (or FAIL)

  • AT+ROLE? - get the operating mode of the module.

There are no parameters.

Module response: +ROLE:

Where Bluetooth module operating mode:

  • 0 - slave. In this mode, another master can connect to the module;
  • 1 - master. In this mode, the module can itself connect to any Bluetooth device;
  • 2 - slave-loop. The module sends back all the bytes that were sent to it.
  • AT+ROLE= Set the operating mode of the Bluetooth module.

Parameter: Bluetooth module operating mode:

  • 0 - slave;
  • 1 - master;
  • 2 - slave-

Module response: OK

  • AT+UART= ,,Install the module for the serial port.

Options:

  • Stop bit:
  • 0 - no;
  • 1 - yes;
  • Parity bit:
  • 0 - no;
  • 1 - yes.

Module response: OK (or FAIL).

  • AT+UART? - get module exchange parameters.

There are no parameters.

Module response: +UART: ,,

  • Baud rate (9600,19200,38400,57600,115200);
  • Stop bit;
  • Parity bit.
  • AT+CMODE= Set the Bluetooth module connection mode.

Parameter:

  • 2 - slave-loop mode.

Module response: OK

  • AT+CMODE? - get the module connection mode.

There are no parameters.

Module response: +CMODE:

Where Bluetooth module connection mode:

  • 0 - the module can only connect to the Bluetooth device specified by the AT+BIND command;
  • 1 - the module can connect to any Bluetooth device;
  • 2 - slave-loop mode.
  • AT+INQM= ,,Set options to request a search for Bluetooth devices.

Options:

  • :
  • 0 - standard request mode;
  • 1 - request in RSSI mode;
  • Maximum number of devices responding to a request;
  • Wait timeout (1–48: 1.28 sec to 61.44 sec).

Module response: OK (or FAIL).

  • AT+INQM? - get parameters for requesting a search for Bluetooth devices.

There are no parameters.

Module response: +UART: ,,

  • AT+INQ - start searching for Bluetooth devices.

There are no parameters.

The module's response is a list of found devices.

  • AT+BIND= Link a Bluetooth module to another module.

Module response: OK (or FAIL).

  • AT+BIND? - get the address of the device associated with the Bluetooth module.

There are no parameters.

Module response: Address of the device associated with the Bluetooth module.

  • AT+FSAD=

    Module response: OK (or FAIL).

    • AT+RMSAD=

      Module response: OK (or FAIL).

      • AT+RMAAD - clear the list of authorized devices for our Bluetooth module.

      Module response: OK (or FAIL).

      • AT+LINK= Connect to a Bluetooth device.

      Parameter: Bluetooth device address.

      Module response: OK (or FAIL).

      A complete list of AT commands can be found.

      Usage example

      Let's consider an example of receiving air humidity and temperature data from a DHT11 sensor connected to Arduino on an Android device (phone, smartphone, tablet). The Arduino receives data from the DHT11 sensor every 10 seconds and sends it through the HC05 module to the Android device.

      We will need the following parts:

      • Arduino board
      • prototyping board
      • DHT11 sensor
      • Bluetooth module HC05
      • connecting wires
      • Android phone or tablet

      Let's assemble the circuit shown in the figure:


      We get:


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

      H" // constants #define DHTPIN 8 // pin for connecting the DATA contact #define DHTTYPE DHT11 // sensor DHT 11 #define INTERVAL_GET_DATA 2000 // measurement interval, ms // creating an instance of the DHT object DHT dht(DHTPIN,DHTTYPE); // variable for the measurement interval unsigned long millis_int1=0; int pos=0; // including the SoftwareSerial.h library #include SoftwareSerial mySerial(2, 3); // specify rx and tx pins respectively void setup() ( Serial.begin(9600); // start the serial port mySerial.begin(9600); dht.begin(); // start DHT Serial.println("start prg" ); ) void loop() ( if(millis()-millis_int1 >= INTERVAL_GET_DATA) ( pos=1-pos; if(pos==0) ​​( // getting humidity data from DHT11 int humidity = dht.readHumidity(); // output to the serial port monitor Serial.print("humidity=");Serial.println(humidity); mySerial.print("H=");mySerial.println(humidity); ) else ( // getting humidity data from DHT11 int temp = dht.readTemperature(); // output to the serial port monitor Serial.print("temperature=");Serial.println(temp); mySerial.print("T=");mySerial.println(temp) ; ) // start of the counting interval millis_int1=millis(); ) )

      Let's check on the Android device the reception of data sent by Arduino via the HC05 bluetooth module. Let's install the Bluetooth Terminal program on the Android device. In the program we will establish a connection with the HC05 module:


      And we observe the reception of data coming from Arduino through the HC05 module:


      And outputting data to the Arduino IDE serial port monitor:


      Frequently asked questions FAQ

      1. There is no response from the module to AT commands
      • Check that the module is connected correctly;
      • Check the connections of the module's KEY pin (or pin 34) to 3.3V;
      • Check the settings for the serial port (speed 38400 baud, maybe for modules different manufacturers turn off).
      2. Android device cannot connect to bluetooth moduleHC05
      • Check the module's connection to the power supply; the LED on the module should blink quickly (network search);
      • Check that the module's KEY pin (or pin 34) is disconnected from 3.3V;
      • Set the slave role using AT commands (AT+ROLE=0).
      3. Data is not transferred toAndroid device
      • Check that the HC05 bluetooth module is properly connected to the Arduino board;
      • Baud rate Arduino data and HC05 must match the one set using the AT+UART AT command.