Serial.begin causes unpredicatble behaviour.

Hello there. new to arduino here and loving it, but have hit a wall with a small project.

my sketch works fine, until I want to see some info printed in the Serial monitor. it is a small circuit built on an Arduino Uno + motor shield exactly like this photo, with the addition of a push button:

push button once to turn the motor for 2 seconds, then wait 4, then reverse 2 seconds. works perfectly fine until I insert a Serial.begin(9600) command, then it behaves as if the button is continually being pressed. motor speeds up, pauses reverses over and over again. what is the problem?

thanks for any suggestions!

relevant code from working version - Serial commands are commented and pushed to the right for simplicity:

int switchPin = 2;
int val;
void setup() {
  
                                                                                 //  Serial.begin(9600);
                                                                                 //   Serial.println("Waiting for button push...");

  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(switchPin, INPUT); 

}

void loop(){
                            // READ DATA
 val = digitalRead(switchPin);   // read input value and store it in val
  if (val == LOW) 
  {                           //ENGAGE MOTOR & RAISE LID
                                                                                     //        Serial.println("button press detected");
        digitalWrite(12, HIGH); //Establishes forward direction of Channel A
        digitalWrite(9, LOW);   //Disengage the Brake for Channel A
        analogWrite(3, 35);   //Spins the motor on Channel A at full speed
      
        delay(1000);
        analogWrite(9, HIGH);//Engage the Brake for Channel A
//        delay(2000);
        val = digitalRead(switchPin);   // CHECK TO SEE IF BUTTON STILL PUSHED
        if (val == LOW) // IF PRESSED
          {
//            delay(2000);
          } else {
          digitalWrite(9, HIGH); //Eengage the Brake for Channel A
          delay(3000);
          digitalWrite(12, LOW); //Establishes forward direction of Channel A
          digitalWrite(9, LOW);   //Disengage the Brake for Channel A
          analogWrite(3, 35);   //Spins the motor on Channel A
          delay(1000);
          digitalWrite(9, HIGH); //Engage the Brake for Channel A
       
          }

  }
    }
}

Maybe you have something connected to the RX or TX pins (pin 0 or pin 1)? Please describe the odd behaviour.

the odd behavior is this: when I add just Serial.begin(9600); into the setup of the sketch, it stops working entirely. when I add a Serial.println in, the motor turns thru it’s patterns as if the button is always being pushed.

is it possible that the Motor Shield is somehow causing this problem with Serial.begin? I’m probably showing my noobness here… thanks!

relevant code

My guess is that the irrelevant code that you left out is causing the problem.

Pete

I found my problem. wiring issue. MODERATORS: you can delete this thread. I don't think it will be helpful to anyone.

thanks.

I don't think it will be helpful to anyone.

Sure it will. See reply # 3.