pushbutton turns on LED in pin 13, Arduino UNO

I'm testing out a pushbutton on an UNO before I incorporate it into my larger project on my MEGA. I can't seem to get the program to work though. I am trying to be able to press the button, and the LED in pin 13 on the UNO should go on, but nothing is happening.

const int buttonPin = 2; 
const int ledPin = 13; 

int buttonstate = 0; 

void setup() {
  pinMode(ledPin, OUTPUT); 

  pinMode(buttonPin, INPUT); 

}

void loop() {
  if (buttonstate == HIGH){
    digitalWrite(ledPin, HIGH); 
  } else {
    digitalWrite(ledPin,LOW);
  }

}

You declare int buttonstate = 0 in setup().

In your if statement you check if it is high, which it is not and never will be, unless you add a line to check your button and set it to high when button is pressed.

You better use bool for buttonstate as high and low is the value you use for it.

In the tutorial there is a lesson doing more or less exactly what you want.

I followed that tutorial step by step and it still won't work. I tried putting the buttonstate=0 in the setup(), but that wouldn't work either. is it possible that my wiring is wrong?

(deleted)

zack2321:
I followed that tutorial step by step and it still won't work. I tried putting the buttonstate=0 in the setup(), but that wouldn't work either. is it possible that my wiring is wrong?

Actually, no. You skipped this line of code. This line change the state of 'buttonState' which in turn change the led.

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);