Print Versus Println
Part of the First Circuits section of Coddy's Arduino journey. Lesson 8 of 22.
Serial.println() prints its text and then starts a new line. Serial.print() prints the text and stays on the same line, so whatever comes next is added right after it.
Serial.print("Speed: ");
Serial.println("fast");
Serial.println("Done");The monitor shows two lines:
Speed: fast
DoneBuild a line from several pieces with print(), and finish it with println(). The space inside "Speed: " keeps the words apart: without it the monitor shows Speed:fast.
Printing what the sketch is doing, as it does it, is the main way to find out why a sketch does not work.
Challenge
EasyBlink the LED on pin 13 (500 ms on, 500 ms off) and report each change in the Serial monitor:
- when you turn it on, print
LED: on - when you turn it off, print
LED: off - print
"LED: "withprint(), then the word withprintln(), so each status is one line
Press Run, then Check.
Try it yourself
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// print LED: on
digitalWrite(13, HIGH);
delay(500);
// print LED: off
digitalWrite(13, LOW);
delay(500);
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in First Circuits
2Talking to Your Computer
Hello, Serial MonitorPrint Versus PrintlnPrinting NumbersYour First VariableCounting UpWhen an Int Runs OutPractice on your own: Arduino playground