0
0
Arduinoprogramming~20 mins

Receiving commands over Bluetooth in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bluetooth Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Bluetooth command receiver sketch?
Consider this Arduino code that reads characters from a Bluetooth serial connection and prints them to the Serial Monitor. What will be printed if the Bluetooth device sends the characters 'HELLO'?
Arduino
void setup() {
  Serial.begin(9600); // Serial monitor
  Serial1.begin(9600); // Bluetooth module
}

void loop() {
  if (Serial1.available()) {
    char c = Serial1.read();
    Serial.print(c);
  }
}
Ahello
BNo output because Serial1 is not initialized
CHELLO
DHELLOHELLO
Attempts:
2 left
💡 Hint
Think about what Serial1.read() returns and how Serial.print() works.
🧠 Conceptual
intermediate
1:30remaining
Which Arduino function checks if Bluetooth data is ready to read?
You want to read incoming data from a Bluetooth module connected to Serial1. Which function tells you if there is data waiting to be read?
ASerial1.read()
BSerial1.available()
CSerial1.begin()
DSerial1.print()
Attempts:
2 left
💡 Hint
This function returns how many bytes are ready to read.
🔧 Debug
advanced
2:30remaining
Why does this Bluetooth command receiver code not print anything?
Look at this Arduino code snippet. It should print characters received from Bluetooth on Serial1 to the Serial Monitor. But nothing appears on the Serial Monitor. What is the problem?
Arduino
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial1.available() > 0) {
    char c = Serial1.read();
    Serial.print(c);
  }
}
ASerial1.available is missing parentheses, so it does not call the function
BSerial1.read() is called before Serial1.available()
CSerial.begin(9600) should be Serial1.begin(9600)
DSerial.print(c) should be Serial.println(c)
Attempts:
2 left
💡 Hint
Check how functions are called in Arduino code.
📝 Syntax
advanced
2:30remaining
Which option correctly reads a full command string from Bluetooth until newline?
You want to read a full command sent over Bluetooth ending with a newline character '\n'. Which code snippet correctly reads characters into a string until '\n' is received?
Arduino
String command = "";
void loop() {
  while (Serial1.available()) {
    char c = Serial1.read();
    if (c == '\n') {
      // command complete
      Serial.println(command);
      command = "";
    } else {
      command += c;
    }
  }
}
AReads characters but uses Serial.read() instead of Serial1.read()
BReads characters but never clears the command string
CReads characters but prints command before '\n' is received
DReads characters until '\n', then prints the command and clears it
Attempts:
2 left
💡 Hint
Look for the code that resets the command string after printing.
🚀 Application
expert
3:00remaining
How many commands will be stored in the array after this Bluetooth input?
This Arduino code reads commands separated by commas from Bluetooth and stores them in an array. If the Bluetooth device sends 'ON,OFF,TOGGLE,STATUS', how many commands will be stored?
Arduino
String commands[5];
int index = 0;
String current = "";

void loop() {
  while (Serial1.available()) {
    char c = Serial1.read();
    if (c == ',') {
      commands[index++] = current;
      current = "";
    } else {
      current += c;
    }
  }
  // After input ends, store last command
  if (current.length() > 0) {
    commands[index++] = current;
    current = "";
  }
}
A4
B3
C5
D1
Attempts:
2 left
💡 Hint
Count the number of commas and remember the last command after the last comma.