Arduino Serial Flush

Ammar Ali Oct 12, 2023
Arduino Serial Flush

In this tutorial, we will discuss how we can check if the serial transmission is done or not using the Serial.flush() function in Arduino.

Check if the Serial Transmission Is Done or Not Using the Serial.flush() Function in Arduino

When we transmit data from serial, the data is placed in a buffer, and the program moves to the next statement, and the data is transmitted slowly from the buffer because serial is slow. If you don’t want the program to move forward until the transmission is finished, you can use the Serial.flush() function to make sure all of the data is transmitted and the buffer is empty now. Using this function, your program will not move forward until the serial transmission is done.

void setup() { Serial.begin(9600); }
void loop() {
  Serial.print("Somthing");
  Serial.flush();
}

In the above code, we are printing a string on the serial monitor, and then we are checking if the serial transmission is done or not. If it’s done, the program will move forward to the next statement.

Author: Ammar Ali
Ammar Ali avatar Ammar Ali avatar

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.

LinkedIn Facebook

Related Article - Arduino Serial