I want to connect four Buttons on my Arduino board, concretely on the digital input pins 2 – 5.
Following /arduino.cc/en/Tutorial/Button I have connected the parts as shown in the upper part of the attached image (next post). However, as soon as one button is closed, the input is distributed to any of the input pins.
I have also tried to connect the parts as shown in the lower part of the attached image (next post). However, as soon as a digital input pin is not attached to ground (if the button is closed) the input value on the pin is completely undetermined (why? I don't understand that)
You need to use the internal pullups. digitalWrite(pin, HIGH) this turns on the pullups. Do this for each of your pins. Otherwise, the pins are left floating. You can then use the switches to pull the pin to ground. Remove the 5V from the circuit and it should work much better.
When the switch changes from closed to open, it seems that takes about ~300 ms till the input on that pin remains stable (I just conclude that from the flickering of the LED).
What sort of switch is this, it could be that you are suffering with contact bounce if you see instability at change time. Have you got a scope, if not is 300mS a guess because it sounds long for contact bounce.