Newbie: 1 button + 1 led

I did the easy examples of the book "Getting Started with Arduino". Now I am experimenting to get everything under the hood.
Button is connected to pin 9 and button is connected to pin 5. The setup is via a breadboard. Two resistors are inserted each 10 K.
The led is always on but lightening more when the button is pressed - why is that? It should only light when it has been turned on by a button press.

The simple code is here:

#define LED 5
#define BUTTON 9

int val = 0;
int old_val = 0;
int state = 0;

void setup() {
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}

void loop() {
val = digitalRead(BUTTON); //read inputValue and store it
if((val == HIGH)&&(old_val == HIGH)){
state = 1;
}
else if((val == HIGH)&&(old_val == LOW)){
state = 1;
}
else if((val == LOW)&&(old_val == LOW)){
state = 0;
}
old_val = val;

if(state == 1) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}

Can't comment on the code yet, but can you describe in exact detail how your button and it's resistor is wired to the input pin? It's possible you have a 'floating input pin'.

Lefty

I think a picture is the best I can do. Could the breadboard be defect?http://picasaweb.google.com/clauswilson/SkilteTingOgDiverse#5300530478672965106

Most likely not defective. You have your switched wired such that the input pin is 'floating' when not being pressed. This cause circuit noise to cause false highs and lows.

You can rewire the switch as shown in this link and reverse the logic of what logic state a pushed switch is.

Lefty