detecting a switch

Turn on the pin4 internal pullup resistor.

pinMode (pin4, INPUT_PULLUP); // IDE 1.0.1

pinMode (pin4, INPUT);
digitalWrite (pin4, HIGH); // earlier IDEs