Digital Pin always high

Status
Not open for further replies.

bossredman

Well-known member
Is there any way to prove (with a multi-meter - ie eliminating code) that my digital pin 23 is defective.

I think its jumping between being Hi & low even with nothing connected to it.

I'm assuming this via
Code:
Serial.print (digitalRead(encoder0PinA)); Serial.print (" -- ") ; Serial.println (digitalRead(encoder0PinB));
PinA being 23
 
... please post more code next time ! We don't know if you have set the pinMode (and which) before.
Do you have set it to pullup or pulldown ?
 
Hi my sketch is over 2000 lines long - hence why i didnt post more code.

Here is what I have (code-wise) relating to that pin (23):
Code:
//Rotary Encoder
   ......  
    #define encoder0PinA  23
    #define encoder0PinB  13
   ......  

Void Setup()
   ......  
//Rotary Encode Digital Pin set up
      pinMode (encoder0PinA,INPUT);
      pinMode (encoder0PinB,INPUT);
   ......  

Void Loop()
{
.....      
n = digitalRead(encoder0PinA);
      if ((encoder0PinALast == LOW) && (n == HIGH)) 
      {
          if (digitalRead(encoder0PinB) == LOW) 
          {
              encoder0Pos--;
              if ( encoder0Pos < encoder0Min)
              {
                  encoder0Pos++; 
              }
          } 
          else 
          {
              encoder0Pos++;
              if ( encoder0Pos > encoder0Max)
              {
                  encoder0Pos--; 
              }
          }
          
          Serial.print("Rotary Encoder:= ");
          Serial.print (encoder0Pos);
          Serial.println ("/");
      } 
      encoder0PinALast = n;

      //Serial.print (digitalRead(encoder0PinA)); Serial.print (" -- ") ; Serial.println (digitalRead(encoder0PinB));
   ......   
}

I've done a search for both '23' & 'encoder0PinA' & found nothing relavant.

Hence I wanted to see if I could test electronically.

Hope that makes sense.

What can cause a digital pin to exhibit this kind of behaviour?
 
Last edited:
Is anything connected to that pin to provide a known signal to measure as input?

Having 2000 lines of code for a hardware test makes it tough to know something else isn't in the way. And having it wired to 'unknown' hardware more so.

Pulling two wires to alternate GND and 3.3V to put a know value on it would be one way. Or tying pin 13 with LED at output to that pin and writing a test sketch would quickly let it be shown to work or not.
 
Last edited:
Note, you are using pin 13 as an input. Since pin 13 has the LED attached to it, it might not be able to be used as a normal input pin, due to the resistor used for the LED.
 
if nothing is connected to the pin, digitalRead() will vary -- read about floating pins
https://electronics.stackexchange.com/questions/83133/arduino-digitalread-reading-wrong
add a pullup resistor, or pinMode(23,INPUT_PULLUP);

Doh!!!!
I honestly can't believe I missed something so obvious and basic as that.
I was using pins 23 &13 for a rotary encoder.
I guess it is basically just 2 momentary switches - right?
Adding the _PULLDOWN (as per all my other switches!!!!!!) has done the trick.

Thank you
 
Status
Not open for further replies.
Back
Top