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.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Arduino Serial

  • Arduino Clear Serial Monitor
  • Arduino Serial Read String