Screwy button or screwy code?

I'm a beginner with microcontrollers and circuitry. I'm building a basic circuit (button and LED wired independently from each other) that when you press the button, the LED lights up. Well, I'm trying to learn the hard way, (for a beginner anyway) and wire them seperately and use IDE to connect them. (Get what I'm saying?) I've run into an issue where my button is giving a HIGH signal when it's not pressed. Can anyone explain why this is happening?

Here's the code I'm running:

//Press and hold down button to turn on LED
int led = 12;
int button = 8;
void setup()
{
** pinMode(led, OUTPUT);**
** pinMode(button, INPUT);**
** Serial.begin(9600);**
}
void loop()
{
** if(digitalRead(button) == LOW)**
** {**
** digitalWrite(led, HIGH);**
** }**

** else**
** {**
** digitalWrite(led, LOW);**
** }**
** int buttonPrnt = digitalRead(button);**
** Serial.println(buttonPrnt);**
** delay(1);**
}

Tell us how your button is wired to the Arduino.

WazzupDrewfus:
I've run into an issue where my button is giving a HIGH signal when it's not pressed. Can anyone explain why this is happening?

Your button must be pulled up if it's connected from a pin to GND, or pulled down if it's connected from a pin to +5V. The pullup or pulldown can be a resistor (10K is fine), or an interrnal pullup. If you just wire a pin to a button without a pullup or pulldown, your pin will electrically float, and will be at a random level between 0 and 5V.

Best, in my opinion, is to wire the button between the pin and GND, and in your setup() function, use:

   pinMode(btnPin, INPUT_PULLUP);

This will save you an external resistor. Don't forget that if you do this, the button pin will be active LOW when the button is pressed.

LarryD:
Tell us how your button is wired to the Arduino.

This is the best way I can describe it. (I don't know how to read schematics)
https://drive.google.com/file/d/0BygrksgwSMntRTBrUkZZX202ZUU/edit?usp=sharing

Unable to see image.

I don't know how else to post it

do you have a camera(phone) ?
you can upload the photo to tinypic.com and use the link to post it here.
or just use a Paint program to "draw" it out and use that same site to upload the JPG file for posting here.


Here it is^

ok, it looks like you've pulled the button high (to 5V) - that means when the button is pressed the digitalRead(btnPin) == LOW
which your code then executes to switch ON the LED.

compare it with here;

where pressing it gives HIGH

I've run into an issue where my button is giving a HIGH signal when it's not pressed

Your switch is wired that way.
Wire it up as indicated in the previous reply. http://arduino.cc/en/Tutorial/Button
Use a 10k resistor.