Confused about how push buttons work

I am currently playing around with circuit #5 from the starter kit:

http://i.imgur.com/jkJhOqJ.jpg

I am a little confused with how push buttons work. From my understanding, when the push button is not pressed, the contacts are open as seen in this image:

http://mosaic.cnfolio.com/uploads/B202Coursework2011TeamJournalB105/pushbutton_legs_final.jpg

Thus, for the starter kit circuit, when the button is not pressed, 5V does not flow through the push button so if I read off the push button it should read 0V. And when the button is pressed, the contacts close and thus the push button reads 5V.

However, in the code for the push button it says: " // Remember that if the button is being pressed, it will be // connected to GND. If the button is not being pressed, // the pullup resistor will connect it to 5 Volts. "

This contradicts to what I said earlier which is why I am confused. Does anyone know what the issue is? Is it because the push button is normally closed.

You can usually setup a button pin two ways, set the pin high at 5v and then pull it low via a button connected to ground, or pull the pin low with a resistor and then make it high via a button connected to 5v. I like the below way of setting the button pin high, then pulling it low via a button connected to ground.

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

http://www.gammon.com.au/switches

When the button is not pressed, the input pins "see" +5V through the pullup resistors (a pin does not consume much current, so connecting to +5V though a resistor is about the same as connecting it directly to +5V.)

When the button IS pressed, the top pin is connected to the bottom pin (and then to ground) through the switch contacts. A small current flows through the resistor and switch, but not enough to change the voltage level on the pin (which will be at GND)

Also read:- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

And with a pullup, think of the physical position of the button as the logic level: button up is "high" through the pullup and button down is "low" to ground.

JustinLiang:
Thus, for the starter kit circuit, when the button is not pressed, 5V does not flow through the push button so if I read off the push button it should read 0V. And when the button is pressed, the contacts close and thus the push button reads 5V.

Nope.

Buttons usually connect the I/O pin to GND when you press them, not to 5V. This means the program logic works “backwards”.

It really doesn’t make much difference in the program once you know this.

It’s much better to do it that way from an electronics engineering point of view (connecting something to GND is much safer than connecting it to a power supply).