Serial Communication Issues

So am having an issue getting my Robot code to work right. Its run through Windows 10 via Serial Com.

The Line BIGSERVOSW works when the button is pressed (and held), But it will not activate when Serial COM 5 is sent.

Same thing with the EXTRASERVO at the bottom.

I can not figure out why it work work with serial communication.

I also realize the very last item is not correct i am working on that yet/need to figure that out as well

PROGRAM:

#include <Servo.h>
#define BIGSERVOSW 5
#define EXTRASERVOSW 4
#define ROCK1 2
#define ROCK2 3
#define ROCKETFIRE1 12
#define ROCKETFIRE2 11
#define LED 10

Servo DoorServo;
Servo servo2;
Servo servo3;
char c;
String cmd = "";
void setup() {
 // put your setup code here, to run once:
pinMode(BIGSERVOSW, INPUT);
pinMode(EXTRASERVOSW, INPUT);
pinMode(ROCK1, INPUT);
pinMode(ROCK2, INPUT);
pinMode(ROCKETFIRE1, OUTPUT);
pinMode(ROCKETFIRE2, OUTPUT);
pinMode(LED,OUTPUT);
DoorServo.attach(7);
servo2.attach(6);
servo3.attach(9);
// LETS PULL UP THE INPUTS
digitalWrite(BIGSERVOSW, HIGH); 
digitalWrite(EXTRASERVOSW, HIGH); 
digitalWrite(ROCK1, HIGH); 
digitalWrite(ROCK2, HIGH); 
DoorServo.write(0);
servo2.write(0);
servo3.write(0);
Serial.begin(9600);
digitalWrite(ROCKETFIRE1, LOW);  //get back to default 
digitalWrite(ROCKETFIRE2, LOW);  //get back to default 
digitalWrite(LED, LOW); 
}
void loop() {
 // put your main code here, to run repeatedly:
getSerial();
// Check for bigservo switch
if ( digitalRead(BIGSERVOSW) == LOW || cmd == "5")
{ 
 /* according to "Then a Separate servo with its own button when pressed
moves a Large servo 120 degrees then returns when you let of the button" */
 servo2.write(120);
 while( servo2.read() != 120)  //do nothing till servo come to 120
 {}
 Serial.println(" BIGSERVO 120deg arrived " );
 servo2.write(0);     //bring servo back to 0
 delay(500);     //for debounce
}
else if ( digitalRead(ROCK1) == LOW || cmd == "1")
{
 Serial.println(" ROCK1 pressed" );
 DoorServo.write(95);  // open the door for 95 deg
 
 while( DoorServo.read() != 95)  //do nothing till servo come to 95
 {}
 delay(1000);         // dealy for 1 sec
 digitalWrite(ROCKETFIRE1, HIGH);  //fire the rocket 1 
 delay(2000);          //delay for 2 sec
 digitalWrite(ROCKETFIRE1, LOW);  //get back to default 
 Serial.println(" Rocket low" );
 delay(1000); 
 DoorServo.write(0);  // close the door again 0deg
 while( DoorServo.read() != 0)  //do nothing till servo come to 0
 {}
 Serial.println(" Door closed" );
 delay(500);    //for debounce
 cmd = "";
}
else if ( digitalRead(ROCK2) == LOW || cmd == "2" )
{
 DoorServo.write(95);  // open the door for 95 deg
 Serial.println(" Door opened" );
 while( DoorServo.read() != 95)  //do nothing till servo come to 95
 {}
 delay(1000);         // dealy for 1 sec
 digitalWrite(ROCKETFIRE2, HIGH);  //fire the rocket 1 
 delay(2000);          //delay for 2 sec
 digitalWrite(ROCKETFIRE2, LOW);  //get back to default 
 delay(1000); 
 DoorServo.write(0);  // close the door again 0deg
 while( DoorServo.read() != 0)  //do nothing till servo come to 0
 {}
 Serial.println(" Door closed" );
 delay(500);    //for debounce
 cmd = "";
}
else if ( digitalRead(EXTRASERVOSW) == LOW || cmd == "3")
{
 Serial.println(" EXTRASERVO Pressed" );
 /* according to "Then a Separate servo with its own button when pressed
moves a Large servo 120 degrees then returns when you let of the button" */
 
 servo3.write(120);
 while( servo3.read() != 120)  //do nothing till servo come to 120
 {}
 Serial.println(" EXTRASERVO 120deg arrived " );
 while ( digitalRead(EXTRASERVOSW) == LOW || cmd == "EXTRASERVOSW")  //do nothing till switch is being pressed.
 {getSerial();}
 Serial.println(" switch released" );
 servo3.write(0);     //bring servo back to 0
 delay(500);     //for debounce
}
if ( digitalRead(LED) == HIGH || cmd == "6" )
{
 digitalWrite(LED, HIGH); 
}
if ( digitalRead(LED) == LOW || cmd == "8" )
{
 digitalWrite(LED, LOW); 
}


else if ( digitalRead (ROCK1) == LOW ||cmd == "7" ) 
{
 DoorServo.write(95);  // open the door for 95 deg
 Serial.println(" Door opened" );
 while( DoorServo.read() != 95)  //do nothing till servo come to 95
 {}
 delay(1000);         // dealy for 1 sec
 digitalWrite(ROCKETFIRE1, HIGH);  //fire the rocket 1 
 delay(1000);         // dealy for 1 sec
 digitalWrite(ROCKETFIRE2, HIGH);  //fire the rocket 2 
 delay(2500);     //delay for 2 sec
 digitalWrite(ROCKETFIRE1, LOW);
 digitalWrite(ROCKETFIRE2, LOW);  // get back to default 
 delay(2000); 
 DoorServo.write(0);  // close the door again 0deg
 while( DoorServo.read() != 0)  //do nothing till servo come to 0
 {}
 Serial.println(" Door closed" );
 delay(500);    //for debounce
 cmd = "";
}
}
void getSerial(){
 cmd = "";
 if(Serial.available()>0){
 cmd = "";
 c = Serial.read();
 cmd = c;
 while(Serial.available()>0){
   cmd.concat((char)Serial.read());
 }
}
}
  while( servo2.read() != 120)

