Serial.print() without Serial Monitor connected

For debugging I have a lot of Serial.print()s in my sketch.

Is there a difference in operation and/or run time if the cable to the IDE/Serial Monitor is connected or not?

Nope. The Arduino doesn't know and doesn't care if anyone is listening.

However the calls to print themselves do take some time so you can conditionally include them in the program.

// at top of program
#define DEBUG

// later in code

#ifdef DEBUG
Serial.println("Some debugging info");

Even better system for switching debug output on and off:

#define DEBUG true  //set to true for debug output, false for no debug ouput
#define Serial if(DEBUG)Serial

Add this to setup() if you are using a Leonardo, Pro Micro, or other ATmega32U4 based board and don't want the program to run until the Serial Monitor has been opened while debug output is enabled:

while (DEBUG && !Serial);

Then you can just use Serial functions as usual in the rest of your sketch.

If you have debug and non debug serial output or want multiple levels of output possible you can do something like this:

#define DEBUG_ERROR true

#define DEBUG_WARNING true


void setup() {
  while (!Serial);
  DEBUG_ERROR_SERIAL.println("This is an error message");
  DEBUG_WARNING_SERIAL.println("This is a warning message");
  DEBUG_INFORMATION_SERIAL.print("The state of pin 5 is ");
  DEBUG_INFORMATION_SERIAL.println(digitalRead(5) ? "HIGH" : "LOW");
  Serial.println("This is standard program output");

void loop() {}