Serial.begin(9600) initializes USB serial correctly; BT.begin(9600) initializes SoftwareSerial on pins 10 (RX), 11 (TX) correctly.
Step 2: Check loop behavior
The loop sends "Send data\n" to Serial and "Data" repeatedly to Bluetooth. No syntax errors or crashes; code works fine for sending data over Bluetooth.
Final Answer:
No error, code works fine -> Option A
Quick Check:
Initializes correctly and sends data continuously [OK]
Hint: Code runs fine for sending; BT.read() not needed if only sending [OK]
Common Mistakes:
Thinking Serial.begin() interferes with Bluetooth
Believing BT.read() is always required
Assuming pins 10 and 11 are swapped
5. You want to send sensor data from Arduino to a phone via Bluetooth every second. Which code snippet correctly implements this using SoftwareSerial on pins 2 (RX) and 3 (TX) at 9600 baud?
hard
A. SoftwareSerial BT(2, 3);
void setup() {
BT.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
BT.println(sensorValue);
delay(1000);
}
B. SoftwareSerial BT(3, 2);
void setup() {
BT.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
BT.print(sensorValue);
delay(1000);
}
C. SoftwareSerial BT(2, 3);
void setup() {
BT.begin(115200);
}
void loop() {
int sensorValue = analogRead(A0);
BT.println(sensorValue);
delay(1000);
}
D. SoftwareSerial BT(2, 3);
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1000);
}
Solution
Step 1: Verify SoftwareSerial pins and baud rate
BT is created with RX=2 and TX=3, and BT.begin(9600) matches baud rate for Bluetooth.
Step 2: Check data sending and timing
Inside loop, sensor value is read and sent with BT.println(), then delay(1000) waits 1 second.