Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a baud rate that does not match the Bluetooth module's setting.
Forgetting to initialize Serial communication.
✗ Incorrect
The standard baud rate for Bluetooth serial communication is 9600.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
read which is for receiving data.Using
available which checks incoming data.✗ Incorrect
The print function sends data as readable text over serial.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
write() which sends data, not checks availability.Using
print() which sends data.✗ Incorrect
available() checks if data is ready to read from serial.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
write which sends raw bytes, not readable text.Passing a wrong variable or object.
✗ Incorrect
Use print to send text, and convert the integer value to a string.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
write() instead of read().Checking for wrong end-of-line character.
✗ Incorrect
Check if data is available, read one character, and detect newline '\n' as line end.