Serial communication problem

Hello, i want to send specific message(letter “D”) to arduino from my pc and receive some data. The problem is that when I send something like “abcD” arduino still recognizes it as a request for data. If i send in example “DDD” I receive the data three times and I don’t want to. Here is a part of my code.

void loop()
{
  if(Serial.available() == 1)
{

char READ = Serial.read();
if(DATAA == READ)

{
dhtsensor();
Serial.print("H");
Serial.print(h);
Serial.print("T");
Serial.println(t);
}


}
}

I’ve tried this if(Serial.available() == 1 && Serial.available() < 2) and it still doesn’t work.
I hope to get some response :slight_smile: , thank you

there is also this line "char DATAA = 'D';"

If i send in example "DDD" I receive the data three times and I don't want to.

There's a really, really obvious fix for that. Don't send "DDD"

Yeah :D , but how to accept serial data if its only 1 character and deny everything else. Or it's just not possible?

But "DDD" is simply one character sent three times. Are you looking for some sort of timeout?

The examples in serial input basics show simple reliable ways to receive data.

After you have received all the data you can decide what to do with it.

...R

MOKA12: Yeah :D , but how to accept serial data if its only 1 character and deny everything else. Or it's just not possible?

So how does the arduino know the difference between what is "everything else" and new commands being sent? End of data markers are usually included with commands.

End of data markers are usually included with commands.

Nice to see you come around. Now, if you could just move away from Strings. 8)

Sometimes, the markers indicate the start of the next packet, meaning that the end of the previous one has arrived and the data can be dealt with.