Code operates and ignores the input states...why

Uno with breakout board.

I have a basic robot car that uses ultrasonic to avoid solid objects. This works ok, but now added a bumper bar with three micro switches…Left, Right and Centre.

Wired as here…

micswitch n/c 22k
pos + —o____o-----|–VVVVV---- -ve Three off.
o |
|
i/p pin

The Micro switch motor control code always operates what ever the input is, tried it on pins 10,9,8 and still a problem.

It ignores the logic HIGH or LOW, any ideas anyone as to why this is happening.

#include <Servo.h> 
#include <NewPing.h>

// Pins on the Arduino Sensor Shield v5.0
#define SONAR_SERVO_PIN 4
#define TRIGGER_PIN     A0
#define ECHO_PIN        A1

#define MAX_DISTANCE    200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myServo;

// Motor A [Right Side]
const int enA = 13;
const int in1 = 12;
const int in2 = 11;
// Motor B [Left Side]
const int enB = 5;
const int in3 = 7;
const int in4 = 6;

const int triggerDistance = 20;

 //Define Bumper Bar
const int leftbumpPin = 3;//Left Bumper micro switch
const int rightbumpPin = 2;//Right Bumper micro switch
const int centerbumpPin = 1;//Centre Bumper micro switch
int leftBump;
int rightBump;
int centerBump;
// Variables
unsigned int time;            // to store how long it takes for the ultrasonic wave to come back
int distance;                 // to store the distance calculated from the sensor
int fDistance;                // to store the distance in front of the robot
int lDistance;                // to store the distance on the left side of the robot
int rDistance;                // to store the distance on the right side of the robot


char dist[3];
char rot[3];
int rotation = 0;
String output = "";

void setup() 
{ 
 //Bumper pin set up to inputs         micswitch n/c       22k
 pinMode(leftbumpPin,INPUT);    // pos + ---o____o-----|--VVVVV---- -ve
 pinMode(rightbumpPin,INPUT);   //               o     |  
 pinMode(centerbumpPin,INPUT);  //                     |                   
                                //                   i/p pin
 //Sonar Pin set up
  pinMode (TRIGGER_PIN, OUTPUT);
  pinMode (ECHO_PIN, INPUT);
  myServo.attach(SONAR_SERVO_PIN);  // Attaches the Servo to the Servo Object 

  // set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
} 

void loop()
{
 //Read Bumper input pins
 leftBump=digitalRead(leftbumpPin);
 rightBump=digitalRead(rightbumpPin);
 centerBump=digitalRead(centerbumpPin);

//if (leftBump == LOW);{
//  moveRight(200);
//  delay (1500);
//  moveStop();
//}

//if (rightBump == LOW);{
 // moveLeft(200);
 //delay(1500);
//moveStop();
//}

if (centerBump == LOW);{
   moveBackwards(200);
   delay(1500);
   moveStop();
 }
 
  scan();                                //Get the distance retrieved
  fDistance = distance;
  if(fDistance < triggerDistance){
    moveBackwards(200);
    delay(1500); 
    moveRight(255);
    delay(1200);
    moveStop();
    scan();
    rDistance = distance;
    moveLeft(200);
    delay(1200);
    moveStop();
    scan();
    lDistance = distance;
    if(lDistance < rDistance){
      moveRight(200);
      delay(1200);
      moveForward(200);
    }
    else{
      moveForward(200);
    }
  }
  else{
    moveForward(200
    );
  }
}

void scan()
{
  int deg = 90;
  myServo.write(deg);
  delay(10);

  time = sonar.ping();
  distance = time / US_ROUNDTRIP_CM;
  delay(10);
  if(distance <= 0){
    distance = triggerDistance;
  }

  delay(30);
}

void moveForward(int speed)
{
  // turn on motor A
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);

  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  analogWrite(enA, speed);
  analogWrite(enB, speed);
}

void moveBackwards(int speed)
{
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);

  // turn on motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);

  analogWrite(enA, speed);
  analogWrite(enB, speed);
}

void moveRight(int speed)
{
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);

  // turn off motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  analogWrite(enA, speed);
  analogWrite(enB, speed);
}

void moveLeft(int speed)
{
  // turn on motor A
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);

  // turn off motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);

  analogWrite(enA, speed);
  analogWrite(enB, speed);
}

void moveStop()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);

  delay(200);
}

  if (centerBump == LOW);Whoops !

ooops indeed, Specsavers comes too mind.....Thanks

I note that you have other instances of the same problem in lines commented out

I commented them out so it would be easier to find the fault... :( ..Doh. I now read the pin state in the if statement, bit cleaner.. I stared and stared and did not see my typo...all well now..thanks.

I now read the pin state in the if statement, bit cleaner..

but not so easy to debug if you need to. By putting the pin state in a variable you can print is value should you need to.

Yes, true and I have gone back too the original after you pointed out that reason..thank you