Description

Disables serial communication, allowing the RX and TX pins to be used for general input and output. To re-enable serial communication, call Serial.begin().

Syntax

Use the following function to disable the Serial communication:

Serial.end()

Parameters

The function admits the following object:

Serial: serial port object. See the list of available serial ports for each board on the Serial main page.

Returns

The function returns nothing.

Example Code

The following code disables and then enables serial communication.

void setup() {
  Serial.begin(9600);
  delay(1000); // Allow time for Serial Monitor to connect
  Serial.println("Hello from Serial!");

  Serial.end();  // Stop communication

  delay(2000);   // Simulate doing something else...

  Serial.begin(9600);  // Re-initialize serial
  Serial.println("Serial restarted!");
}

void loop() {
}