Read multiple char from USART int i, j;
char data;
int flag=0;

void loop() 
{
if(Serial.available() &gt; 0){
    data  = Serial.read();
    flag=0;
  }

  if (data == 'd' &amp;&amp; 'b') {
    digitalWrite(cONOF, HIGH);
  } else if (data == 't' &amp;&amp; 'w') {
    digitalWrite(cONOF, LOW);
  }


  if (data == 'y' &amp;&amp; 'w') {
    digitalWrite(start, HIGH);
    delay(2000);
    digitalWrite(start, LOW);
  }


  if (data == 'e' &amp;&amp; 'r' &amp;&amp; 'h' &amp;&amp; 'i') {
    for (i=0;i&lt;10;i++) {
      digitalWrite(horn, HIGH);
      delay(100);
      digitalWrite(horn, LOW);
      delay(100);
    }
    for (j=0;j&lt;10;j++) {
      digitalWrite(horn, HIGH);
      delay(500);
      digitalWrite(horn, LOW);
      delay(500);
    }
    digitalWrite(horn, LOW);
  }

}


I want to read data from the USART where the messages have more than one character. I tried the code above but it doesn't work well. For example, I want to send the message 'db' to turn the output on, but just sending 'd' also turns it on, how do I fix this?
You need split the reading into two processes - storing the characters and checking if they are the right message.

To store the characters for example:

String message = "";

void loop() 
{
while(Serial.available()) {
    char b = Serial.read();

    if (b == '\r') {
        processMessage();
        message = "";
    }
    else {
        message += b;
    }
}
}


The process might look like

void processMessage() {

    if (message == "fb") {
         foo();
    }
    else if (message == "bf") {
         bar();
    }
}


I just use the Messenger library usually. But note you have to change WProgram.h to Arduino.h in Messenger.cpp to get it to work.