Servo.read does not return the position of the servo, it returns the last position sent to the servo. Servo.read will not change till you send another servo.write or servo.writeMilliseconds. The wording of the reference entry is, I believe, ambiguous and leads some to believe that it returns the actual position of the servo. It does not.

Please read the "how to use the forum" stickies to see how to format and post code.

Have a look at serial input basics to see how to do serial communication.

You have no discipline for separating commands on the serial stream. Because you are using
delay(), you cannot assume only one command will be received before getSerial() is called.

Typically you will get line breaks in cmd, and as you don't strip these out before trying
to match command strings, it is likely to mainly fail.

I suggest the easiest thing is to read a single character only in getSerial for now.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

If you want a responsive program you need to get rid of ALL the delay()s. Have a look at how millis() is used to manage timing without blocking in Several things at a time

And please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

...R

Wow thanks a lot guys!
I am very new to programming so sorry for the mess.

I dont really understand exactly what you mean by separating the commands.
Do you mean i should use the servomilli?

also line breaks for cmd?

MarkT:
You have no discipline for separating commands on the serial stream. Because you are using
delay(), you cannot assume only one command will be received before getSerial() is called.

Typically you will get line breaks in cmd, and as you don't strip these out before trying
to match command strings, it is likely to mainly fail.

I suggest the easiest thing is to read a single character only in getSerial for now.

StrikeforcePC:
I dont really understand exactly what you mean by separating the commands.
Do you mean i should use the servomilli?

also line breaks for cmd?

If you study my links and try my serial input examples I suspect what @MarkT has said will make more sense.

...R