0
0
Arduinoprogramming~10 mins

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

Choose your learning style9 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.