int LED = 13; String inputString = ""; void setup() { Serial.begin(9600); inputString.reserve(24); pinMode(LED, OUTPUT); } void ReadSerial() { char inChar; while (Serial.available() > 0) { // get the new byte: inChar = Serial.read(); // add it to the inputString: if ((inChar != 10) && (inChar != 13)) // '\n\r' inputString.concat(inChar); else { if (inputString.indexOf("hello") >= 0) { // return to OS3D Serial.println("arduino"); } else if (inputString == "0" || inputString == "off") { digitalWrite(LED, LOW); // return to OS3D Serial.println("Led Off"); } else if (inputString == "1" || inputString == "on") { digitalWrite(LED, HIGH); // return to OS3D Serial.println("Led On"); } inputString = ""; } } Serial.flush(); } void loop() { ReadSerial(); }