SMS comparison problem

Hi guys im trying to compare the Content of SMS.
But i dont know how i should do this.
I know that in the example they use:
" while( (c = ! = -1)
Serialprintln ((char)c) ;
but i should compare the SMS and watch if it matches my keyword for Example "ON"
and i dont need to write it some where like in the example
and then do stuff but I just dont get it how i should code this...
pls help

I tried somethings like
if( c == "ON")

Look at this tutorial: Serial Input Basics - updated to learn how to read in a string and then act upon it. The tutorial is designed for Serial input, but will work for SMS input just as well.

i know how to read in a string so u mean i could do something like:
" for( i = 0; i<7; i ++)
Sms_String [i] = ;
if "Sms_String == "GO ON""
and here we have the same problem i cant compare with a string cause idk what to put in the braces [?] to use the whole string i dont need to use the braces right just the name so it doesnt have a Index?

string comparison is done with strcmp() or to find a substring within a string strstr()

Remember, when you use strcmp(), that it can return one of 3 values. Zero is for equality.

come on guys i have no clue how to solve this. And its a very important project to me.
strcmp just compares characters but gives a int back so this cant work.


Where was this argument when you tried:

Yeah ik this also dont work but that shows how desperate I am.
how can i solve this?

By using strcmp() or maybe strncmp() on the buffered output,
just like you tried with the direct comparison, which does not work.

strstr() could be useful also, it depends on the format of the message.

    String SmS [7];
    String Command [7];
    Command[1] = "O";
    Command[2] = "N";
    int i = 0;
      SmS[i] =;
   if ( (strcmp(SmS,Command)))
    Serial.println("\nOutput now ON");

ive used this now but there is a ERROR saying: "cannot convert 'arduino::String*' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'"
and btw could you tell me the diffrence between strcmp() and strncmp()? thx

Forget all that String crap and use a char array for storing the message,
which would be obvious, if you had looked at

1 Like
    char SmS [3];
    const char Command [3] = "ON";
   for(int i = 0;i<3;i++)
      SmS[i] =;
   if ( SmS == Command)
    Serial.println("\nOutput now ON");

ive used now char arrays and direct comparison but the if case still doesnt get true :frowning:

Do you read what we write? You were already told how to deal with that

I miss the closing zero on the SmS char array, it is filled with chars from some function.
Is it really guaranteed, that the third char is a zero?

1 Like

so i can use stringcomparison to arrays? okay u said i can forget about the string stuff

C-strings are char arrays, with a zero signaling the end of it.
strcmp(), strncmp(), strstr() work on those cstrings (zero terminated char arrays).


I said you should get rid of the String crap, which is a big difference.

1 Like

thx guys i made it and thank you for your patience :sweat_smile: