0
0
Arduinoprogramming~10 mins

Sending data over Bluetooth in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the Bluetooth serial communication at 9600 baud rate.

Arduino
void setup() {
  Serial.begin([1]);
}
Drag options to blanks, or click blank then click option'
A4800
B115200
C9600
D19200
Attempts:
3 left
💡 Hint
Common Mistakes
Using a baud rate that does not match the Bluetooth module's setting.
Forgetting to initialize Serial communication.
2fill in blank
medium

Complete the code to send the string "Hello" over Bluetooth.

Arduino
void loop() {
  Serial.[1]("Hello");
  delay(1000);
}
Drag options to blanks, or click blank then click option'
Aprint
Bavailable
Cwrite
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using read which is for receiving data.
Using available which checks incoming data.
3fill in blank
hard

Fix the error in the code to read a character from Bluetooth and store it in variable 'c'.

Arduino
char c;
void loop() {
  if (Serial.[1]() > 0) {
    c = Serial.read();
  }
}
Drag options to blanks, or click blank then click option'
Awrite
Bbegin
Cprint
Davailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using write() which sends data, not checks availability.
Using print() which sends data.
4fill in blank
hard

Fill both blanks to send the integer variable 'value' as a string over Bluetooth.

Arduino
int value = 123;
void loop() {
  Serial.[1](String([2]));
  delay(1000);
}
Drag options to blanks, or click blank then click option'
Aprint
Bvalue
Cwrite
DSerial
Attempts:
3 left
💡 Hint
Common Mistakes
Using write which sends raw bytes, not readable text.
Passing a wrong variable or object.
5fill in blank
hard

Fill all three blanks to read a line from Bluetooth and store it in 'inputString'.

Arduino
String inputString = "";
void loop() {
  if (Serial.[1]() > 0) {
    char c = Serial.[2]();
    if (c == [3]) {
      // end of line
    } else {
      inputString += c;
    }
  }
}
Drag options to blanks, or click blank then click option'
Aavailable
Bread
C'\n'
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using write() instead of read().
Checking for wrong end-of-line character.