Clearing serial buffer solved

I tried all the methods in this thread, with mixed results.

What worked for me was the following, the value of 10 on the loop was arbitrary, this can be tuned for your needs:

//clear out the serial buffer

byte w = 0;

for (int i = 0; i < 10; i++)
{
while (Serial.available() > 0)
{
char k = Serial.read();
w++;
delay(1);
}
delay(1);
}

arduinoenigma.blogspot.com

1 Like