Problem with LED13 and button

Hi list,

Having a problem with something simple.
I have a board programmed: press a button, LED13 lights up and it triggers a soundfile in MaxMSP.
But the LED13 is behaving erratically, it keeps lighting on and off and often does not repond to the buttonpress. I have no idea. Have a different board programmed in the same way, with the same circuit which works prefectly. Any ideas?

Code:

int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status

void setup() {
Serial.begin(57600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
}

void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
Serial.println("A");
}
else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.println("M");
}

delay(100);

}

troubleCircuit.pdf (826 KB)

I'm inclined to guess the two boards are not actually wired identically.... but in any case, provide a schematic. Specifically, how is the button wired?- got a pullup or pulldown? If it's high when released that implies a pullup, but from the code it's not the internal one, so is it wired to ground with a pullup?

And pretty please, put your code in code tags,

it's so
{
much
}
easier to read

There's a pdf of the schematic on the original post.
I'm using two Arduino UNO rev 3. Brand new...

Oh, it's high when pressed, with a 220Ohm resistor from 5v between the button and pin 7.

That's a really crap "schematic".... the end of the resistor doesn't even go to a hole and the nearest hole is on a row that's not connected.

Are you sure you have the button the right way round; they're easy to get 90 degrees out.

Internally they connect as shown attached: two pairs are connected internally and then the pairs are connected by the switch-easy to get it wrong.

push button.PNG

I'm very sorry, its all very rushed... It's not a schematic. And it's the wrong button. I'm using a NO (red-capped) pushbutton, with two legs.

The resistor is connected between 5v and the lead for pin 7.

I'm the stupidest person in the world.
Connecting the switch between pin 7 and GND with the internal input_pullup solved the problem.

Thank you so much for spending time on this stupid thing. And I shall get better at posting information!!