How to flush the input serial buffer in Arduino?
One possible approach is to read and discard everything for a fixed time, like a second. For example:



unsigned long now = millis ();
while (millis () - now &lt; 1000)
  Serial.read ();  // read and discard any input


I'm not a big fan of trying to "flush the input buffer". How do you know if a second is long enough? Or maybe it is too long? You are better off reading to some known delimiter.