Serial Input controls outputs

I am having some issues and hope you guys here might be able to help me, i am writing a program that takes a command from a PC and toggles outputs high or low based off the command the arduino receives. I struggled to find a working example to use to start from but eventually found something that works. However, the example i found simply takes that data inputed to the serial port and prints it back out, i did get it to control output pins but i need it to be a bit more selective by if it gets this command these pins go high and these pins go low but the statement where the data is sent to be printed and where i have the digitalwrite for the pins wont allow me to add a && (receivedChars == "CH002") at the bottom under void shownewdata the program doesnt work, if you enter CH002; in the terminal it doesnt print or toggle the pins like its supposed to, if you get rid of && (receivedChars == "CH002") and enter CH002 it works but then its not selective and soaly prints out what input it received . Ultimately im going to have several commands like CH002 that are going to toggle pins and would like to get the code to be more selective.

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
const int cs1pin = 2; // 
const int cs2pin = 3; // 
const int cs3pin = 4; // 
const int cs4pin = 5; //
const int cs5pin = 6; // 

 

boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
    pinMode(cs1pin, OUTPUT);
    pinMode(cs2pin, OUTPUT);
    pinMode(cs3pin, OUTPUT);
    pinMode(cs4pin, OUTPUT);
    pinMode(cs5pin, OUTPUT);
}

void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = ';';
    char rc;
   
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
            
        }
    }
}

void showNewData() {

    if ((newData == true) && (receivedChars == "CH002")) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        digitalWrite(cs1pin, LOW);
        digitalWrite(cs2pin, HIGH);
        digitalWrite(cs3pin, LOW);
        digitalWrite(cs4pin, LOW);
        digitalWrite(cs5pin, LOW);
        newData = false;


    } 
}

You cannot compare the values of two char arrays using ==.

Use strcmp()

Do you have an example of where i can start with using strcmp() for my purpose?

I use the CplusPlus website as my reference strcmp()

...R

flux4201:
Do you have an example of where i can start with using strcmp() for my purpose?

When you enter this string: "Ignite L" from the InputBox of Serial Monitor with Line ending tab at Newline option, only then the built-in LED (L) of the UNO Board will ignite. For any other entered string, the L will remain OFF.

char myChar[20] = "";

void setup() 
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW); //L is initially OFF

}

void loop() 
{
  byte n = Serial.available();
  if(n != 0)
  {
    byte n = Serial.readBytesUntil('\n', myChar, 20); //receive chars until Newline char ('\n' = 0x0A arrives
    myChar[n] = '\0';   //insert null character
    int x = strcmp(myChar, "Ignite L"); //comparing two strings; x= 0 when matching happens
    if( x == 0)
    {
      digitalWrite(LED_BUILTIN, HIGH);  //strings have matched; L is ON
    }
    else
    {
      digitalWrite(LED_BUILTIN, LOW); //for other string received; L is OFF
    }
  }

}

GolamMostafa:
When you enter this string: "Ignite L" from the InputBox of Serial Monitor with Line ending tab at Newline option, only then the built-in LED (L) of the UNO Board will ignite. For any other entered string, the L will remain OFF.

char myChar[20] = "";

void setup()
{
 Serial.begin(9600);
 pinMode(LED_BUILTIN, OUTPUT);
 digitalWrite(LED_BUILTIN, LOW); //L is initially OFF

}

void loop()
{
 byte n = Serial.available();
 if(n != 0)
 {
   byte n = Serial.readBytesUntil('\n', myChar, 20); //receive chars until Newline char ('\n' = 0x0A arrives
   myChar[n] = '\0';   //insert null character
   int x = strcmp(myChar, "Ignite L"); //comparing two strings; x= 0 when matching happens
   if( x == 0)
   {
     digitalWrite(LED_BUILTIN, HIGH);  //strings have matched; L is ON
   }
   else
   {
     digitalWrite(LED_BUILTIN, LOW); //for other string received; L is OFF
   }
 }

}

Thanks, this is good but for my case i dont need a if / else like what you gave an example of, for my project, the arduino would need to accept about 50 different commands (CHxxx, where xxx is a combination of different numbers) to change the state of groups of outputs. I played with the code a bit attempting to modify it but with my limited knowledge of C++ i wasnt able to make anything work well to suit my needs. I am taking code i wrote in basic many years ago (and lost) and attempting to move it over to C++. Any help would be greatly appreciated.