void loop() { int voice; int freq; // send data only when you receive data: if (Serial.available()) //there is a byte { //is it the header?? if (Serial.read() == 171) // ab hex { while(Serial.available() <= 1) //wait for two bytes { } voice = Serial.read(); freq = Serial.read(); // say what you got: Serial.print(voice); Serial.print("-"); Serial.println(freq); write_pot(voice,freq); }else{ Serial.println("wrong header received flushing buffer"); Serial.flush(); } } }