Challenge - 5 Problems
Serial Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of mixed Serial.print() and Serial.println() calls
What will be the output on the Serial Monitor after running this Arduino code?
Arduino
void setup() {
Serial.begin(9600);
Serial.print("Hello");
Serial.print(" ");
Serial.println("World");
Serial.println("!");
}
void loop() {}Attempts:
2 left
💡 Hint
Remember that Serial.print() does not add a new line, but Serial.println() does.
✗ Incorrect
Serial.print() writes text without moving to a new line. Serial.println() writes text and then moves to a new line. So the first two print calls write "Hello " on the same line, then println("World") writes "World" and moves to a new line. The last println("!") writes "!" and moves to a new line.
❓ Predict Output
intermediateSerial.println() with numbers and strings
What will be printed on the Serial Monitor after this code runs?
Arduino
void setup() {
Serial.begin(9600);
Serial.println(123);
Serial.print("Number: ");
Serial.println(456);
}
void loop() {}Attempts:
2 left
💡 Hint
Serial.println() adds a new line after printing, Serial.print() does not.
✗ Incorrect
Serial.println(123) prints 123 and moves to a new line. Then Serial.print("Number: ") prints "Number: " without a new line. Finally, Serial.println(456) prints 456 and moves to a new line.
🔧 Debug
advancedWhy does this code not print on separate lines?
This Arduino code is supposed to print each word on a new line, but it prints everything on the same line. What is the reason?
Arduino
void setup() {
Serial.begin(9600);
Serial.print("Line1");
Serial.print("Line2");
Serial.print("Line3");
}
void loop() {}Attempts:
2 left
💡 Hint
Check the difference between Serial.print() and Serial.println().
✗ Incorrect
Serial.print() prints text but does not move to a new line. To print on separate lines, Serial.println() must be used.
🧠 Conceptual
advancedEffect of multiple Serial.println() calls
What will be the output of this Arduino code on the Serial Monitor?
Arduino
void setup() {
Serial.begin(9600);
Serial.println("Start");
Serial.println();
Serial.println("End");
}
void loop() {}Attempts:
2 left
💡 Hint
Serial.println() with no arguments prints a blank line.
✗ Incorrect
The first println prints "Start" and moves to a new line. The second println() prints a blank line. The third println prints "End" and moves to a new line.
❓ Predict Output
expertCombining Serial.print() and Serial.println() with variables
What will be the exact output on the Serial Monitor after running this code?
Arduino
void setup() {
Serial.begin(9600);
int a = 5;
int b = 10;
Serial.print("a = ");
Serial.print(a);
Serial.print(", b = ");
Serial.println(b);
Serial.println("Done");
}
void loop() {}Attempts:
2 left
💡 Hint
Remember that Serial.println() adds a new line after printing, Serial.print() does not.
✗ Incorrect
The first three Serial.print() calls print "a = 5, b = " on the same line. Then Serial.println(b) prints "10" and moves to a new line. Finally, Serial.println("Done") prints "Done" and moves to a new line.
