Button being ignored

The if (digitalRead(Limit_1) == LOW) is being ignored.
I am not seeing any Serial.print() ouput.
My stepper motor is running.
digitalWrite(ENA, LOW); "should" stop the motor.

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;
const int ENA = 4;
//int Limit_1 = 11;
int Limit_1 = A5;
//int ENA = 4;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
  Serial.begin(115200);

   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   myStepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]

    pinMode(Limit_1,INPUT_PULLUP);
    //pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
    //digitalWrite(ENA, HIGH);
    //digitalWrite(Limit_1, HIGH);
}

void loop()
{  
  
  if (digitalRead(Limit_1) == LOW)
  //if (digitalRead(Limit_1) == HIGH)
  {
    digitalWrite(ENA, LOW);
    //ENA = LOW;
    //ENA = HIGH;
    Serial.print(digitalRead(Limit_1));
    Serial.print("++++"); 
    //Serial.println(ENA);
    Serial.println(digitalRead(ENA));
  }
   myStepper.runSpeed();   // This will run the motor forever.
}
       

Ralph

Maybe it is wired wrong in the schematic you didn't post.

2 Likes
  if (digitalRead(Limit_1) == LOW)
  //if (digitalRead(Limit_1) == HIGH)

You tried both of the above and nothing is printed for either one?

1 Like

Yes I tried both.

The switch is just wired to ground and A5.

Do you really want a schematic?

Ralph

Given that the other pins used are digital pins, but you've specified that your switch is wired to an analogue pin, I don't think it's unreasonable.

I have tried using the digital pins with the same results.
So I switched to the Analog just to see if it made a difference.
No difference.

Ralph

Hello
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.

The code is posted in my first post.
But here ya go again.

// motor runs
// Include the AccelStepper Library
#include <AccelStepper.h>

const int dirPin = 6;
const int stepPin = 7;
const int ENA = 4;
//int Limit_1 = 11;
int Limit_1 = A5;
//int ENA = 4;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup()
{  
  Serial.begin(115200);

   myStepper.setMaxSpeed(5000);   // this limits the value of setSpeed(). Raise it if you like. 15000 does not work
   myStepper.setSpeed(1000);   // [12495 works with METRO 12500 does not work]

    pinMode(Limit_1,INPUT_PULLUP);
    pinMode(ENA, OUTPUT);    // sets the digital pin 4 as output
    //digitalWrite(ENA, HIGH);
    //digitalWrite(Limit_1, HIGH);
}

void loop()
{  
  
  if (digitalRead(Limit_1) == LOW)    //being ignored button press makes no difference. No Serial.print() output.
  //if (digitalRead(Limit_1) == HIGH)
  {
    digitalWrite(ENA, LOW);
    //ENA = LOW;
    //ENA = HIGH;
    Serial.print(digitalRead(Limit_1));    //Nothing
    Serial.print("++++"); 
    //Serial.println(ENA);
    Serial.println(digitalRead(ENA));
  }
   myStepper.runSpeed();   // This will run the motor forever.
}
     

I would double check the switch connection to GND and the cables. And the switch itself...

Everything has been triple checked and used on other sketches so I know the switch and wiring works!

Ralph

One more time :wink: .


Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.


const byte Limit_1 = A5;

void setup()
{  
  Serial.begin(115200);

    pinMode(Limit_1, INPUT_PULLUP);
}

void loop()
{  
    Serial.println(digitalRead(Limit_1) == HIGH ? "HIGH" : "LOW");
}
       

Disconnect everything from the Arduino except the usb cable and the button. Do you see anything on serial monitor like that?

I see:

HIGH
HIGH
?

Ralph

I'd be very worried if I saw '?'

Looks like you've broken something, badly.

OK, you don’t see where we are going with this?

Place a jumper between A4 and ground and see what happens…

And if your switch won’t do that, you broke your need a new switch. :expressionless:

a7

1 Like

Which motor driver? Maybe LOW IS enable.

const byte Limit_1 = A5;

No. The jumper goes from A5 to ground for Ralph to see

LOW
LOW

Going A5 to ground is the same as the switch.

The switch is working. I can use it with other sketches.

I am going to set up a new UNO with just a switch and a LED to demonstrate the problem.

Any one would be able to replicate easily what I am seeing.

I will even attempt to do a Fritzing schematic.

Ralph

LOL, I actually ‘fixed’ that from A0 after looking back at the code. THX.

a7