title: How to capture a variable stream of characters and process them on a Arduino using serial?
body: <p>I'm trying to read variable streams of characters and process them on the Arduino once a certain string of bytes is read on the Arduino. I have a sample <a href="http://www.arduino.cc/en/Tutorial/Sketch" rel="nofollow">sketch</a> like the following, but I can't figure out how to compare the "readString" to process something on the Arduino. I would like the Arduino to process "commands" such as {blink}, {open_valve}, {close_valve}, etc.</p>
  
  <pre><code>// Serial - read bytes into string variable for string
  String readString;
  
  // Arduino serial read - example
  int incomingByte;
  
  // flow_A LED
  int led = 4;
  
  void setup() {
      Serial.begin(2400);  // Open serial port and set Baud rate to 2400.
      Serial.write("Power on test");
  }
  
  void loop() {
      while (Serial.available()) {
        delay(10);
        if (Serial.available() &gt; 0) {
            char c = Serial.read(); // Gets one byte from serial buffer
            readString += c; // Makes the string readString
        }
      }
  
      if (readString.length() &gt; 0) {
          Serial.println( readString); // See what was received
      }
  
      if (readString == '{blink_Flow_A}') {
          digitalWrite(led, HIGH); // Turn the LED on (HIGH is the voltage level).
          delay(1000);             // Wait for one second.
          digitalWrite(led, LOW);  // Turn the LED off by making the voltage LOW.
          delay(1000);             // Wait for a second.
      }
  </code></pre>