Removing Garbage from Serial

Greetings

I'm working on a heavy duty project where I have 2 step motors that are being controlled by arduino; However when I send an arduino signal I send a lot of garbage with it. My baud rates match and if I send my signals through the computer it works perfectly fine. The idea is that when i send a signal it has to repeat this signal so the motors spin, but due to the garbage being send it repeats the garbage, which does is not a valid signal for the motor to spin (valid signals are W, A, S, D, '/' (to stop the motors)). When I check the serial monitor I see that the step motors take one step, then it sends the letter I put in and then it starts repeating the garbage.
Could someone help me please? I was thinking maybe excluding all signals except for W, S, D, A and another one to stop the motors?

Credit for the code goes to someone else, I dont remember where I got it from tho...

#include <SoftwareSerial.h>
#include <Stepper.h>

#define COMMAND_LEFT 'a'
#define COMMAND_RIGHT 'd'
#define COMMAND_FORWARD 'w'
#define COMMAND_BACK 's'
#define COMMAND_STOP ' '

SoftwareSerial BlauweTand(2, 3);

int stepsInRev = 200;

int num_of_steps = 1;

Stepper myStepper1(stepsInRev, 4, 5, 6, 7);
Stepper myStepper2(stepsInRev, 10, 11, 12, 13);

char lastCall = ' ';

void forwardStep(int steps) {
  BlauweTand.println("forward");
  myStepper1.step(1);
  myStepper2.step(1);
  delay(10);
}
void backwardStep(int steps) {
  BlauweTand.println("backward");
  myStepper1.step(-1);
  myStepper2.step(-1);
  delay(10);
}
void leftStep(int steps) {
  BlauweTand.println("left");
  myStepper1.step(1);
  myStepper2.step(-1);
  delay(10);
}
void rightStep(int steps) {
  BlauweTand.println("right");
  myStepper1.step(-1);
  myStepper2.step(1);
  delay(10);
}
void allStop() {
  BlauweTand.println("stop");
  PORTD = B00000000;
  PORTB = B00000000;
}
void setup() {
  Serial.begin(9600);
  BlauweTand.begin(9600);
  myStepper1.setSpeed(100);
  myStepper2.setSpeed(100);
}
void loop() {
  if (BlauweTand.available()) {
    char data = (char)BlauweTand.read();
    switch (data) {
      case COMMAND_FORWARD:
        forwardStep(num_of_steps);
        Serial.println("Vooruit");
        break;
      case COMMAND_BACK:
        backwardStep(num_of_steps);
        Serial.println("Achteruit");
        break;
      case COMMAND_LEFT:
        leftStep(num_of_steps);
        Serial.println("Links");
        break;
      case COMMAND_RIGHT:
        rightStep(num_of_steps);
        Serial.println("Rechts");
        break;
      case COMMAND_STOP:
        allStop();
        break;
    }
    Serial.println(lastCall);
    lastCall = data;
    Serial.println(lastCall);
    
  }
  else {
    char data = lastCall;
    Serial.println(lastCall);
    switch (data) {
      case COMMAND_FORWARD:
        forwardStep(num_of_steps);
        break;
      case COMMAND_BACK:
        backwardStep(num_of_steps);
        break;
      case COMMAND_LEFT:
        leftStep(num_of_steps);
        break;
      case COMMAND_RIGHT:
        rightStep(num_of_steps);
        break;
      case COMMAND_STOP:
        allStop();
        break;
    }
    lastCall = data;
  }
}

1. You are sending one of the following commands from the InputBox of the Serial Monitor (Fig-1):

a for COMMAND_LEFT
d for COMMAND_RIGHT
w for COMMAND_FORWARD
s for COMMAND_BACK
/ for COMMAND_STOP

SerialMonitor.png
Figure-1:

2. Please, be sure which one of the following options of the 'Line ending tab' of the Serial Monitor you want to select that would be sent as a character (s) after your command character of Step-1.

No line ending -- nothing will be sent
Newline -- 0x0A (\n) will be sent
Carriage return -- 0x0D (\r) will be sent
Both NL&CR -- 0x0D is sent first and then 0x0A is sent

I would suggest to choose 'No line ending' option.

3. The following coding style for the UART receiver seems logical to me:

void loop()
{
   byte n = BlauweTand.available();
   if(n !=0)
   {
       char data = BlauweTand.read();   //no need cast
       //----------------------------------------------------
       switch (data)
    {
      case COMMAND_FORWARD:
        {
          forwardStep(num_of_steps);
          Serial.println("Vooruit");
          break;
        }
      case COMMAND_BACK:
        {
          backwardStep(num_of_steps);
          Serial.println("Achteruit");
          break;
        }
      case COMMAND_LEFT:
        {
          leftStep(num_of_steps);
          Serial.println("Links");
          break;
        }
      case COMMAND_RIGHT:
        {
          rightStep(num_of_steps);
          Serial.println("Rechts");
          break;
        }
      case COMMAND_STOP:
        {
          allStop();
          break;
        }
   }
}

SerialMonitor.png

[size=small][Color=red]BlauweTand[/Color][/size]

You remind me of an ex-colleague from years ago; facebook = smoelenboek

For those that ain't familiar with the Dutch language
BlauweTand is a literal translation of Blue (blauw) Tooth (tand).

sterretje:
BlauweTand is a literal translation of Blue (blauw) Tooth (tand).

Kinda guessed that.