How to add and handle a push button?

Hi:
I need to add a push button to enter "calibration mode". First, how do I connect it?
PIN->Push button->Ground?
PIN->Push button->+5V?

And do I need to place a resistor in between?

Thanks

You connect the switch to ground, and use the built in pullup resistor.

switch normally open.?
then as described above
...................
If u think a program will set pin to output.. and HIGH.. then this is NOT good.
A 220..1k resistor to gnd will avoid such a eventuality

Here is a widely accepted way to wire a switch. Note that the digital input will be HIGH until the switch is closed, then it will go LOW. The hardware debounce works on most switches that I have tried. You may need to debounce in software if you get more than one signal per push. Look at the "state change detection" example in the IDE for a good method of reading the switch.

AWOL:
You connect the switch to ground, and use the built in pullup resistor.

And how do I use the built in pullup resistor? Is it enabled by default?

pinMode(pin, INPUT_PULLUP); enables the internal pullup in the later versions of the IDE.

groundfungus:
pinMode(pin, INPUT_PULLUP); enables the internal pullup in the later versions of the IDE.

I get an error message about INPUT_PULLUP, I thought it was a predefined constant; do i have to define it?

Here
http://www.arduino.cc/en/Tutorial/Pushbutton

it says that when the push button is pressed, "it makes a connection between its two legs, connecting the pin to ground". So the pins can be grounded with no resistor?

An input pin can be grounded or connected to 5V.

groundfungus:
An input pin can be grounded or connected to 5V.

Thank you guys, this is working like a charm. I'm using a 1K resistor, is it enough? 5V/1KOhm gives 0.005A, I shouldn't worry, should I?

Regards,
Robert

1K is fine but you need no external resistor if internal pullup resistors are enabled, unless the switch is at the end of a long wire and is picking up noise with only the internal pullup.

I get an error message about INPUT_PULLUP

so, use Plan B and set pinMode to be OUTPUT, then digitalWrite it HIGH to enable the pull up.

Which version of the IDE ared you using?

AWOL, did you mean?

pinMode(pin, INPUT); 
digitalWrite(pin, HIGH);

Oops, sorry, yes, INPUT.

AWOL:

I get an error message about INPUT_PULLUP

so, use Plan B and set pinMode to be OUTPUT, then digitalWrite it HIGH to enable the pull up.

Which version of the IDE ared you using?

1.0