Bluetooth modules like HC-05 and HC-06 let your Arduino talk wirelessly to other devices. This helps you send and receive data without wires.
Bluetooth with HC-05/HC-06 module in Arduino
SoftwareSerial bluetooth(10, 11); // RX, TX pins void setup() { Serial.begin(9600); // Start serial monitor bluetooth.begin(9600); // Start Bluetooth serial } void loop() { if (bluetooth.available()) { char data = bluetooth.read(); Serial.print(data); // Show data on serial monitor } if (Serial.available()) { char data = Serial.read(); bluetooth.print(data); // Send data to Bluetooth } }
Use SoftwareSerial to create a serial connection on other pins because Arduino Uno has only one hardware serial port.
Make sure baud rates match between Arduino and Bluetooth module (usually 9600).
SoftwareSerial bluetooth(2, 3); // RX=2, TX=3 void setup() { Serial.begin(9600); bluetooth.begin(9600); }
if (bluetooth.available()) { char c = bluetooth.read(); Serial.print(c); }
if (Serial.available()) { char c = Serial.read(); bluetooth.print(c); }
This program reads data from the Bluetooth module and prints it on the serial monitor. It also sends anything typed in the serial monitor to the Bluetooth device.
/* Simple Bluetooth communication with HC-05/HC-06 Connect HC-05 RX to Arduino pin 10 (RX), TX to pin 11 (TX) Use SoftwareSerial to communicate */ #include <SoftwareSerial.h> SoftwareSerial bluetooth(10, 11); // RX, TX void setup() { Serial.begin(9600); // Start serial monitor bluetooth.begin(9600); // Start Bluetooth serial Serial.println("Bluetooth ready"); } void loop() { if (bluetooth.available()) { char data = bluetooth.read(); Serial.print("Received: "); Serial.println(data); } if (Serial.available()) { char data = Serial.read(); bluetooth.print(data); } }
HC-05 can be master or slave; HC-06 is slave only.
Make sure to connect HC-05 TX to Arduino RX pin and RX to Arduino TX pin (cross connection).
Use a voltage divider on HC-05 RX pin if Arduino uses 5V to avoid damage (HC-05 RX is 3.3V tolerant).
HC-05/HC-06 modules let Arduino communicate wirelessly using Bluetooth serial.
Use SoftwareSerial to connect Bluetooth module on different pins.
Match baud rates and connect pins correctly for communication.
Practice
Solution
Step 1: Understand the function of HC-05/HC-06 modules
These modules are designed to allow wireless serial communication using Bluetooth technology.Step 2: Compare options with module purpose
Only To enable wireless serial communication between Arduino and other Bluetooth devices correctly describes enabling wireless serial communication; others describe unrelated functions.Final Answer:
To enable wireless serial communication between Arduino and other Bluetooth devices -> Option AQuick Check:
HC-05/HC-06 = Wireless serial communication [OK]
- Confusing Bluetooth with Wi-Fi connectivity
- Thinking it powers the Arduino
- Assuming it speeds up Arduino processing
Solution
Step 1: Recall SoftwareSerial constructor syntax
The constructor is SoftwareSerial(rxPin, txPin), so RX is first, TX second.Step 2: Match pins to constructor
Given RX=10 and TX=11, the correct call is SoftwareSerial BT(10, 11);Final Answer:
SoftwareSerial BT(10, 11); -> Option BQuick Check:
SoftwareSerial(rx, tx) = SoftwareSerial(10, 11) [OK]
- Swapping RX and TX pins
- Using default hardware serial pins (0,1) for SoftwareSerial
- Choosing pins not supported by SoftwareSerial
SoftwareSerial BT(10, 11);
void setup() {
Serial.begin(9600);
BT.begin(9600);
}
void loop() {
if (BT.available()) {
char c = BT.read();
Serial.print(c);
}
}Solution
Step 1: Understand data flow in code
The code reads characters from Bluetooth (BT) and prints them to Serial Monitor.Step 2: Analyze input and output
If HC-05 sends "Hello", BT.read() reads each character and Serial.print outputs them, so "Hello" appears.Final Answer:
Hello -> Option DQuick Check:
BT.read() + Serial.print = "Hello" [OK]
- Assuming no output without Serial.println
- Forgetting to call BT.begin()
- Confusing BT with Serial hardware pins
SoftwareSerial BT(10, 11);
void setup() {
Serial.begin(9600);
BT.begin(115200);
}
void loop() {
if (BT.available()) {
Serial.write(BT.read());
}
}
Assuming the HC-05 module is set to 9600 baud.Solution
Step 1: Check baud rate consistency
HC-05 default baud is 9600, but BT.begin uses 115200, causing communication failure.Step 2: Verify other code parts
SoftwareSerial pins and Serial.begin are correct; BT.read() is correctly placed in loop.Final Answer:
BT.begin baud rate does not match HC-05 baud rate -> Option CQuick Check:
Baud rates must match for communication [OK]
- Using different baud rates between Arduino and HC-05
- Placing BT.read() in setup() instead of loop()
- Confusing Serial and SoftwareSerial pins
Solution
Step 1: Collect full string from Bluetooth input
The correct code declares a global String input = ""; and uses while (BT.available()) { char c = BT.read(); input += c; } to accumulate all available characters into the string.Step 2: Compare the full input string and control LED
After accumulating, if (input == "LED ON") { digitalWrite(13, HIGH); input = ""; } turns on the LED and clears the input for next message.Step 3: Analyze other options
One option incorrectly compares a single BT.read() char to 'LED ON'; another turns on the LED on if (BT.available()) without checking content; the last captures only a single char per loop with input = BT.read().Final Answer:
The code snippet that accumulates characters into a String using while(BT.available()) -> Option AQuick Check:
Read full input string before comparing [OK]
- Comparing single char to full string
- Not accumulating all characters before checking
- Turning LED on without input check
Ready to prove it?
Pass the test and this pattern moves unknown
