Wireless communication is swiftly replacing the wired connection when it comes to electronics and communication. Designed to replace cable connections HC-05 uses serial communication to communicate with the electronics. Usually, it is used to connect small devices like mobile phones using a short-range wireless connection to exchange files. It uses the 2.45GHz frequency band. The transfer rate of the data can vary up to 1Mbps and is in range of 10 meters.
The HC-05 module can be operated within 4-6V of power supply. It supports baud rate of 9600, 19200, 38400, 57600, etc. Most importantly it can be operated in Master-Slave mode which means it will neither send or receive data from external sources.
Description of pins
- Enable - This pin is used to set the Data Mode or and AT command mode (set high).
- VCC - This is connected to +5V power supply.
- Ground - Connected to ground of powering system.
- Tx (Transmitter) - This pin transmits the received data Serially.
- Rx (Receiver) - Used for broadcasting data serially over bluetooth.
- State -Used to check if the bluetooth is working properly.
Modes of Operation
The HC-05 Bluetooth Module can be used in two modes of operation: Command Mode and Data Mode.
In Command Mode, you can communicate with the Bluetooth module through AT Commands for configuring various settings and parameters of the Module like get the firmware information, changing Baud Rate, changing module name, it can be used to set it as master or slave.
A point about HC-05 Module is that it can be configured as Master or Slave in a communication pair. In order to select either of the modes, you need to activate the Command Mode and sent appropriate AT Commands.
Coming to the Data Mode, in this mode, the module is used for communicating with other Bluetooth device i.e. data transfer happens in this mode.
Programming HC-05 with Microcontroller
Technical specs of the code:
- Arduino-Uno is used as the microcontroller.
- Name: HC-05
- Password: 1234 (or 0000)
- Type: Slave
- Mode: Data
- Baud Rate: 9600 with 8 data bits, no parity and 1 stop bit
Android App interfacing with HC-05
Now, we will develop a small android application to demonstrate the connection of bluetooth module and the android app. We will be using Android Studio for this purpose and above mentioned C code on the microcontroller.
- Create an empty project on Android Studio
- Create a ListView containing all the available bluetooth devices.
- Get the name and MAC-address of HC-05 module.
- Open connection with HC-05 module.
- Instruct the module with data as bytes.
Understanding the code
1.Getting all the Bluetooth devices in ListView
This code is for the MainActivity or first activity where the list will be displayed then after that when device will be selected, Control activity will come to give the command.
2.Getting the name and MAC address of device
Now we will create a OnClick Listener for the list so that thename and MAC address can be extracted from the device.
3.Establishing a connection between both of them
The connect() function in the Control.java will help to make the connection between both.
4.Finally commanding the HC-05 module
Here first we will check if our socket is connected, then only we will proceed to avoid the Null Pointer exception.
Now finally as we have done our first basic project with the HC-05 module and the Android programming, we can move on to complex electronic bots and make there wired connection to wireless using this amazing module HC-05 and also we now know to make a custom app.
You can find the above code in form of Android Studio Project commited here.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Encoder and Decoder
- Difference between Half adder and full adder
- Shift Micro-Operations in Computer Architecture
- Difference between Verilog and SystemVerilog
- Multiplexer Design using Verilog HDL
- Error Detection Codes: Parity Bit Method
- Difference between Amplitude Modulation and Frequency Modulation
- Difference between Amplitude Modulation and Phase Modulation
- Difference between Frequency Modulation and Phase Modulation
- JK Flip Flop and SR Flip Flop
- Difference between Multiplexer and Decoder
- FPGA Full Form
- Difference between Feedback and Feed Forward control systems
- Difference between E-paper and LCD
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.