Input Pull Up Issue

I have a pin that I'm using as an input pull up connected to a pushbutton and I have it printing the pin state back to the computer for troubleshooting. When the button is not pushed down the pin reads as a 1, like it should. However when pushed down, instead of reading zero because it's connected to ground, it doesn't read anything. Nothing prints out until the button is up again.

At first I thought it was a problem with the button but when I bypass the button and just directly connect the pin to ground I have the same issue. Could it just be a faulty pin? None of my other input pull up pins have been having this issue except for 13.

er 13 has always been a trouble maker cause "they" insist on putting an LED there, on the uno I think its buffered by an op amp but I dont have one so I cant say what effects that has on it

Yeah I figured that's why 13 doesn't work right but 6 gives me this same issue.

Then the most likely culprit is that you have a bug in your sketch or a problem with your wiring.

schoolsterz123:
However when pushed down, instead of reading zero because it's connected to ground, it doesn't read anything.

It can't "not read anything". When you do a digitalRead you get a number back. What is that number? Post your sketch please.

void loop(){
  
  int EstopVal = digitalRead(EstopBut);
  int DispatchVal = digitalRead(DispatchBut);
  int NowGate = digitalRead(GateSwitch);
  int NowRestraint = digitalRead(RestraintSwitch);
  unsigned long currentMillis = millis();
  
  if (EstopVal == LOW) {
    prevEstopVal == HIGH;}
  else {
    prevEstopVal == LOW;
  Serial.println(EstopVal);
  delay(1000);
  }
  //***************EMERGENCY STOP MODE****************//      
  if (EstopVal == LOW && prevEstopVal == HIGH) {
     
    if(currentMillis - previousMillis > EstopInterval) {
    previousMillis = currentMillis;
    
    if (EstopLit == LOW)
      EstopLit = HIGH;
    else
      EstopLit = LOW;
    digitalWrite(EstopLT, EstopLit);
    }
}
  
  if (EstopVal == HIGH && prevEstopVal == LOW) {   
  
  //**************GATE CONTROL*****************//
  if (LastGate != NowGate) {
      delay (50);
      if (LastGate != NowGate) {
            Serial.println("#S|SENDK|[0&{F10}]#");
            LastGate = NowGate;
      }
  }
  //***********RESTRAINT CONTROL**************//
   if (LastRestraint != NowRestraint) {
      delay (50);
      if (LastRestraint != NowRestraint) {
            Serial.println("#S|SENDK|[0&{F9}]#");
            LastRestraint = NowRestraint;
      }
  }
  
  //blinking dispatch button code
  if(currentMillis - previousMillis > DisInterval) {
    previousMillis = currentMillis;
    
    if (DispatchLit == LOW)
      DispatchLit = HIGH;
    else
      DispatchLit = LOW;
    digitalWrite(DispatchLT, DispatchLit);
      }
  
  if (DispatchVal == LOW) {
    digitalWrite(DispatchLT, HIGH);
    Serial.println("#S|SENDK|[0&~]#");//Sends Enter Key
    delay(3000);
  }
 }
}

Let me know if you need my setup code... Thanks!

Serial.println(EstopVal);

When it is "LOW", this will be Serial.println(0);, i.e. print nothing (null).

Try this:

Serial.println(EstopVal,DEC);

It still doesn't print anything back when connected. My main concern isn't really the fact is not printing back a number but because it's not it's not reading the pin as LOW ever effecting a big portion of my code.

Ok, try this:

if (!EstopVal && prevEstopVal) {
  ...
}
if (EstopVal && !prevEstopVal) { 
  ...
}

Also, what is the purpose of "prevEstopVal". It seems to me that it is redundant as it always is the logical inverse of "EstopVal", and never used on its own.

The prevEstopVal and EstopVal are so it will only do that when there is a change from high to low or low to high for the other section.

But I don't see how it would do that.

You read in the button.
If its low, then EstopVal = low, preEstopVal = high.
else EstopVal = high, preEstopVal = low.

Next time the loop occurs, the same happens again. (meaning the two are Always the not of each other)

By any chance was this what you were trying to do:

void loop(){

  int EstopVal = digitalRead(EstopBut);
  int DispatchVal = digitalRead(DispatchBut);
  int NowGate = digitalRead(GateSwitch);
  int NowRestraint = digitalRead(RestraintSwitch);
  unsigned long currentMillis = millis();

  //***************EMERGENCY STOP MODE****************//      
  if (EstopVal == LOW && prevEstopVal == HIGH) {
        ......
  }

  if (EstopVal == HIGH && prevEstopVal == LOW) {   
        ......
  }
  
  preEstopVal = EstopVal; //Note this stores the old value for next time around
}

Yes that is exactly what I am trying to do. When I write the code that way though it gets all funky and doesn't seem to work correctly.

Here is what my code is when written that way:

const int DispatchBut = 8;
const int EstopBut = A0;
const int EstopLT = 12;
const int DispatchLT = 3;
const int GateSwitch = 4;
const int RestraintSwitch = 5;
int DispatchLit = LOW;
int EstopLit = LOW;
int LastGate;
int LastRestraint;
int prevEstopVal;
long previousMillis = 0;
long DisInterval = 1000;
long EstopInterval =500;

