Problem with digital inputs

hya guys,

i am quite new to this, so this might be a stupid question. i can not get any of the digital inputs on my board to work except for pin 13. i've changed the pin declaration to any other one and connected up my switch in the same way, just to the other pin, and nothing happens. Any suggestions?

cheers a lot Julian

Pin 13 has an LED and resistor so it's slightly different than the others.

What does your sketch do?

How is your switch wired?

I am building a MIDI controller, that incorporates 12 push buttons. when the button is pressed, the sketch sends a noteOn message through a midi connector wired to pin 1, when it is released, it sends a noteOff message. all this works fine, but as previously said, oly for pin 13.

i do not have the buttons i want so far, so i am using SPDT switches. one input of the switch is unwired, one is connected to +5V, the output is connected to the arduino.

I hope you can help with this.... cheers

triple_ninja:
I am using SPDT switches. One input of the switch is unwired, one is connected to +5V, the output is connected to the arduino.

That’s your problem. When an input pin is not connected to anything it ‘floats’ and can be read as HIGH or LOW randomly.

You can wire the other end of each switch to Ground so that the input pin is connected to either +5v (HIGH) or 0V (LOW).

Typically you would use a resistor to force a known state when a switch is off. If the switch goes to +5v then the resistor goes from the input pin to Ground and is called a ‘pull down’ resistor. If the switch goes to Ground the resistor goes from the input pin to +5v and is called a ‘pull up’ resistor. The Arduino has built-in pull-up resistors that you can activate by doing digitalWrite(pin, HIGH) to an input pin.