Introduction
In this experiment, we will use the HC-05 Bluetooth module to establish wireless communication between an Arduino and another device, such as a smartphone or computer.
Components Needed
- HC-05 Bluetooth Module
- Arduino (e.g., Uno, Nano)
- Jumper wires
- Breadboard
Circuit Setup
- Connect the VCC pin of the HC-05 module to the 5V pin of the Arduino.
- Connect the GND pin of the module to the GND pin of the Arduino.
- Connect the TXD pin of the HC-05 to the RX pin of the Arduino (pin 0).
- Connect the RXD pin of the HC-05 to the TX pin of the Arduino (pin 1).
Ensure proper wiring before powering the circuit.
Code for Bluetooth Communication
Upload the following code to your Arduino to establish Bluetooth communication:
void setup() {
Serial.begin(9600); // Start communication with HC-05
Serial.println("HC-05 Bluetooth Test");
}
void loop() {
if (Serial.available()) {
char received = Serial.read(); // Read received data
Serial.print("Received: ");
Serial.println(received); // Echo back the received data
}
}
Explanation
The HC-05 communicates with the Arduino using UART. The received data is printed to the Serial Monitor, and you can send data back to the connected device.
Troubleshooting
- If the HC-05 does not respond, ensure the connections are correct and the module is powered on.
- If data is not received, verify the baud rate matches between devices (default is 9600).