0
0
Arduinoprogramming~10 mins

Receiving commands 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.

Arduino
Serial[1](9600);
Drag options to blanks, or click blank then click option'
Aread
Bbegin
Cprint
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of begin to start communication.
Trying to read or write before starting communication.
2fill in blank
medium

Complete the code to check if data is available to read from Bluetooth.

Arduino
if (Serial.[1]() > 0) {
Drag options to blanks, or click blank then click option'
Aavailable
Bread
Cwrite
Dbegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using read() instead of available() to check for data.
Using write() or begin() which do not check data availability.
3fill in blank
hard

Fix the error in reading a byte from Bluetooth and storing it in variable command.

Arduino
char command = Serial.[1]();
Drag options to blanks, or click blank then click option'
Aavailable
Bwrite
Cbegin
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using available() which returns number of bytes, not the data.
Using write() which sends data, not reads it.
4fill in blank
hard

Fill both blanks to read a command and check if it equals 'A'.

Arduino
if (Serial.[1]() > 0) {
  char command = Serial.[2]();
  if (command == 'A') {
    // Do something
  }
}
Drag options to blanks, or click blank then click option'
Aavailable
Bread
Cwrite
Dbegin
Attempts:
3 left
💡 Hint
Common Mistakes
Reading without checking if data is available.
Using write() or begin() instead of read() to get data.
5fill in blank
hard

Fill all three blanks to read a command, check if it is 'B', and send a response 'OK'.

Arduino
if (Serial.[1]() > 0) {
  char command = Serial.[2]();
  if (command == '[3]') {
    Serial.println("OK");
  }
}
Drag options to blanks, or click blank then click option'
Aavailable
Bread
CB
DA
Attempts:
3 left
💡 Hint
Common Mistakes
Not checking availability before reading.
Comparing to a string instead of a character.
Using wrong functions to read or check data.