Description

Waits for the transmission of outgoing serial data to complete.

flush() inherits from the Stream utility class.

Syntax

Use the following function to wait for the buffered outgoing data to be sent:

Serial.flush()

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 waits until the whole serial buffer is sent, then turns on an LED:

void setup() {
  Serial.begin(9600);
  
  Serial.print("Sending... "); // this could be a large amount of data
  Serial.flush();  // Waits until everything above is actually sent
  digitalWrite(LED_BUILTIN, HIGH); // Only turns LED on after data is sent
}

void loop() {
}

See also