Sounds like your input is floating. In your pictures I didn't see any ground, and that will leave your input floating. Take a close look at the button tutorial here. Try wiring it up just like that.
try using the internal pullups, that is: set digitalWrite(inputPin, HIGH);
that should turn on the pin as a pullup. does it still flake out?
if you using digitalWrite as HIGH state while pinMode is input, internal strong pull-up resistor will be active
and active low input such as switch to GND will be OK