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().
Use the following function to disable the Serial communication:
Serial.end()
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.
The function returns nothing.
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() {
}