void setup(){
  //start serial connection
  //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(DispatchBut,  INPUT_PULLUP);
  pinMode(EstopBut, INPUT_PULLUP);
  pinMode(DispatchLT, OUTPUT);
  pinMode(EstopLT, OUTPUT);
  pinMode(GateSwitch, INPUT_PULLUP);
  pinMode(RestraintSwitch, INPUT_PULLUP);
  Serial.begin(9600);
 Serial.println("#S|LIMITS|[]#"); 
}

void loop(){
  
  int EstopVal = digitalRead(EstopBut);
  int DispatchVal = digitalRead(DispatchBut);
  int NowGate = digitalRead(GateSwitch);
  int NowRestraint = digitalRead(RestraintSwitch);
  unsigned long currentMillis = millis();
  
  //***************EMERGENCY STOP MODE****************//      
  if (EstopVal == LOW && prevEstopVal == HIGH) {
     
    if(currentMillis - previousMillis > EstopInterval) {
    previousMillis = currentMillis;
    
    if (EstopLit == LOW)
      EstopLit = HIGH;
    else
      EstopLit = LOW;
    digitalWrite(EstopLT, EstopLit);
    }
}
  
  if (EstopVal == HIGH && prevEstopVal == LOW) {   
  
  //**************GATE CONTROL*****************//
  if (LastGate != NowGate) {
      delay (50);
      if (LastGate != NowGate) {
            Serial.println("#S|SENDK|[0&{F10}]#");
            LastGate = NowGate;
      }
  }
  //***********RESTRAINT CONTROL**************//
   if (LastRestraint != NowRestraint) {
      delay (50);
      if (LastRestraint != NowRestraint) {
            Serial.println("#S|SENDK|[0&{F9}]#");
            LastRestraint = NowRestraint;
      }
  }
  
  //blinking dispatch button code
  if(currentMillis - previousMillis > DisInterval) {
    previousMillis = currentMillis;
    
    if (DispatchLit == LOW)
      DispatchLit = HIGH;
    else
      DispatchLit = LOW;
    digitalWrite(DispatchLT, DispatchLit);
      }
  
  if (DispatchVal == LOW) {
    digitalWrite(DispatchLT, HIGH);
    Serial.println("#S|SENDK|[0&~]#");//Sends Enter Key
    delay(3000);
  }
 }
 prevEstopVal = EstopVal;
}

For some reason the lights aren't blinking at all, they are just staying on or off depending on the state of the EstopBut pin. It seems to be switching back and forth between the two but it isn't carrying everything out like it should. Thanks for all of your help!

If you want to keep track of button presses, consider this library: Arduino Playground - MomentaryButton.

TCWORLD:
But I don't see how it would do that.

You read in the button.
If its low, then EstopVal = low, preEstopVal = high.
else EstopVal = high, preEstopVal = low.

Next time the loop occurs, the same happens again. (meaning the two are Always the not of each other)

By any chance was this what you were trying to do:

void loop(){

int EstopVal = digitalRead(EstopBut);
  int DispatchVal = digitalRead(DispatchBut);
  int NowGate = digitalRead(GateSwitch);
  int NowRestraint = digitalRead(RestraintSwitch);
  unsigned long currentMillis = millis();

//EMERGENCY STOP MODE*//     
  if (EstopVal == LOW && prevEstopVal == HIGH) {
        ......
  }

if (EstopVal == HIGH && prevEstopVal == LOW) { 
        ......
  }
 
  preEstopVal = EstopVal; //Note this stores the old value for next time around
}

This doesn't seem to be working because it ends up just making both EstopVal and prevEstopVal the same value as soon as it starts so they are never the opposite value except for a split second so neither if statement is ever true for an extended period of time like it needs to be. As for the momentary button press, I'll need that later for something else but as far as this button goes its either open or closed.

What I would suggest trying is using the 'boolean' variable type rather than 'int' type.

boolean DispatchLit = LOW;
boolean EstopLit = LOW;
boolean LastGate;
boolean LastRestraint;
boolean prevEstopVal;

and

  boolean EstopVal = digitalRead(EstopBut);
  boolean DispatchVal = digitalRead(DispatchBut);
  boolean NowGate = digitalRead(GateSwitch);
  boolean NowRestraint = digitalRead(RestraintSwitch);

There is another issue, which is that you are using 'previousMillis' for two different things, both the blinking dispatch, and estop light. I would suggest you use two variables, one for each (e.g. eStopPreviousMillis, and dispatchPreviousMillis).

What you will find though is that if you are using a tactile type switch, there will be lots of noise, so it will essentially call both until the button has settled.
You should put a capacitor between the input pin and ground (approx 10nF to 100nF) to act as debouncing.

...................................

Just to clarify something you wrote while I was writing this, if the switch is either open or closed, then why not just look at if(EstopVal == LOW){

//**************GATE CONTROL*****************//
    if (LastGate != NowGate) {
      delay (50);
      if (LastGate != NowGate) {

What is the purpose of the second "if"? The variables won't change. Ditto for further down.