Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of begin to start communication.
Trying to read or write before starting communication.
✗ Incorrect
The begin function starts serial communication at the specified baud rate.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The available() function returns the number of bytes available to read.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using available() which returns number of bytes, not the data.
Using write() which sends data, not reads it.
✗ Incorrect
The read() function reads one byte from the serial buffer.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Reading without checking if data is available.
Using write() or begin() instead of read() to get data.
✗ Incorrect
First, check if data is available with available(), then read it with read().
5fill in blank
hardFill 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'
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.
✗ Incorrect
Check if data is available, read it, then compare to character 'B'. If true, send "OK".