Serial input from button

What you have is called a 'floating input' pin when you are not pressing the button, it just reads noise as there is no valid logic high voltage being applied to the pin when the switch is released.

If you wire your 1k resistor from the input pin to +5vdc, I think you will see it will work. One can also instead enable an internal software enabled pull-up resistor for the input pin by doing a digitalWrite(pin#,HIGH); right after the mode command setting the pin to input mode.

Lefty