False Digital Reads

Hey All,

Could anyone tell me why i am getting false digital reads?

Code sets maleConnectorPins to HIGH and then reads if the femaleConnectorPins are connected and read HIGH.

Currently i am just getting "47" show on my LCD.

uint8_t maleConnectorPins[] = {22, 24, 26, 28, 30, 32, 34 ,36 ,38,  40, 42, 44, 46};// Check what cable is conencted Pins
uint8_t femaleConnectorPins[] = {23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47};// Check what cable is conencted Pins

        for (uint8_t m = 0; m < sizeof(maleConnectorPins); m++) // Setup output pins
        {  
          pinMode(maleConnectorPins[m],OUTPUT);
          digitalWrite(maleConnectorPins[m],LOW);
        }
        for (uint8_t f = 0; f < sizeof(femaleConnectorPins); f++) // Setup input pins
        {  
          pinMode(femaleConnectorPins[f],INPUT); // Turn off internap pullup resistor
        }
        //////////////////////////////////////////////////////////////////////////////////////
        for (uint8_t i = 0; i < sizeof(femaleConnectorPins); i++) // Setup Female input pins
        { 
          digitalWrite(maleConnectorPins[i],HIGH);
          if (digitalRead(femaleConnectorPins[i]) == HIGH)
          {  
              //int var;           
              //var = f + 1; 
              lcd.setCursor(0,0);
              lcd.print(femaleConnectorPins[i]); 

          }
          else if (digitalRead(femaleConnectorPins[i]) == LOW)
          {
            
          }     
        }

Because lcd.print(femaleConnectorPins[i])

Is input pin 47 actually HIGH? If so that is what I would expect to see. The code will run too fast to see the status of any pin except the last pin that reads HIGH.

If i do

lcd.print(i)

It just says "12" am i doing this bit wrong?

The code is running so fast you can't see anything but the last because you are displaying at the same position:

              lcd.setCursor(0,0);
              lcd.print(femaleConnectorPins[i]);

You could put a delay just to convince yourself.

Please describe what you actually want the output to be.

david_2018:
Is input pin 47 actually HIGH? If so that is what I would expect to see. The code will run too fast to see the status of any pin except the last pin that reads HIGH.

No there is nothing plugged in other than a jumper from 22 to 23 at the moment

eddcaton:
No there is nothing plugged in other than a jumper from 22 to 23 at the moment

The inputs are floating. If you want a low reading on an unconnected input pin, you will need a pulldown resistor to ground.

david_2018:
Please describe what you actually want the output to be.

I would like the output to be 23. As i currently have 22 and 23 connected together.

david_2018:
The inputs are floating. If you want a low reading on an unconnected input pin, you will need a pulldown resistor to ground.

Thanks,
I will give that a go

The resistors worked with this.
Thanks for all the help.

I have one further question if anyone knows what i am doing wrong or need to change i would be very grateful.

With the same code in my first post, I am trying to set an array of pins high and then see where pin goes high to see where the jumper cable is connected.

I have the input working and showing on an LCD so i can see where the pin is going high. But i would also like to know what output pin was high.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.