/** * Author: Domenico Monaco * * Description: Simple Arduino Serial communication, with echo of entire line received. * * Source: https://gist.github.com/kiuz/d59519e0de7677df42c3/ * * License: GNU v2 2014 */ int incomingByte = 0; // for incoming serial data bool waiting = false; String line = ""; void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0) { waiting = false; // Set to false, Arduino not in "Waiting" state but are in "Reading" state incomingByte = Serial.read(); // read Char line = line + (char)incomingByte; // add Char to line delay(1); //Delay of Serial transfer speed }else{ //waiting is False only after "reading" state //with this line are printed only one times into "waiting" state if(waiting==false){ waiting = true; // print entire line Serial.print(line); Serial.print(" "); line = ""; // Resete line Serial.println(""); Serial.println("Waiting for a message..."); Serial.println("");} } }