Bird
Raised Fist0
Arduinoprogramming~10 mins

Sending data over Bluetooth in Arduino - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Sending data over Bluetooth
Start Setup
↓
Initialize Bluetooth Serial
↓
Check if data available
Yes↓
Send Data
↓
Repeat or Stop
The program sets up Bluetooth communication, waits for data input from serial, then sends data to Bluetooth repeatedly.
Execution Sample
Arduino
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); // Bluetooth
}

void loop() {
  if (Serial.available()) {
    Serial1.write(Serial.read());
  }
}
This code initializes Bluetooth serial and forwards received serial data to Bluetooth.
Execution Table
StepActionData Available?Data SentOutput
1Start setupNoNoNo output
2Initialize Serial and Serial1NoNoNo output
3Enter loopNoNoNo output
4Check Serial.available()NoNoNo output
5Wait for data inputYesNoNo output
6Check Serial.available()YesYesData sent to Bluetooth
7Read byte from SerialYesYesByte read
8Write byte to Serial1YesYesByte sent over Bluetooth
9Repeat loopYesYesContinuous data sending
10No more data inputNoNoStops sending data
💡 No more data input or program stopped, so no more data sent.
Variable Tracker
VariableStartAfter Step 5After Step 6After Step 9Final
Serial.available()01 or more1 or more1 or more0 when no input
Data sentNoNoYesYesNo
Key Moments - 3 Insights
Why does the program check Serial.available() before sending data to Bluetooth?
Because there's no data to send if none available; the execution_table rows 3-5 show no data sent until input arrives.
What happens if Serial.available() returns 0?
No data is sent or read; the program waits, as shown in execution_table rows 3-4.
Why do we use Serial1.write(Serial.read())?
To read one byte from serial input and immediately send it to Bluetooth, shown in rows 6-8.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the program start sending data over Bluetooth?
AStep 4
BStep 6
CStep 2
DStep 10
💡 Hint
Check the 'Data Sent' column in execution_table rows.
According to variable_tracker, what is the value of Serial.available() after step 9?
A0
BUndefined
C1 or more
D-1
💡 Hint
Look at the 'Serial.available()' row in variable_tracker after step 9.
If no more data input, what happens to data sending according to execution_table?
AData sending stops
BData sending continues
CData sending pauses then resumes automatically
DData sending sends garbage data
💡 Hint
See the exit_note and step 10 in execution_table.
Concept Snapshot
Setup Bluetooth serial with Serial1.begin(9600);
Check data available with Serial.available();
Read data with Serial.read();
Send data with Serial1.write();
Only send when data available.
Loop to keep sending data.
Full Transcript
This example shows how to send data over Bluetooth using Arduino. First, the program sets up the serial communication for both the main serial monitor and the Bluetooth module. It waits until data is available from the serial monitor by checking Serial.available(). When data arrives from serial, it reads one byte and sends it to Bluetooth via Serial1. This process repeats continuously while data is provided. If no more data, the program stops sending. The execution table traces each step, showing when data is sent or not. The variable tracker shows how the availability of input data changes over time. Key moments clarify why checking data availability is important and how data is forwarded to Bluetooth. The visual quiz tests understanding of when data sending starts, the state of data availability, and what happens on no input.

Practice

(1/5)
1. What is the main purpose of using Bluetooth with an Arduino?
easy
A. To connect Arduino to the internet directly
B. To increase the Arduino's processing speed
C. To send and receive data wirelessly
D. To power the Arduino without a battery

Solution

  1. Step 1: Understand Bluetooth function

    Bluetooth is a wireless communication technology used to send and receive data without wires.
  2. Step 2: Identify Arduino's Bluetooth use

    Arduino uses Bluetooth to communicate wirelessly with other devices, not to speed up or power itself.
  3. Final Answer:

    To send and receive data wirelessly -> Option C
  4. Quick Check:

    Bluetooth = wireless data transfer [OK]
Hint: Bluetooth means wireless data transfer [OK]
Common Mistakes:
  • Thinking Bluetooth powers the Arduino
  • Confusing Bluetooth with internet connection
  • Assuming Bluetooth speeds up processing
2. Which Arduino code snippet correctly initializes a SoftwareSerial Bluetooth connection on pins 10 (RX) and 11 (TX) at 9600 baud?
easy
A. SoftwareSerial BT(11, 10); BT.begin(115200);
B. SoftwareSerial BT(11, 10); BT.begin(9600);
C. SoftwareSerial BT(10, 11); BT.begin(115200);
D. SoftwareSerial BT(10, 11); BT.begin(9600);

Solution

  1. Step 1: Check pin order for SoftwareSerial

    SoftwareSerial constructor uses RX pin first, then TX pin. So (10, 11) means RX=10, TX=11.
  2. Step 2: Verify baud rate matches 9600

    BT.begin(9600) sets baud rate to 9600, which is standard for many Bluetooth modules.
  3. Final Answer:

    SoftwareSerial BT(10, 11); BT.begin(9600); -> Option D
  4. Quick Check:

    Correct pins and baud = SoftwareSerial BT(10, 11); BT.begin(9600); [OK]
Hint: RX pin first, then TX pin in SoftwareSerial [OK]
Common Mistakes:
  • Swapping RX and TX pins
  • Using wrong baud rate
  • Calling begin() with wrong speed
3. What will be the output on the Bluetooth receiver if the Arduino code below runs?
SoftwareSerial BT(10, 11);
void setup() {
  BT.begin(9600);
  BT.println("Hello");
}
void loop() {}
medium
A. HELLO
B. Hello
C. hello
D. No output

Solution

  1. Step 1: Understand BT.println() behavior

    BT.println("Hello") sends the string "Hello" followed by a newline over Bluetooth.
  2. Step 2: Check case sensitivity

    The string "Hello" is sent exactly as written, preserving case.
  3. Final Answer:

    Hello -> Option B
  4. Quick Check:

    BT.println("Hello") sends "Hello" [OK]
Hint: println sends exact string with newline [OK]
Common Mistakes:
  • Assuming output is uppercase
  • Thinking no output because loop is empty
  • Confusing println with print
4. Identify the error in this Arduino Bluetooth code snippet:
SoftwareSerial BT(10, 11);
void setup() {
  Serial.begin(9600);
  BT.begin(9600);
}
void loop() {
  Serial.println("Send data");
  BT.print("Data");
}
medium
A. No error, code works fine
B. Missing BT.read() to receive data
C. Pins 10 and 11 are swapped in SoftwareSerial
D. Serial.begin() should be BT.begin() only

Solution

  1. Step 1: Verify initialization

    Serial.begin(9600) initializes USB serial correctly; BT.begin(9600) initializes SoftwareSerial on pins 10 (RX), 11 (TX) correctly.
  2. 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.
  3. Final Answer:

    No error, code works fine -> Option A
  4. 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

  1. 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.
  2. Step 2: Check data sending and timing

    Inside loop, sensor value is read and sent with BT.println(), then delay(1000) waits 1 second.
  3. Final Answer:

    SoftwareSerial BT(2, 3); void setup() { BT.begin(9600); } void loop() { int sensorValue = analogRead(A0); BT.println(sensorValue); delay(1000); } -> Option A
  4. Quick Check:

    Correct pins, baud, send, and delay = SoftwareSerial BT(2, 3); void setup() { BT.begin(9600); } void loop() { int sensorValue = analogRead(A0); BT.println(sensorValue); delay(1000); } [OK]
Hint: Match pins, baud, and use println with delay [OK]
Common Mistakes:
  • Swapping RX and TX pins
  • Using wrong baud rate
  • Sending data on Serial instead of BT
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard