Power input (3.3V to 5V)
Power input (3.3V to 5V)
Ground
Serial data transmission
Serial data reception
Enable pin (active high)
State pin (indicates the module's status)
Applications
The HC-05 Bluetooth Module is widely used in various applications, including |
Home automation, industrial automation, wearable devices, and more
Robot control, robotic arms, and other robotic applications
Wireless serial communication, wireless sensor networks, and more
Wireless health monitoring, medical device control, and more
Conclusion
The HC-05 Bluetooth Module is a reliable and efficient wireless communication module that enables devices to communicate with each other over Bluetooth protocol. Its compact size, low power consumption, and easy configuration make it an ideal module for IoT and robotics projects.
HC-05 Bluetooth Module Documentation
Overview
The HC-05 is a widely used Bluetooth module that enables serial communication between devices. It is a slave device that can be connected to a microcontroller or a computer to establish a wireless connection with other Bluetooth devices.
Pinout
The HC-05 module has the following pins:
VCC: Power supply (typically 5V)
GND: Ground
RX: Receive pin (connected to the microcontroller's transmit pin)
TX: Transmit pin (connected to the microcontroller's receive pin)
EN (optional): Enable pin (used to enable or disable the module)
STATE (optional): State pin (indicates the module's status)
Code Examples
### Example 1: Basic Arduino Serial Communication
In this example, we will use an Arduino board to send and receive data using the HC-05 module.
Hardware Connection
Connect the HC-05 module's VCC to the Arduino's 5V pin
Connect the HC-05 module's GND to the Arduino's GND pin
Connect the HC-05 module's RX to the Arduino's TX pin (pin 1)
Connect the HC-05 module's TX to the Arduino's RX pin (pin 0)
Arduino Code
```cpp
#include <SoftwareSerial.h>
SoftwareSerial btSerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
btSerial.begin(9600);
}
void loop() {
if (btSerial.available()) {
Serial.write(btSerial.read());
}
if (Serial.available()) {
btSerial.write(Serial.read());
}
delay(10);
}
```
In this example, we use the SoftwareSerial library to establish a serial communication between the Arduino and the HC-05 module. The `btSerial` object is used to communicate with the module.
### Example 2: Android App Control using HC-05
In this example, we will use an Android app to control an LED connected to an Arduino board using the HC-05 module.
Hardware Connection
Connect the HC-05 module's VCC to the Arduino's 5V pin
Connect the HC-05 module's GND to the Arduino's GND pin
Connect the HC-05 module's RX to the Arduino's TX pin (pin 1)
Connect the HC-05 module's TX to the Arduino's RX pin (pin 0)
Connect an LED to a digital pin on the Arduino board
Arduino Code
```cpp
const int ledPin = 13; // LED connected to digital pin 13
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
char cmd = Serial.read();
if (cmd == '1') {
digitalWrite(ledPin, HIGH);
} else if (cmd == '0') {
digitalWrite(ledPin, LOW);
}
}
}
```
In this example, we use the Arduino's serial communication to receive commands from the Android app. The app sends a character '1' to turn on the LED and '0' to turn it off.
Android App Code (using Android Studio)
```java
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class BluetoothControlActivity extends AppCompatActivity {
private BluetoothAdapter btAdapter;
private BluetoothSocket btSocket;
private OutputStream outputStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetooth_control);
btAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = btAdapter.getRemoteDevice("HC-05's MAC address");
btSocket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
btSocket.connect();
outputStream = btSocket.getOutputStream();
Button btnOn = findViewById(R.id btn_on);
Button btnOff = findViewById(R.id btn_off);
btnOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
outputStream.write('1');
} catch (IOException e) {
Toast.makeText(BluetoothControlActivity.this, "Error sending command", Toast.LENGTH_SHORT).show();
}
}
});
btnOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
outputStream.write('0');
} catch (IOException e) {
Toast.makeText(BluetoothControlActivity.this, "Error sending command", Toast.LENGTH_SHORT).show();
}
}
});
}
}
```
In this example, we use the Android Bluetooth API to establish a connection with the HC-05 module. We then use the `outputStream` object to send commands to the Arduino board, which controls the LED accordingly.