Multiple Button Motion Control

I have setup 3 buttons and everything works well with 1 or 2 but when I add the 3rd the troubles start. I am using the buttons to control the motor. One buttons turns clockwise, another counterclockwise, and another turns clockwise then turns counter clockwise.

The problem occurs when I add the 3rd button the motor will turn when I’m not pressing anything, or I’ll press a button and when I let go it still moves. I have debounced everything. Any suggestions appreciated.

Photo of my setup
http://www.jbdstudio.com/image.html

//set pins
int scanButtonPin = 2;  //start scan button
int jogHighButtonPin = 4;  //jog button
int jogLowButtonPin = 7;  //jog button
int dirPin = 8;      //stepper direction
int stepPin = 12;    //stepper step

//set vars
int scanButtonstate = 0;
int jogHighButtonstate = 0;
int jogLowButtonstate = 0;
int startScan = 0;
int i;

//setup loop
void setup() {

  pinMode(scanButtonPin, INPUT);
  pinMode(jogHighButtonPin, INPUT);
  pinMode(jogLowButtonPin, INPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);

}


//begin loop
void loop() {

//START SCAN WHEN BUTTON PRESSED   

  //read the scan input pin
  scanButtonstate = digitalRead(scanButtonPin);

  //check for button press
  if (scanButtonstate == HIGH) {
    
     //SINGLE SCAN PASS
      // Set the direction.
      digitalWrite(dirPin, HIGH);     
      delay(100);
    
      // scan for i microsteps
      for (i = 0; i<2000; i++) {
        // step signal
        digitalWrite(stepPin, LOW);  
        digitalWrite(stepPin, HIGH);
        // delay controls speed 
        delayMicroseconds(200);       //replace with delay(25) to scan speed            
      }                              
      
      // change direction
      digitalWrite(dirPin, LOW);
      delay(100);
    
      // rewind i microsteps
      for (i = 0; i<2000; i++) {
        // step signal
        digitalWrite(stepPin, LOW);  
        digitalWrite(stepPin, HIGH);
        // delay controls speed 
        delayMicroseconds(500);         //replace with delay(25) to scan speed            
      }   
  }        

//JOG THE MOTOR

  //read the jog high input pin
  jogHighButtonstate = digitalRead(jogHighButtonPin);

  while (jogHighButtonstate == HIGH) {
      // Set the direction.
      digitalWrite(dirPin, HIGH);     
      delayMicroseconds(200);
   
      digitalWrite(stepPin, LOW);  
      digitalWrite(stepPin, HIGH);
      // delay controls speed 
      delayMicroseconds(100);     //change to 200
      
      jogHighButtonstate = digitalRead(jogHighButtonPin);
      delayMicroseconds(200);
  }
  
    //read the jog low input pin
  jogLowButtonstate = digitalRead(jogLowButtonPin);

  while (jogLowButtonstate == HIGH) {
      // Set the direction.
      digitalWrite(dirPin, LOW);     
      delayMicroseconds(200);
   
      digitalWrite(stepPin, LOW);  
      digitalWrite(stepPin, HIGH);
      // delay controls speed 
      delayMicroseconds(100);       //change to 200
      
      jogLowButtonstate = digitalRead(jogLowButtonPin);
      delayMicroseconds(200);
  }

}

Difficult to tell from the photo what is connected to what, or what the values of the pullup/downs are. Which is the third button you've added? Can you elucidate, please?

added more images http://www.jbdstudio.com/image.html

10K pull down resistors

The 3rd button is the right-most one.

I've tried other inputs and other positions on the breadboard with not luck.

I think it's my wiring logic, but not sure.

Don't use pull down resistors use pull up resistors and connect the button between the arduino input and ground. A 10K pull down will give you poor noise immunity. If you must use pull downs make them 1K but pull ups are better.

Grumpy,

The pull up resistor configuration did the trick. My noise issues are gone. Thanks for the advice.

Brian